Spell Checker  Spell Checker

Here is an email I received in response to my essay on how to write unmaintainable code. My responses are marked with a ∇ and green type.

Closure : Michal Kočárek : michal.kocarek@brainbox.cz : 2009-03-23

at first I have to say that I really enjoy the Unmaintainable code tutorial, as it sometimes looks like it has been taken from reality (and, unfortunately, some are coding accordingly that).

You are quite right. The essay started as therapy. I would get so angry when I encountered poor code. The essay was an opportunity to ridicule it and lampoon it. I discovered that readership for my essays on how to write unmaintainable code had orders of magnitude better readership than my essays on how to write good code. Now when I encounter terrible code, I clap my hands in glee — another item for my collection.

I am sending you two suggestions into Unmaintainable code howto. I think both of them are beautiful way for writing messier code.

1. Closures]

Closure is beautiful way in JavaScript, how to take variables from outer scope, use them in current scope — then return myself with variables still being referenced. Simple example:
function foo(bar) {
   var baz = function() {
      return bar;
   }
   return baz;
}

var x = foo(2);
y = x(); // y is 2;
By mixing closures which have side-effects and reusing variables from global scope, one can create beautiful parts of code, even more beuautiful than the obfocusator would.

2. switch(true)

Personally, I think this is wonderful statement, which programmers are not used to.

I have never seen code like that before, outside of FORTH. Are you sure that would compile? I am so used to Java where all the case clauses must be evaluated at compile time without duplicates.

I would appreciate, if you find at least some pieces of this code helpful for extending your Unmaintainable code howto.


CMP homejump to top

available on the web at:

http://mindprod.com/feedback/unmain/closure.html
  

optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\feedback\unmain\closure.html
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, especially when sending an ad-hominem attack, a rant composed mainly of obscenities or a death threat, please quote the offending passage and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. I can’t very well fix erroneous or ambiguous text if I can’t find it.
Blog
IP:[65.110.21.43]
Your face IP:[50.19.155.235]
You are visitor number 11.