Friday 3 February 2012

Object Oriented vs Object Spagetti

Novadays I'm dealing with some other developer's software. It's a bit old software. Nobody here knows who wrote the codes. It's written in .NET Framework 1.1 and using Visual Studio 2003.

Yes yes I know migrate the codes to current framwork instead of talking you're saying probably. Wait a little and be patient my friends.

I think the developer was new to .NET and probably this is his first codes in .NET. You know when .NET first introduced "Object Orientation" was the first think people talked.  But as I always say "you have to balance the theory and practice". Technology is a kind of fashion for male programmers.
"Ohh this year Object Oriented Programming is so popular",
"Are you still using tables... I am using divs "
"3 Tier application is old fashioned"

If you are old enough you may know server strategies in time. Once there were 1 huge server for everything Then people think that it's dangerous to keep all the eggs in one basket. We switch to multi server environment. File Server, Mail Server, Database Server, Domain Server.... Then again somehow we changed our mind and a huge server came back with the virtual servers.

Lets come back to our subject. I am digging the codes to understand why he did something like a spagetti.
A process started in an application and I follow the codes in 10 different functions in 5 different application written in 2 different languages PLUS Stored Procedures, using user defined nested functions in 4 level. It's like an adventure. I never know where I'm going to end when I start from a point.

My first manager told me some golden rules of IT.

1 - One day we may die. Write the codes clear, understandable, standardised and documented. so that one other programmer can continue your job immedialtely

2 - Always keep it simple. This is not an arena for you to show your talents.

3 - Updating a code is harder. Always write codes to change anything easily.

I will tell you the rest of them in future. But he is right. You may write in C# and VB but you don't need to use both of them in one project. (Actually I don't understand why we need to use C# anyway.)

Now I'll tell what I did to add a simple field to a screen.
I opened the insert screen and added a textbox
I opened the database and added the field
I opened the codes (in VB) of the insert screen and try to add this field to save buttons click event.  but I realized that the screen values are loaded into variables and sended to a functions in a dll.
I found the dll application and open the source and began editing.(dll was in C# )
I follow the dll and saw there is another reference to another dll which is directly related to insert operation.
I opend other dll application and update the lines. But I saw that the screen values now sended to a stored procedure as parameters.
I open SQL server and updated stored procedure.

Finally I finished the insert but I also did the similar things for the display and update screens (I don't know why but there were 2 screens for insert and updates.

So now I have to compile them in order and include the dll's to main application.
Come on.. This is just a waste of time.  It's the third challanging job in my carrier.

1 - I saw a man storing the data like this : first he creates the line then he converts the line into binary then he wrote to a database table. it's true and he did it for the whole application and NO the data was not sensitive. I realized that he used his binary files for his database needs for his whole life. When He found SQL server in front of him he didn't understand about query, relation etc. He did everything with his best knowledge.

2 - There was a ERP system written by a rookie. Front screens and gui  was good. but in codes and database it was unbelievible. ID fields were character based. If you want to create a relation between 3 table you had to know which characters are the link part of the which table. Even worse part was he had no idea about cross reference tables, he had no clue about field naming. Also he had no idea about object orientation he repeat many code parts in many places in his code.

After them this is less challanging for me. :)

Final Word : Please my friends. Keep your codes simple and updatable. Reading standards will take your 2 hours maximum. But will save days in the future.

No comments:

Post a Comment