Saturday, January 12, 2008

'Why Ruby should never be taught'

The title shamelessly refers to this post by Ka Ping Yee (via Tim Bray).

As I finally started to really learn to decipher Ruby by reading the Pickaxe (2nd edition), I came across one example that I knew must contain a typo of some sort. I fired up irb just to make sure... but came away horrified:
irb(main):001:0> def a
irb(main):002:1>   2
irb(main):003:1> end
=> nil
irb(main):004:0> a = 3
=> 3
irb(main):005:0> a
=> 3
irb(main):006:0> a()
=> 2

A single name within a single scope that refers to two different things!

It took me quite a while to realise that in many languages (including Java which I use almost exclusively at work) this isn't so bizarre at all, because those grammars make a very clear distinction between variables on the one hand and functions/methods on the other.

When studying Ruby, I am apparently reasoning from a Python and JavaScript mindset, because I expect Ruby to share with those languages the dynamic typing nature and the combination of OO and functional programming influences. In Python and JavaScript the above is simply unimaginable.

It is obvious that I have quite a number of obstacles to overcome in getting used to Ruby...

Friday, January 04, 2008

Reluctantly started to make some sense

Adding features to an old code base is hard and often not much fun. It is especially hard when not enough time could be budgetted to really get to understand what that particular piece of code is trying to accomplish, let alone to figure out by which coincidence it is actually almost accomplishing that original goal most of the time.

But of course, if you want to stand a chance of successfully shoveling all the 'accidental features' that you and your teammates introduced in the previous release candidate under the carpet, at the end of the day you need to get pretty familiar with whatever logic apparently appeared most intuitive to a bunch of other clowns.

So this week, after spending hours doing my very best to avoid making 'new major changes', which many of us claiming experience with such matters consider risky at the project stage we're in, I had to concede that I didn't really understand much of what some esteemed predecessor had thought was a good solution to the problem at hand. And if we wanted our users to enjoy working with an application that behaves in a somewhat predictable fashion, the last programmer leaving his mark should at least be able to predict that behaviour rather precisely from what he'd observed. As it was, all of us unlucky enough to have witnessed that particular string of characters were manically trying our best to eventually forget that painful sight.

Coming to realise that there would not be any other way out apparently was the hardest part. Finally, yet another unexpected 'accidental feature' side effect broke what was left of my resistance and I set out to do what we had all agreed by oath to never do... With a next release candidate scheduled for yesterday (or the day before), I was going to seriously touch untouchable code... I started to slowly replace all kinds of magic numbers with self-describing semi-constants (say what?) and flattened deeply nested if-then structures by introducing just enough well defined boolean variables. Eventually a satisfying sense of logic started to emerge... Even the readable and predictable kind of logic that I was looking for! But then, with the spaghetti straigthened out and all alligned, and some initial testing confirming that the program was actually doing what I now believed it should, the scary thing was that quite a number of lines appeared to be missing in action...

Not to worry though! Let's just say "less is more" and 'what he says' etc. etc. and hope nobody is going to actually, you know, miss those lines ;-).

And if you think that I am completely full of myself because of my little far fetched success story... well, you might be right, but I tend to consider this more of a humbling experience really. And don't forget that I now have many boring hours ahead of testing just about all the different scenario's the code attempts to deal with... which was probably the real reason I was putting off this refactoring for so long in the first place. And, err, no, unit tests were not exactly available or straightfoward to introduce in this 'JSP heavy' environment.... :-(

Anyway, what I enjoy about this is that dealing with legacy code can actually become rather satisfying and good fun as soon as you dare fixing things up, even in small ways. That, and that it gave me an excuse to link to a great blog post that advocates keeping code bases small, but loses all credibility by being way too long itself... :-)

Monday, December 31, 2007

Spoken

(A story in Dutch...)

Ben wordt wakker. Alweer. Het is donker en hij is nog ontzettend moe. Hij draait zich maar eens om. Het liefst valt hij nu gelijk weer in slaap. Maar dan dringt het tot hem door dat dat niet gaat lukken. Rustig blijven! Niet weer in paniek raken... Te laat. De stress is niet te stoppen en giert al gauw door z'n hele lijf.

De laatste nachten was het steeds opnieuw raak. Er moet een oplossing zijn! Verzin toch iets! Dan kun je daarna weer rustig gaan slapen. Maar hij ziet geen uitweg. Waarom kan hij het weer niet zelf? Ach, hij kan het heus wel, maar niet nu, niet in deze situatie. Natuurlijk had hij het ook nooit zover moeten laten komen! Nu moet hij zich gewoon neerleggen... maar dat lukt juist niet. Hij heeft dat al zo vaak geprobeerd. Het is allemaal zo vermoeiend!

Hij denkt terug aan z'n uitbarsting van vanmiddag. Hij was het zat om genegeerd te worden, steeds het idee te hebben dat niemand echt luistert naar wat je te zeggen hebt. Z'n leidinggevende toonde wel begrip, maar vond ook dat ie moeilijk deed. Hij kan zich voorstellen dat ze hem er straks gewoon uitgooien. Misschien is dat ook wel het beste... Van hem hoeft het allemaal niet meer zo nodig. In het begin was alles nog nieuw en leuk, maar nu...? Kon hij het ze maar duidelijk maken! Weinig kans. De communicatie loopt al zo stroef. Misschien gaat dat over een tijdje beter... Het is in elk geval niet zo dat hij daar niet z'n best voor doet.

Op dit moment heeft hij daar niets aan. Hij kijkt naar de schimmen van de meubels in de kamer. Zo kan hij niet slapen. Zijn wereld staat op z'n kop! Als z'n ouders het eens wisten... Ze zouden zijn frustratie wel begrijpen, maar zij hebben juist steeds gezegd dat hij het zelf moet kunnen. Ja, tuurlijk! Maar zij slepen niet de ballast met zich mee waarmee ze hem hebben opgezadeld.

Hij weet dat hij hulp zal moeten inschakelen. Maar tot nu toe won de schaamte het steeds van dat besef. Er beginnen tranen te stromen. En dan schreeuwt hij het uit in de stilte van de nacht. Z'n adem stokt en hij hoort weer alleen die stilte. Er zal toch vast iemand zijn die hem hoort?! Hij zal blijven schreeuwen... Nee, het lucht niet op. Helemaal niet. Het helpt hem geen steek verder. Maar wat moet hij anders? Blijven ademhalen, want dat zou je nog vergeten. Maar dan stoot hij z'n vers gevulde longen weer leeg in de volgende oerkreet.

De deur van z'n kamer gaat open.
"Hallo meneer, wat is er aan de hand?"
Een mannenstem. Hij kent die stem wel.

"O, ben je op je buik gedraaid?! Maar jochie, waarom draai je je niet gewoon lekker weer op je rug? Ja, ik snap wel dat je dat moeilijk vindt met je slaapzak aan. Nou stil maar, kom maar even mee naar mama... misschien mag je wel even aan de borst! En je had al zo weinig geslapen vandaag, want in het kinderdagverblijf wilde je niet. Ja, ja, rustig maar... Kijk eens wie daar is!"

Ben schokt nog wat na, maar hij weet dat het nu allemaal goed komt.

Thursday, July 10, 2003

I never thought I'd get here... and I wonder if I'll stay.
It's tempting to just run away, as this freedom makes me fear
that I'd be talking into thin air, with nobody to care ;-)