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.
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).
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 :(
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 ) {

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 :-)

9/7/2009 14:47:12

I like this

9/8/2009 13:18:03

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!

9/8/2009 13:55:40

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 {
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.

mohd ajami
9/9/2009 15:19:21

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

9/9/2009 22:03:36

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

9/10/2009 00:25:02

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

3/8/2011 17:29:38

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.

4/24/2011 12:26:40

great post

5/3/2011 22:35:09

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.

6/20/2011 23:20:17

7/20/2011 12:47:11

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

12/23/2011 23:11:58

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

12/25/2011 23:04:35

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

12/25/2011 23:21:14

good, I will bookmark this site

2/5/2012 17:04:56

So fun article is! I agree the idea!

3/12/2012 18:25:37

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

3/30/2012 20:02:29

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

4/3/2012 00:52:50

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

4/9/2012 02:10:03

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

4/9/2012 02:10:23

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.

4/11/2012 23:26:03

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

4/16/2012 22:55:32

as well as reduce the <h1><a href="" title="Coach Outlet Online">Coach Outlet Online</a></h1> of most illness. <h1><a href="" title="Coach Factory Outlet">Coach Factory Outlet</a></h1> therapy is not only proven to <h1><a href="" title="Coach Outlet">Coach Outlet</a></h1> protection against infectious diseases, <h1><a href="" title="Coach Outlet Online">Coach Outlet Online</a></h1> been proven to affect the mood <h1><a href="" title="Coach Factory Online">Coach Factory Online</a></h1> morale of employees. <h1><a href="" title="Coach Factory Outlet">Coach Factory Outlet</a></h1> in an aroma therapy <h1><a href="" title="Coach Outlet">Coach Outlet</a></h1> environment

4/16/2012 23:34:20

6has become necessary in everyday life of women seeking fashion

4/17/2012 01:34:39

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

4/17/2012 23:57:46

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.

4/18/2012 01:04:55

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

4/18/2012 01:36:46

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

4/19/2012 01:36:50

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.

4/19/2012 01:43:37

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

4/21/2012 01:34:01

ving in contact w<a href=>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

4/22/2012 22:12:24

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

4/24/2012 20:38:16

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.

4/25/2012 22:44:48

<a href="">louis vuitton</a>
[url=]louis vuitton[/url]

4/25/2012 22:53: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.

4/25/2012 22:54:17

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.

4/25/2012 23:02:22

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.

4/25/2012 23:04:23

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.

5/8/2012 19:11:04

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.

5/12/2012 02:18:09

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.

5/12/2012 19:31:30

Great,thanks for your sharing.

5/16/2012 00:25:07

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

5/16/2012 19:54:43

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.

5/16/2012 23:25:37

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

5/18/2012 05:15:01

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

5/19/2012 01:59:18

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.

5/23/2012 18:57:56

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.

5/23/2012 18:58:41

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

5/31/2012 01:32:49

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

5/31/2012 01:32:55

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

5/31/2012 01:33:01

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

5/31/2012 18:13:04

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

6/5/2012 20:47:41

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 .


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.

6/21/2012 22:58:34

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.

6/28/2012 23:43:20

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

7/8/2012 18:19:51

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

7/8/2012 18:20:11

our website, good lucky ,,i will come usually

7/9/2012 17:57:31

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.

7/9/2012 17:58:04

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

7/9/2012 17:58:18

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.

7/9/2012 20:15:43

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

7/24/2012 11:30:43

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...


10/8/2012 23:15:23

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

10/8/2012 23:16:02

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

7/8/2013 01:10:55

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

Kasey Kasem
7/13/2015 14:53:49

Keep your feet on the ground and reach for the stars.


Leave a Reply.