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

 
Last week I changed my Job, and started working in Rockwell Automation, after spending the last two years working in web development using Java. In this post I would like to share the worst moments in those years. Do you know all the theory we learnt in universities about Object Oriented, code reuse, encapsulation, cohesion, robust systems that don’t break because of a small change? I didn’t see anything of that, projects where started by unexperienced programmers who just heard that Java is Object Oriented without knowing what the hell does that mean.

Working on those spaghetti projects was very frustrating, but in the same time very challenging, it was amazing how some people managed to write indigestible code that makes you through up. This is my top 5 worst codes till now:

1. Do You Call This Validation?
Try to guess what this programmer is trying to do using this piece of code? exactly he is trying to validate the number of days in a month as a part of a bigger date validation method, if the month is 4,6,9,11 it should be 30 days, while if its 1,3,5,7,8,10,12 it should have 31 days, with a special consideration of month 2 and leap years.
Picture
Yes maybe the code is working, but can you read it easily? are you sure its bug free? in your opinion how many people out there needed to validate a date string? maybe something around 1000000 programmers right? Good, So don’t you think that there should be some magical method that will do this for you? What about trying to parse it with a DateFormat instance and catch an exception if something goes wrong? 

Whenever you are up to start coding something just stop and do this conversation with your self:

   yourself: Hi you.
   you: Hi yourself.
   yourself: do you think this operation is very common?
   you: Yes, I Think Date validation is done by many people...
   yourself: do you know something that will do it for you?
   you: No.
   yourself: ok, so ask master Google about “Java Date Validation”.
   you: oooh here is a ready solution, thanks yourself.
   yourself: you are welcome you, see you the next time, bye.
   you: bye yourself. 

2. Is This a Constructor?
Here a programmer wrote this constructor (I took the image using my iPhone), some of you may think yes its a big constructor but he used eclipse automatic code generation tools, NOO, in this constructor there was a tiny bug that I discovered, which made me conclude that this constructor was written by hand. (by the way this is only the top part of the constructor, its not complete).
Picture
For the programmer who wrote this constructor I have two questions, one, why the hell did you write this constructor by hand? two, do you think there is someone much crazier than you that will call a constructor with all that parameters? ok maybe there will be a 0.001% chance that this constructor is needed in that class. But writing it by hand? if I was a manager I would fire him, I don’t need programmers that waste 30 minutes for something that could be done in 1 second (and yet do it wrong).

3. The Power of Encryption
This one is really great, its clear that someone is trying disparately to encode a string. The problem is that this is not encoding, this is starting to become encryption somehow WTF!!. what about performance? how many times is the String parsed and parsed again? never heard about a StringBuilder or StringBuffer? couldn’t you read a bit about encoding before starting your own encoding solutions? guys all this makes our life difficult :(
Picture
4. Ever Heard About Data Integrity?
During my work I was located for 3 months on a project which was using a postgres database and till now everything was wonderful, the problem was that the people who created the database schema never heard about Data Integrity, Primary Keys, Foreign keys ...etc, working with that DB was like putting your data in a trash (it just accepts anything you put in it!!), come on man at least put primary keys for God sake!!

The nice excuse of not forcing data integrity was ... “we don’t need it, all DB access is done through Hibernate”, oooh really? so you are saying that Hibernate doesn’t need constraints? and you are so sure that there will be no other application in the future that will access the database directly? How the hell could you be so sure that you don’t have corrupted data if you don’t have constraints? 

After working on that project I soon realized that there was a lot of trash in the DB, orphan tuples, missing data ...etc. Take this advice, if you see someone using a database without forcing data integrity, and you have the power, just fire him and send him home, there are so many dump ass programmers in this field that we have to get rid of.

5. Best Comments Ever
Everybody should place comments in their code, its good to comment your code. YES!! but if your comments are not useful just don’t write them down and waste my time, how many times did you see something like this:

     //print the value of x if its bigger than 10
     if( x > 10 ) {
        System.out.println(x);
     }

Is this comment useful? I can already see that if x is greater than 10 it will be printed, I am a programmer who reads Java code faster than your comments, writing a comment like this one is an insult for programmers (Yes we know what is an IF statement), I don’t want to see those stupid comments in the code, its even a maintenance nightmare, later when the specification changes, and x should be printed when its greater than 9 instead of 10, I will have to change the code and the stupid comment too. What about this one:

     //the constructor
     public Person( ) {
         //some code
     }

Ok now lets talk seriously, we are Java developers, we are working on a serious project, do you think that someone needs your help, to tell him that, that was a constructor? if your answer is yes, fire him and you will save time and money. If you find comments like this do two things:

   1. Delete them.
   2. Try to locate the person who wrote them and shoot him.

These where the worst codes I ever seen, have you seen codes worst than those? please post them and lets all have fun :-)

 


Comments

abdalrahman
09/07/2009 14:47

I like this

Reply
amos
09/08/2009 13:18

I hope you did some refactoring and not let such a "spaghetti code" as is! If so, can you post it, just to see "before" and "later" ... would be intresting!

Reply
09/08/2009 13:55

Of course some refactoring for code like this is required, keeping in mind that a small change would destroy everything, especially that those projects didn't had any Unit tests that could make your life easier.

For situations like comments you just delete them as I mentioned (step two is not mandatory :-))

For the database, adding data integrity constraints is a must, and so they were added, but to be honest I couldn't add everything I wanted because I didn't had a lot of time to do it (3 months and I had to implement a new subsystem), and the data in the DB was corrupted, and required a serious schedule to be adjusted. So it wasn't a 100% sane DB but it was way better than the first version.

For the Date Validator it was piece of cake:

public boolean validDate(String date, String formatString) {
SimpleDateFormat format = new SimpleDateFormat(formatString);
try {
format.parse(date);
return true;
} catch(ParseException e) {
return false;
}
}

For the constructor a simple (cmd + shift + g) command in eclipse (on a Mac) which detects a method/constructor references made it clear for me that it wasn't used so it was simply deleted.

Finally for the Encoding issue (or may be I have to call it encryption) redundant operations where removed, if you take a look you could find that some replaces are done over and over, and everything was done by a StringBuilder instead of Strings (for performance), but the bad news is that the system was used for almost 3 years with that encoding, and the database was full of data encoded with this magic method, so the only option was to decode it in a reverse way and prevent catastrophic problems. Especially because working on that project was for a client (not a full time project), and work was assigned by task, which didn't allow for good and serious refactoring (time was very limited, and I can't work for free).

Refactoring is very important, but in the real life when you have 10 days to create a new feature to a client, and this is the only thing that he will pay for, you don't have many options. And unfortunately the project works from the outside, which is exactly what the client wants, convincing him for additional 10 payed days for adjusting a piece of code that is already working is almost impossible (unless he is a programmer and understands your language and knows that this refactoring will save money on the long term) but this is real life its not university ... so sometimes you have to satisfy the client and satisfy yourself. you can't work 20 days for free :-( and there are realities that makes your perfect life impossible. You try to convince clients that code is written bad, that the structure is bad and it should be refactored, and this will take some time. But if in the end the client doesn't want to pay for these days you can't do anything (unless you want to work for free).

of course if you are working on an internal project for full time, refactoring is a must, waste 10 days now and you will save a lot of bug fixing later.

Reply
mohd ajami
09/09/2009 15:19

wow, man, good blog.

in the first case, i love how he made a falling down switch :), although not in the right place

will link to your blog on my facebook :), developers would love it :D

Reply
09/09/2009 22:03

for section 'The Power of Encryption' and you also may use built-in (ready components) features that save your time in coding such bad bad bad coding

nice work man

Reply
09/10/2009 00:25

@Mohd Ajami, Thanks man for the free advertisement ;-).

Reply
03/08/2011 17:29

I'm just surprised to discover how a lot of data I received on this specific topic. I m so extremely thankful of you. 1 factor I could assert that, after reading this article I became preserved from the whole ineffective search I ought to have performed on this particular matter. Your write-up can be a authentic fantastic factor in disguise.

Reply

great post

Reply
05/03/2011 22:35

But if there is a personal itself has very good,
For you are sincerely, love you,
So you really can put entrusted to his life.

Reply
06/20/2011 23:20

Reply
Loser
07/20/2011 12:47

I don't like you printed all my code here! I'm very proud of this code!

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
12/25/2011 23:04

I'm happy I found this article,its great!

Reply
12/25/2011 23:21

good, I will bookmark this site

Reply
02/05/2012 17:04

So fun article is! I agree the idea!

Reply

Find the best hotel furniture from contract furniture specialists at Hill Cross Furniture.

Reply
03/30/2012 20:02


Can see your blog I very happy! Thanks for your sharing, I wish you a happy life!

Reply
04/03/2012 00:52

You did really job on your blog,i love your blog style,and how you make your point on this article ,cool.

Reply
04/09/2012 02:10

A good article, worth sharing for you, see you your article to your future success believe a great help, hope to see more of you share good article, thank you for sharing

Reply
04/09/2012 02:10

Very good article, not only feel good, I nearby of all the friends all say this is a very good article, the content of the novel, clear view, fully show the author rich writing ability and life experience, hope to see more of the good article to share.

Reply
04/11/2012 23:26

First of all, types of name tiffany co want to be the necklace around

Reply
04/16/2012 22:55

as well as reduce the <h1><a href="http://www.mycoachoutletstoreonlinee.net/" title="Coach Outlet Online">Coach Outlet Online</a></h1> of most illness. <h1><a href="http://www.coachfactoryoutletx.com/" title="Coach Factory Outlet">Coach Factory Outlet</a></h1> therapy is not only proven to <h1><a href="http://www.coachoutletstoreonlinem.net/" title="Coach Outlet">Coach Outlet</a></h1> protection against infectious diseases, <h1><a href="http://www.coachoutletonlinelife.com/" title="Coach Outlet Online">Coach Outlet Online</a></h1> been proven to affect the mood <h1><a href="http://www.coachfactoryoutletonline-top.net/" title="Coach Factory Online">Coach Factory Online</a></h1> morale of employees. <h1><a href="http://www.coachfactoryoutletc.com/" title="Coach Factory Outlet">Coach Factory Outlet</a></h1> in an aroma therapy <h1><a href="http://www.coachoutletonlinelife.com/" title="Coach Outlet">Coach Outlet</a></h1> environment

Reply
04/16/2012 23:34

6has become necessary in everyday life of women seeking fashion

Reply
04/17/2012 01:34

A web site selling authentic hand bags will always have a guarantee:Authentic or money back.

Reply
04/17/2012 23:57

I feel this blog is very well organized and is quite interesting. I really want to join this kind of events.Thanks for the post.

Reply

Under western culture accomplish of those 3 louis vuitton outlet online store main paths louis vuitton outlet stores will be usage of Charlotte now Rectangle and this eastern is Street Tim Pillow. hgjhgj

Reply
04/18/2012 01:36

louis vuitton outlet store It has prompted the wave inside the division of treating numerous diseases such as countless severe eyesight diseases.shytrysgf

Reply
04/19/2012 01:36

The Louis Vuitton piece is sure to make an impression on any travel mates you may have or even just to those sitting next to you in the airport, awaiting their flight.

Reply
04/19/2012 01:43

A web site selling authentic hand bags will always have a guarantee:Authentic or money back.
http://www.mycoachoutletstoreonlinee.net

Reply
04/21/2012 01:34

ving in contact w<a href=http://www.louisvuittonoutletwebsite.org/>Louis Vuitton Outlet</a>ining the home bottom will

likely then be the future In .it.Inch But should you be reckon that this is simply not a great choice, you are able to

explore charade which can be an additional in house online game. uring this recreation, preferably, there must be two

competitors. There'll be part that may make a scene your message that's prepared on a piece

Reply
04/22/2012 22:12

1one more idea the girl were feeling just like starting ended up being the girl self confidence

Reply
04/24/2012 20:38

Wow! This can be one particular with the most valuable blogs We have ever arrive across on this subject. Truly Excellent. I'm also an expert in this subject so I can understand your hard work.
http://www.michaelkorsoutlet-online.us

Reply
04/25/2012 22:44

<a href="http://www.louisvuihhttonoutletbbh.com">louis vuitton</a>
[url=http://www.louisvuissttonoutletbbh.com]louis vuitton[/url]

Reply
04/25/2012 22:53

The Coach Factory Online make no guarantees to their inventory so you may lose a really great deal or style simply because you did not act. coach factory online outlet is a great place to find coach handbags at great prices. You may have noticed that the Coach purses are not discounted on a regular basis at the department stores, as well as, those great coupons you get in the mail normally excludes Coach products. http://www.coachfactoryonlineoutletc.com

Reply
04/25/2012 22:54

Appearance fashion, confidence and a perfect coach handbags, you must spend some time and effort to find a division has total choose what you like to for export various kinds of Coach Outlet Store. Are you anxious to choose some of the brand bags? Are you searching for reliable sellers? When you come to the Coach Outlet Online Store , these are not problems.http://www.coachoutletstore-online.org

Reply
04/25/2012 23:02

Welcome to visit our Louis Vuitton Outlet, whatever you like, our shop can supply to you.Launched in honor of the 2004 Euro Cup in Portugal, the Attaquant gets its original shape from the soccer ball. Amazingly you could definitely go to louis vuitton Handbags Outlet to get louis vuitton purses in as many cultural events as you could for instance carnivals, weddings, Christmas, Valentine's Day, dancing events, sports matches, fashion shows, and so on. http://www.onlouisvuittonoutlet.com

Reply
04/25/2012 23:04

This brown handbag called Flagship Signature Brown Handbag has been the best seller in the Coach Factory Outlet for almost three weeks. Matching with classic C Logo designs, the Coach new arrivals of this season in the coach factory online outlet will show you the most outstanding characters of their own.http://www.coachfactorystoreoutletonline.org

Reply
05/08/2012 19:11

Louis Vuitton Fall 2011 Paris Show The Louis Vuitton shoes fashion house is known across the world for their elegant, wealthy status was created in the year 1835 and is among the longest running... Louis Vuitton Fall/Winter 2011 Bag Collection Fe-tish also fe-tish. ln this season's louis vuitton bags uk collection 'Fetish' and 'Fashion' are explored through their interchangeable meanings. At once neither is... Louis Vuitton Store Online Handbags can also bring great accuracy as well as practical applicability and fashionable. Providing you've got a hair-trigger finger reaction, if you do find a louis vuitton uk that you want you're in with a great chance of securing it. http://www.louisvuitton-lv.co.uk

Reply
05/12/2012 02:18

Welcome to the Coach Factory Outlet store and Enjoy Shopping Here! We promise all the customers to have the superior qualities and low prices. We are proud to celebrate our sixth 'Best of Award of Excellence' from Wine Spectator for Coach Factory Outlet Online. Our Sommelier team works diligently to ensure you have some of the best wine values available. There are some practical and beautiful items for sale at? Coach Factory Outlet Online for your selection. Do not miss it and have one for a try.

Reply
05/12/2012 19:31

Great,thanks for your sharing.

Reply
05/16/2012 00:25

Le bon goût, j'ai bénéficié de

Reply
05/16/2012 19:54

Most perple reckon that owning
mulberry outlet
from Outlet Store shopping is actually buying of the most useful bags on the planet.
mulberry sale
with fashion style and top quality succeed. In any occasions they are very suitable and appropriate for its precise and rich design.It is believed that you will like the products on the
mulberry outlet uk
. There are spacious sizes and different colors, styles and so on.
http://www.mulberryoutletonale.co.uk

Reply
05/16/2012 23:25

This is my first opportunity to visit this website. I found some interesting things and I will apply to the development of my blog. Thanks for sharing useful information

Reply
05/18/2012 05:15

with fashion style and top quality succeed. In any occasions they are very suitable and appropriate for its precise and rich design.

Reply
05/19/2012 01:59

Your blog is outstanding; do not a lot ofthings people are talking about intelligence. I am glad I have this chance in my relatingsome of the search.

Reply
05/23/2012 18:57

If the dress in question does this for you, ask to try on something else. There are enough options out there to help you avoid this problem.

Reply
05/23/2012 18:58

This is not a flattering look. This happens even with the thinnest of women.

Reply
05/31/2012 01:32

I am glad I found this website, it is the correct information for you,thanks!

Reply
05/31/2012 01:32

I love reading your information good. I can provide you with invaluable news.

Reply
05/31/2012 01:33

Thank you for your article, I have been looking for this for a long time

Reply
05/31/2012 18:13

Working on those spaghetti projects was very frustrating, but in the same time very challenging

Reply
06/05/2012 20:47

Very good and wonderful blog , by the contact of these days , I learn from your blog to a lot of meaningful knowledge . Not only that, also know a lot of like-minded Friends of Bo , the mutual exchange of learning, to communicate with each other , the same are very appreciate your blog , hope you have more similar share . Thank you for sharing this .

Reply


People often feel ready to stage is a waste of time, only when the real chance come, and they have no ability grasp, they usually didn't prepare to consciousness is wasted time.

Reply
06/21/2012 22:58

You should tolerate those opinions with you different people, like this day is better. If you always want to change him, that way you can be a pain. To learn how to do is stand him. You have to learn to tolerate his is.

Reply
06/28/2012 23:43

A thousand-li journey is started by taking the first step

Reply
07/08/2012 18:19


If you wish to be the best man, you must suffer the bitterest of the bitter.

Reply
07/08/2012 18:20

our website, good lucky ,,i will come usually

Reply
07/09/2012 17:57

Best Blog! The awareness you provide is quite useful, why I was not clever to find it in the past. Anyways I’ve joined to your feeds. Please, maintain the brilliant work up.

Reply
07/09/2012 17:58

It makes our lives more convenient,but also let more people become increasingly dependent,it is my idea for beautiful.

Reply
07/09/2012 17:58

Its performance and its appearance are fascinated me, I was deeply attracted to it, it made ​​me feel very fashionable. I believe that people who understand it will have the same feelings with me.

Reply
07/09/2012 20:15

The reason for this failure, there may be many, but the success of the reasons but only one.

Reply
07/24/2012 11:30

How the heck did they use Hibernate without declaring an @Id for persistence? lol... Must have been an older version or something? I didn't think you could get away with not having a primary key for your @Entity...

Reply

http://www.louisvuittonofficialwebsite2.com

Reply
10/08/2012 23:15

Really is to let people unexpectedly, give me too much surprise, I said I am very lucky..

Reply
10/08/2012 23:16

You have to believe in yourself. That's the secret of success.

Reply
07/08/2013 01:10

Just this morning I butchered the code of my HTML email. Inline CSS styling is such a pain.

Reply



Leave a Reply