X

Sunday, October 11, 2009

Code Readability VS Error centralization

I found this a good thing to write about and didn’t want to postpone otherwise I might forget.

A very common rule in computer science or Software engineering to be specific is to make the code you write more readable than hacky, even if it would cause a slight performance loss, as readability relatively important than this maybe-tiny performance loss, even in the easiest example it’s preferred to write an if else instead of using the one-line  Ternary operator. This is also for people who love to minimize their code >><< that it will look so obfuscated.

Yesterday I was completing an engine I’m writing since this last summer vacation and I had to review a very old code, I remember I was very very lazy while writing it, I just wanted to finish this boring and very repetitive part, so the biggest function was like 190 lines of say 9 ifs, so I wanted to change some variable that controls the logic throughout the whole function and hell started, I had to  re-understand every bit of each line to know what to edit, and that’s all in the sake of code readability so that I could divide the function into 8 ifs and formulate the code as the process in real life goes so the reader wouldn’t face problems imagining what the code does.

What made it a real hell that there was whole other 5 functions that had the same logic error :( , so I cursed code readability, i needed to make my errors more centralized so that they can be easily contained and corrected, the next day (the one that’s now) I spent it getting use of what I know about digital design and made something close to a truth table gave each action 2 bits … and reduced the code to 40 lines with two for loops and only one place to edit the flow afterwards.

 

 

//About my domain, 3MaTeS wanted to change the company that’s registering my domain, and so told me to wait a month till it expires and be free to register from anywhere else, after a month (28-9) I found that the original company I wanted to replace had already registered my domain for itself for another year so If wanted to have my domain back I have to renew it only from them only :s, seems that I don’t have another way around.

0 comments:

Post a Comment

Newer Posts Older Posts Home