Home
Entries Friends Calendar Userinfo Homepage Previous Previous

Advertisement

Fellow adventurers
Adventures of a Paladin
code_martial
[info]code_martial
Add to Memories
Tell a Friend
A 5 year old article from my old website, salvaged from the Internet Archive.


We all know that one must KISS. But how does one KISS? This article is all about a hypothesis that if you try to KISS, you can also KISS.

Alright, so your Tech Lead has handed you down a nice interface design and done whatever was necessary to explain the behaviour of the system through those interfaces. Now what are you waiting for, stupid? Code it up and deliver it yesterday... er... whatever! In any case, it is your responsibility now to put together something that works. You are the developer who writes the first cut of fresh software.

You are the target of a zillion curses doled out by maintenance engineers who have to clean up the mess after you're done. You're at the recieving end of one bug report after another that comes out of the QA department while you're working on the next iteration of development. Life sure sounds like it's hell.

Everyone has his own opinions about how to handle this situation and so have I developed a set of guidelines to keep myself out of such situations. Do these work? Apparently they do, which is why I took time out to put this whole thing together, but YMMV.

Be honest, be shameless

We all make errors in life and more so while programming a computer, which involves giving very precise instructions because computers haven't yet reached the stage where one can expect them to DWIM. One of the often made mistakes I have come across is trying to keep everything under wraps when it comes to handling errors.

Do not handle errors that you can not.

Trying to cover up error conditions when you don't have any idea of what to do can often be dangerous. Once I was trying to access a web application that required a login. I gave my username and password and it failed to authenticate. I spent about half an hour trying to figure out what my password was and then going to the database itself and resetting the password to something new. Still no luck. On scanning the authentication code, I found that the implementer caught any exception and returned authentication failure. The actual reason for failure was that there was no database connection!

In another project, we started seeing errors in the logs that said there was no column called "Infinity". That looked like a division by zero error and it is apparently quite dumb to let a division happen without checking for division by zero. In reality the divisor was never supposed to be zero so the check was unnecessary. The best that could done was to check and report an error but that machinery was already in place and it worked. Had the case been hushed up, say, by setting the result to zero, we would have had bad data and not have noticed it.

The whole idea is for a program to fail noisily when it has to. This makes it easy to detect the failure at the point of occurence where you have most context available to figure out its cause. You can then choose to eliminate the cause or plan out a strategy to handle that failure. When you are writing lower layers of a system, you should dutifully report errors and not hush them up. It is for the higher layers to decide what to do. It may be a simple, “Sorry, there seems to be some problem doing foo. Please try again later.” or something more sophisticated like giving suggestions on how or when to get things done right.

Note that you'd be lucky if you follow the above style and the libraries you use report errors by throwing exceptions. With return codes it is your responsibility to check the error code and report it, otherwise you'll be simply swallowing it (and throwing an unrelated error somewhere later).

Cut the crap

The goal of an implementation engineer is to write code that:

  • is largely free of defects
  • has defects that can be detected easily and quite early
  • has a simple logic for the benefit of maintenance engineers
  • is well structured to ease evolution and perfective maintenance

I will try to show how aiming to cut the crap and keeping the number of lines in your source code at a minimum can help you in reaching these goals.

Keep It Short, Stupid

Software Engineering statistics show that the number of defects per line of code is roughly constant across all programming languages. That is the reason why usage of higher level languages is advocated. So, if you try to reduce lines of code within the decided language of implementation, you reduce the incidence of bugs as well. Once you have written a unit, you rescan it to see if there is some flab you can shed. Rescanning for re-implementation is inherently more rigorous than scanning for correctnes, because at each step you would be double-checking to ensure you don't break the behaviour. To keep it largely free of defects, KISS.

If we again recall our Software Engineering lessons we'll know that the earlier a defect is found, the easier it is to rectify it. When less amount of code does more work, more things break if it is buggy, making things easier to detect. With more bug reports, you also get more context to examine and pin-point the defect. For code whose defects an be easily and quickly detected, KISS.

Trying to keep things short requires elimination of redundant code. This results in simplification of the underlying logic because someone reading your code has to deal with lesser number of confusing constructs likes loops and tests. Lesser amount of context needs to be kept in the head while going through it. It is also beneficial to do data transformation in less number of steps, each doing something significant, to keep things clear. To simplify your logic, KISS.

If done correctly, code elimination also leads to improvements in the internal design of code and makes things modular. For example, if you face several blocks of code, each with only minor variations, you factor out the common parts into one unit that the others depend on. This makes the unit that you have factored out more "responsible" and allows other blocks of code to off-load their responsibility to it. We all know the benefits of modular code, so I will just say that, to have well structured code, KISS.

Write disposable code

Now we move on to slightly more subjective issues. My suggestion is that when you write disposable code, you implicitly write maintainable and extensible code. What I mean by disposable code is your program is composed of a number of small, self-contained units such that any unit may be replaced with another unit that does the same job and it shouldn't required changes in other parts of the program. This is the holy grail of Component Based Software Engineering, and the general principle can be applied to micro level coding too.

When you try to make your code disposable, you end up writing modular, cohesive code that has a high degree of invariance. Modularity implies that your codebase is divided into neat sections, each having its own set of responsibilities. Cohesivity implies that related things appear together in your codebase. Invariance implies that changes in one part of your codebase do not require changes in other parts. Perfective maintenance and behavioural enhancements then become easier because you don't have to worry about introducing regression errors, unless the behavioural change itself is incompatible with the previous behaviour.

Now that I have harped about all the virtues of writing disposable code, what does it take to figure out that a maintainer would be too hesitant to dispose off pagefuls of code because he can't be sure of its repercussions? Joel Spolsky thinks that rewriting from scratch is a bad idea. Writing disposable code allows you to get a lot done without resorting to a rewrite from scratch.

Don't mind obfuscating in favour of saving loc numbers

Okay, that was just to wake you up. Writing obfuscated code is a crime against humanity. Often people get the wrong ideas about obfuscation, however. Being terse is not obfuscation. Even in activities other than programming, like public speech or daily conversation, verbosity is not appreciated. Why then do you think (if you do think that way) that being verbose in code is going to make things clear? To me, it is more clear if you write something like:

   return !call_a_function();

than something like:

   int retval = call_a_function();
   // If retval was zero we should return success (true)
   if (retval == 0)
   {
     return true;
   }
   // Otherwise we should return failure (false)
   else
   {
     return false;
   }

Another thing to remember is that once you are done coding the logic, you should do a second pass over what you have written. Usually when you are not implementing a well defined algorithm, you tend to evolve some logic as you code. Evolutionary coding of logic looks clear and simple to the implementer because it is a reification of his thought process. However, it isn't necessarily simple for someone who is reading through it for the first time and trying to decipher it. More often than not, such evolutionary code has redundant loops, conditionals and unnecessary explicit temporaries, that get in a reader's way of understanding the logic. Like Eric Raymond says in his book, “The Art of UNIX Programming”, Chapter 1, Section 9:

“You'll carelessly complicate when you should be relentlessly simplifying — and then you'll wonder why your code bloats and debugging is so hard.... You need to care. You need to play. You need to be willing to explore.”

After you are done with cutting the flab off your logic, you can get some more mileage if you know the style conventions of your programming language. Every language has a bunch of idiomatic way of doing things. Those idioms are very well recognised and their usage makes your code no less clear. The most illustrative example of idiomatic usage, perhaps, is the short-circuit behaviour of “logical and” and “logical or” operators. Use these style conventions and idioms as often as you can. Of course, a lot also depends on the syntax of your programming language .Some languages are more easy to obfuscate (Perl?) than others (Python!). Though business logic is usually so simple that you have to try hard to obfuscate its implementation, my personal observation is that the above, seemingly counter-intuitive tips work for algorithmic code as well.

When worse comes to worst, and you manage to obfuscate your code, be good and make it disposable. The maintenance engineer who has to deal with it (and that may very well be you), he can bug the local language expert for deciphering it out. He might also offer advice on how to rewrite it better, and teach you some other tricks. In the extreme worst case, your code might have to be thrown away, so it should be easily replaceable.

Tahir Hashmi 2005-01-07

Tags: , , ,

[info]bombaylives
Add to Memories
Tell a Friend

We are starting with Mumbai Chapter of The Sapling Project on 19′th December 2009.

We will be distributing saplings to all participants.

We would like you to take saplings from us, plant them where you can take care of them for couple of years till the time they grow into small trees.

When : 11.00 am, 19 December 2009

Where : Barista, Shivaji Park, Dadar

http://www.thesaplingproject.com/

The Sapling Project soon in Chennai, Bangalore & Delhi.

Cheers to Kiruba ShankarHrish Thota and Shantanu Godbole


[info]bombaylives
Add to Memories
Tell a Friend
</p>

Innovative movie promo, originally uploaded by Bombayite.

Rickshaws all over Bombay have been painted with the promos, Nice Idea, but I think they missed out the Auto Driver :)


puremeteor
[info]puremeteor
Add to Memories
Tell a Friend
I've been reading the fiasco that has been CAT 2009..Given that Prometric
were conducting this test I'm a bit surprised reading about all this. This
whole sham of a "virus" screwing up test results etc etc shows how
inadequate the whole setup has been
Some key points which I would have hoped with computer based testing:
1. results should be given immediately.
2. probably make it computer adaptive (like the GMAT)
aneeta_04
[info]aneeta_04
Add to Memories
Tell a Friend
Food and Transport is free at work since Monday. Which also means, employees will come, go, eat their breakfast, lunch at the timings decided by the Management. Well, since I stay close to work(7 kms), I still have an option of choosing the facility based on my convenience. It is wise though not to miss the free things in life.

The first time, I heard this news, I was quite happy welcoming the change, I planned to convert all my kitchen time into fitness time. Man proposes, laziness overrides better. 3 days since the change, all idle time has been converted into sleep time till now. Well, new routines take time to set in, I hope it does soon.

We also have this beautiful message which flashes on the Intranet Homepage with "Your Today's Time-In is " and they have separate color for Late(Red)/Early(Green), which will haunt you for the rest of the day if you are late. And then we have this My_Attendance_Report similar to your school report card, with detailed late time and cumulative late time minus some 101 flexible_working_hours_limit parameters. Well, the report card does not tell you that irrespective of flexible timings, if you come late, you miss free food, the token system shuts down at 8.15 am sharp. Interesting Math, the HR, Facilities and IS teams can expect a good hike this year, and the rest of us folks, dont miss school anymore.

And since food is free and its the first week on free food, we dont see the house-wives's husbands with Tupperware tiffin boxes anymore. We stand along with them in the long queues. Some people though continue to bring their food. And the general junta looking at the statistics of men carrying their home-cooked food made an observation that, we now know whose wife cooks really good. The rest seem happy to be off their wives culinary skills experiments ! I also met somebody extra-ordinary who still brings his wife's morning cooked upma but eats his free breakfast and lunch at the office cafeteria. He eats his wife's food as an evening snack, bcos the evening snacks are paid and not free.

Well, not to mention about the extra calories I am consuming in the form of parathas, oil and sweets. I do have considerate team-mates..Like today, they let me eat only a spoon of carrot halwa and leave the rest to the bin. I am blessed with diet-coordinators around! This blog post evolved out of self-sympathy actually :)

Tags: ,
Current Mood: headache

vinayakh
[info]vinayakh
Add to Memories
Tell a Friend
Excellent read Coders at Work review .

Tags: , ,
Current Location: bangalore, India
Current Mood: calm
Current Music: Cold - No One

vinayakh
[info]vinayakh
Add to Memories
Tell a Friend
I recently met with Alex Ohanian - Creator of the Reddit Alien. He was here for the TED conference.

Tags: , ,
Current Location: bangalore, India
Current Mood: cheerful
Current Music: Switchfoot - You

[info]phdcomic
Add to Memories
Tell a Friend
Piled Higher & Deeper by Jorge Cham
www.phdcomics.com
title: "Grad Carols" - originally published 12/7/2009

dhempe
[info]dhempe
Add to Memories
Tell a Friend
[info]bombaylives
Add to Memories
Tell a Friend


Free Colgate, originally uploaded by Bombayite.

Colgate giving free sample of MaxFresh toothpaste.

Location : Gandhi Nagar, Kanjurmarg.

P.s I’m not associated with Colgate or 57007, Am just sharing this in public interest :-)

11011110
[info]11011110
Add to Memories
Tell a Friend
Via polylogblog I learn that the list of accepted papers at STACS has become available.

Three graph algorithm titles caught my attention enough to get me to track down their online versions, though I haven't had time to do much more than scan their abstracts:

Finding Induced Subgraphs via Minimal Triangulations (arXiv:0909.5278) by Fomin and Villanger. This turns out to be about finding moderately-exponential algorithms that find subgraphs of bounded treewidth that are as large as possible and to solve subgraph isomorphism problems when the subgraph to be found is large but of bounded treewidth.

Two-phase algorithms for the parametric shortest path problem by Chakraborty, Fischer, Lachish, and Yuster. Parametric optimization problems involve an input graph with weights that vary (linearly or more complicatedly) with some parameter; one must solve an optimization problem like shortest paths for particular parameter values. In the version studied here, one doesn't want all the different shortest paths for all different parameter values (there can be superpolynomially many different paths even when the edge weights vary linearly); rather, we'd like to compute the shortest path for some small set of parameter values, more quickly than the O(mn) per value that it would take to run Bellman-Ford separately for each value. (One can't use Dijkstra because some edges may be negative.) The authors show that, with polynomial preprocessing, shortest paths for each parameter value may be found in O(m + n log n) time, as fast as Dijkstra.

Planar Subgraph Isomorphism Revisited (arXiv:0909.4692) by Dorn. This is a followup to one of my papers, which provides a completely impractical algorithm for finding any k-vertex subgraph (for fixed k) in a larger planar graph in linear time. The algorithm described here has been improved: it's now exponential in k rather than k log k. I'm still not convinced that it's at all close to practical, but it's a step in the right direction.

Tags: ,

[info]bombaylives
Add to Memories
Tell a Friend


Saifee Hospital, originally uploaded by Bombayite.

No one will believe its a hospital but it is, one of the largest in Bombay :)
Location : Charni Road, Bombay


[info]bombaylives
Add to Memories
Tell a Friend
aneeta_04
[info]aneeta_04
Add to Memories
Tell a Friend
This weekend, I invested a lot of time talking to a broader set of friends whom I never get to talk to usually and the discussions revolved around the way I badly handle relationships. I do not know why I havent written much about any serious relationships here.. either bcos nothing took off very seriously in the first place except my feelings, or may be I feel embarrassed to write about how low I treat myself to make relationships work and how I never learn from getting hurt repeatedly.

Every relationship requires a lot of hard work from either parties and more of forgiving yet not forgetting. Not forgetting so that you dont hurt the other person again by doing the same mistake again. All this applies after knowing a person well and when you have committed yourself to the relationship.

What I fail to understand is how do you measure how much you can forgive a person when you are just getting to know the person. Every time somebody hurts me, I blame it on the premature going-to-be-a-relationship phase and tend to forgive the person, only to be hurt again. I think I love myself when I am being patient with people without knowing that I am doing more harm to me than any good to myself or the person. I set an impression of being a door mat where one could dust off his frustrations and temper on me. And who knows the person may not be taking me as seriously as I take him or the relationship. May be most of my getting to know people is based on online acquaintances and I shouldnt be reading between the lines, fishing for love or emotions ! Who knows the mistake is on my side, getting emotional with people who are just looking to spend some online time together.

Every person, every relationship is different, but I am angry with myself for not being able to identify the pattern of getting hurt over and over. The only good I can do to myself is by not giving anyone the power to hurt me( which I will be soon forgetting). Rather than getting sad about people not understanding me, I should learn to discard them off my emotional bandwidth ! There is already too much to deal with in life... Respect and treat yourself the best :)

And its good to have friends to talk to. Atleast you know not everyone thinks you are bad :) Thank you my dear friends :)

Tags:
Current Location: India,
Current Mood: awake

[info]bombaylives
Add to Memories
Tell a Friend
[info]bombaylives
Add to Memories
Tell a Friend
[info]bombaylives
Add to Memories
Tell a Friend
[info]bombaylives
Add to Memories
Tell a Friend


Rajabai Tower, originally uploaded by Bombayite.

http://en.wikipedia.org/wiki/Rajabai_Tower

[info]bombaylives
Add to Memories
Tell a Friend
[info]bombaylives
Add to Memories
Tell a Friend


Golaman, originally uploaded by Bombayite.

I dunno why would he allow some to dry his pants outside his stall :)
Location : Chowpatty

Profile
solzaire
User: [info]solzaire
Name: solzaire
Website: Homepage
Calendar
Back June 2009
123456
78910111213
14151617181920
21222324252627
282930
about this journal
page summary
tags