Omar Al Kababji  Weird Thoughts From a Weird Mind...

 
Assuming you are a software developer, let me ask you a question, what do you do at work (except drinking coffee)? do you modify code written by others? or do you develop projects from scratch? either way this post is for you. For me Its almost 2 years that I adjust and modify pieces of code written by others (if I just could know where they live), anyway here is the story:

Your boss comes to your office holding a cup of coffee in his hand, and tells you about a new modification, we have to read some information from a .csv file and parse it (YEAAH finally something new to do), this is something that happens everyday, there is a problem and we have to solve it, but lets dig to see how this problem is solved by different programmers?

John, a programmer who is not a programmer (but sadly thinks he is), will consider reading a .csv file the end of the world (I don’t even know what the hell is a csv by the way), he will start spamming all the office asking how he could do it, he will get 10 different ways to solve it, and after wasting 20 days, and interrupting other coworkers during this period, its done... YES YOU CAN JOHN!!. We put John’s modification in a production environment, and we get a big fat NullPointerException, Why? on my PC worked... John its because you considered that the file should be in the directory:

     C:\Documents and Settings\Users\Dump John\Desktop\file.csv

And guess what, that path is written in the source code file, and to change it we need to checkout the project from the repository, change it, recompile it and deploy it again. JOHN take this advise, go find a job in McDonald, and leave programming for real programmers. 

Fred, the second programmer is one who knows everything, he has a 10+ programming experience, he read 15 books about design patterns, he collects certifications as collecting flowers, he used almost all java MVC and web development frameworks, he knows about good programming habits, ok ok you are good Fred, what is your solution? 
  • Create an IDataReader interface that will have a readData() and processData() methods (you have to program  for interfaces).
  • Create a class AbstractDataReader that implements IDataReader and adds many common methods, that will be used by our subclasses.
  • Heey now the file is .csv but in the future may change so lets create those classes CSVDataReader, TSVDataReader, XMLDataReader, DBDataReader, SocketDataReader, FTPDataReader, HTMLDataReader, that will handle almost every kind of file, and lets group text ones alone, and DB alone, so lets make them descendants of AbstractTextDataReader and DBAbstractDataReader.
  • We have DataReader’s for almost any type, but we have to be sure which one to use, so lets create a DataReaderFactory, that will determine the correct file reader and return a proxy to the correct IDataReader object (object factory & proxy pattern).
  • Yeeeeah I like the idea, go on Fred...
  • The way files are processed may change and its not good to put it in a source code file, lets create a proprietary workflow language that can be expressed in plain XML, and use a parser that will parse these commands, and transform them to java code.
  • Lets adapt the delegation design pattern too, I don’t know for what, but it sounds cool I want to use it.
  • Many DataReaders can be operating at the same time, so lets create a pool of IDataReader objects, and lets use Dependency Injection to inject those objects in the classes that will use them.
  • Should we use our own Dependency Injection framework? NO (we are reinventing the wheel) Spring framework provides it, lets integrate Spring in our solution.
  • Since threads are playing we need to put synchronization stuff, and having racing conditions is the last thing we want, this is a serious framework, its Fred’s framework.
  • Everything should be configurable, so lets put everything in .properties files, no wait lets store them in a database, so we can change them without the need to restart the application. 
  • Lets log all operations, and lets also provide a GUI application to manage the threads pool, logs, and configuration parameters. 
  • We should do everything with Aspect Oriented Programming (AOP) in mind, so we can add and remove layers of code without interference. 
  • Ok shut up Fred we got your point.
This is a perfect and nice solution Fred you are really a great programmer, I love your idea. I am not done please keep reading...

Finally Steve a duct tape programmer (as Joel Spolsky describes him in his post)  comes, Steve is just as the previous programmer Fred, but with one additional thing, HE USES THAT THING ON HIS SHOULDERS (yes the head), before even starting to work he asks one or more questions to his boss, to better understand the situation, and after talking with his boss. It is cut clear that those coming information will be only from a .csv file, and they will almost never change. So he decides to go simply with a simple class that reads a file and parse it and thats it. (of course he would make it a bit more flexible to small changes) and everything is done in, lets say... 4 hours? It could be even done in 2 hours.

Got it? No? ok lets continue... after two years both Fred & Steve changed companies (John was shoot by Steve, I told him to find a job in McDonald...), and you can’t reach them anymore, and guess what... a modification is needed. A new piece of information should be passed to the system, so the .csv file has some extra information now, and one additional step should be done when processing the file. And we need someone to do this modification... guess who?? Steve? No. Fred? No. 
I am the one who will do the modification.
In the first case I should waste my time navigating Fred’s framework, moving from one class to another, going up and down in the inheritance tree (Geeez Fred how many classes did you put there). Guys I just need to read a fucking .csv file and process it. 

Finally I get to the point where I can add the new parameter, now what? Oooh yes I have to add the new processing step, yes its easy I just have to validate the new parameter, but please give me one day to learn how the hell can I do it using Fred’s XML workflow language, that its not even working well.

Lets go back, what is the modification? add a parameter and process it. Why for something so easy I should spend so much time? because someone (Fred) who read design patterns thought its cool to do it in that way. Wrong Fred wrong, don’t complicate your life (and mine please) if its not necessary, your boss didn’t ask you to design a general DataReader module that will read everything, even what is written on your dirty pants, he just asked you to extract and process 4 parameters from a .csv file for God sake!! (just give me Fred’s new address).

The bottom line is simple, if you have to read a file just read it as Steve did, but if you need to develop a general data reader module then go Fred’s way, be intelligent, use your head, small things should remain small and simple, its not logical to create a 50 class framework to read a file that can be read in 10 lines of code. 


For me, the best solution was Steve solution, easy, simple, and fast. Have a nice day and remember what Alan Kay said:
Simple things should be simple, complex things should be possible

 


Comments

medopal
01/19/2010 02:19

man you are so cool, LOL.

Unfortunately I saw "Fred" kind of solutions many times. Someone was using Java Reflection API with around 50 lines of code just to write toString method. Which you can do in 3 lines max.

I wish you continue blogging, that was really fun to read ;-)

Reply
02/26/2010 21:10

Wow, I'm sure I know these guys, I think I may have worked with them! Agree with your views on this one. The right solution for the problem is what is required.

Reply
07/30/2010 19:17

Nice statement, I prefer to leave the remarks since the comments grants writers to become more engaged and for the opportunity to certainly learn from each other.

Reply
08/04/2010 17:57

Work is more that a necessary for most human beings; it is the focus of their lives , the souece of their identity and creativity.

Reply
08/11/2010 17:36

Within you I lose myself, without you I find myself wanting to be lost again.

Reply
08/13/2010 21:00

Early to bed, early to rise, make a man healthy, wealthy, and wise.

Reply
08/20/2010 17:54

stray birds of summer come to my window to sing and fly away.
and yellow leaves of autumn, which have no songs, flutter and fall
there with a sign.

Reply
08/22/2010 18:04

sorrow is hushed into peace in my heart like the evening among
the silent trees

Reply
08/25/2010 20:15

The poet's voice need not merely be the record of man, it can be one of the props , the pillars to help him endure and prevail. (William Fulkner, American writer)

Reply
08/26/2010 00:28

When one loves one's art no service seems too hard. (O.Henry, American novelist)

Reply
08/30/2010 17:47

Laws are generally found to be nets of such a texture, as the little creep through, the great break through, and the middle-sized are alone entangled in. (William Shensto, British poet)

Reply
08/31/2010 20:07

Your suggestions are extremely distinctive, I help you. I think you should always be described as a clever man. So i prefer to know you.

Reply
09/01/2010 20:35

When two people are in love, they are eager to have more sweet kisses. But why they are in quarrel, they are hurting each other by the mouths that once used for kissing? Every time when I was upset or tired, I can only kiss by myself.

Reply
09/09/2010 01:07

As you say, superb individuals with schooling for all-around growth is an ideal blend. Now people are very nearly cannot resist the temptation from money. They achieve funds by way of a variety of strategies. I am so unhappy to find out that.

Reply
09/17/2010 17:49

You know it's easier to get killed by a terrorist than get married over the age of 40.《Sleepless in Seattle》

Reply
09/17/2010 18:23

Simple language, concise blog! Another style! I like! Do you like UGG shoes? Welcome to our website to see all kinds of shoes, you must like it.

Reply
09/18/2010 01:53

No morality can be founded on authority, even if the authority were divine. (A. J. Ayer. USA writer)

Reply
09/20/2010 18:44

It can be my 1st time I've went to your site. I noticed an incredible deal of intriguing data inside of your site. From the tons of feedback with your written content content, I guess I'm not the simply 1! Joyful to share, the happiness of potential.

Reply
09/26/2010 20:27

I am astonished to be conscious of how much of methods I received on this matter. I'm so really glad of you. The one factor I could assert that, after searching via this write-up I became stored from the whole useless lookup I should have trained on this sort of subject. Your post is really a traditional great thing in cover.

Reply
09/29/2010 18:43


This blog is very interesting I Like to read story about how the people get something accomplished. This is the reason why i spend all my time just reading i really enjoyed. And i love the blog that contain helpful information and learn about it.

http://buyonline-rx.com/
http://buyonline-rx.com/sitemap.html

Reply
10/06/2010 17:37

We often say someone is so beautiful, just as praise his/her soul in a degree. Because Courage and resolution are the spirit and soul of virtue. Do you think so?

Reply
10/06/2010 19:19

A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing.

Reply
10/07/2010 18:31

In your life, there will at least one time that you forget yourself for someone, asking for no result, no company, no ownership nor love. Just ask for meeting you in my most beautiful years.

Reply
10/08/2010 19:18

Patience, time, and money overcome everything. Do you think so?

Reply
10/13/2010 00:28

Hello! I'm concur with you, you opinions a incredibly excellent. Within the morden time additional and far more men and women like purchasing around the line. But a few of them are anxious about that many people reveal to mendacity. They fell dread. Right here I need to inform you that now people today occur to much more and a lot more Civilization, they couldn't mendacity, if you should acquire some shoeses, please arrive to our webpage, Thank you really significantly.

Reply
10/14/2010 00:46

Hello! Nice to meet you, Today is a good day. Hope you a happy day. I am like your blog very much.

Reply
10/14/2010 02:28

Thank you very much. Best wish to you. Wherever you are in each smile of my blessing, deeply bless you, my friends. If you want to buy a shoes, Please come here Nike Shox Clearance shoes to chooes.

Reply
10/16/2010 01:45

I am really excited to get comments from your blog, Thank you so much. I’ll be interested to hear how things go in your future posts, Can you tell me? Leave words come to wigan and some point drop drops embellish, My heart without much affection, To a host heavy gold holy.

Reply
10/17/2010 19:18

wow, so nice

Reply
10/18/2010 20:23

Your bolg is so wonderful, I quite extremely fancy it. At this time the wether is excellent, do you possess a joyful working day? I hope you joyful each working day. Enable the joy flew into your cardiovascular system, enable the great luck as part of your system. Make it possible for the land flowing with with your coronary heart, permit the time with sincerity and unforgettable. We are a Nike Dunk SB lover.

Reply
10/19/2010 02:15

In case you would probably go up high, then use your personal legs ! Tend not to let yourselves carried aloft; tend not to hold yourselves on other individual's backs and heads.

Reply
10/19/2010 19:47

What a find photo, thanks for dreaming up this website. What's not to love about a review of knitting needles that features comments such as determined clear clicking. If rosewood is the soprano, then this is alto. Or even the fact of a review in the first place. Who would have thought that "craftiness" could be so articulate. I must steal time to peruse the rest of this site soon!

Reply
10/26/2010 17:44

Don't part with your illusions. When they are gone you may still exist, but you have ceased to live.

Reply
10/27/2010 17:41

Each one particular flower, Is a lyrical ballads, each and every a gentle wind, Is often a comfy greetings, Each field is a single coronary heart,The moist, Every single communication is often a constant genuine feeling!

Reply
10/27/2010 18:55

Pass our songs, laughter; I am waiting for your wonderful life! Come on!

Reply
11/01/2010 00:30

You actually provided us so detail information.that may be excellent for us to discover a little something.numerous comments I noticed almost decided with you.Excellent luck with your lifestyle.

Reply
11/02/2010 00:51

That is a wonderful piece of writing, I observed your blog page internet site searching aol for any equivalent topic and came to this. I couldnt get to a lot other info and information on this weblog submit, so it was good to discover this 1. I'll finish up becoming returning to look at another articles or web site posts that you've yet another time.

Reply
11/02/2010 01:59

If you would know the value of money, go and try to borrow some.

Reply
11/05/2010 01:44

Don't bother just to be better than your contemporaries or predecessors. Try to be better than yourself.

Reply
11/09/2010 17:36

May you have enough happiness to make you sweet, enough trials to make you strong, enough sorrow to keep you human, enough hope to make you happy.

Reply
11/09/2010 18:36

You're fantastic.Continue to work hard.

Reply
11/22/2010 22:14

hei , guy , that is have so much girls , do you want to see them.

Reply
11/23/2010 18:42

Fantastic! This is what we need. Like a pen to write the fireworks, vivid and outstanding.

Reply

The greatest happiness is to work for education.

Reply
11/24/2010 23:14

Because you know of my heart!

Reply
11/26/2010 17:24

Yeah, you blog structure is so simple, I like the style. I also like writing something if my spare time. So I can learn something from your article. Thanks.

Reply
11/28/2010 21:50

I shall remember that happiness day forever.

Reply
12/05/2010 16:31

good,it is very nice.

Reply
12/21/2010 00:42

Il faut avoir la qualité morale noble ; il fautut s’entendre franchement avec desautres s’entendre franchement avec desautres ; il faut avoir des comportements courtois.

Reply
01/06/2011 00:30

Happy every day in new year

Reply
01/20/2011 01:57

Wonderful world, I wish you happiness!

Reply
02/21/2011 01:10

Cheap MBTs on hot sale, they are all in the top-quality ,get the Comfortable and the Health from the MBT.welcome to visite our site . we could offer the best service for you!

Reply
02/24/2011 20:00

you can find what you want to in here,make your life full of color ,it's a perfect website.

Reply
02/25/2011 17:21

you can find what you want to in here,make your life full of color ,it's a perfect website.

Reply
02/28/2011 17:09

you can find what you want to in here,make your life full of color ,it's a perfect website.

Reply
03/04/2011 19:37

Life is just like a box of chocolate, You never know what you are going to take.

Reply
03/07/2011 19:03

I'm just surprised to discover how significantly of facts I received on this specific topic. I m so incredibly thankful of you. One particular point I could assert that, after reading this article I became preserved from the whole ineffective search I ought to have completed on this particular matter. Your write-up is actually a authentic wonderful factor in disguise.

Reply
03/10/2011 19:05

Thanks so much for posting these, they are fantastic! So bummed I missed what looks like a truly unique evening.

Reply
03/30/2011 02:17

A man has two ears and one mouth that he may hear much and speak little.

Reply
12/23/2011 23:11

act. It is in reference to your charge upon him, that the young people are expected to obey, and It is

Reply
01/02/2012 18:03

I know your comment to the point.

Reply



Leave a Reply