Archive for the ‘CodeDesign’ Category
November 26th, 2009
Three months back, I went on a coding spree to create a simple wiki system to coordinate the creation of a school magazine. I tried several open-source wiki systems. Did not work. Main culprit? The navigation. First in all wiki systems I tried, everything was a link, second, some things—like uploading an image—took five actions in a specific order. So I created a super simple system, where actions are buttons and places are links. I was very happy with it, but the audience was not. There was one [-edit-] button per page, and to the audience it was unclear what would be edited if they clicked it. So I added lot’s of redundancy, now every item has it’s own edit button. As it turned out, images need a different edit button, because to the audience images are uploaded, not edited. I gave all the buttons a fixed column, leaving blank the ones that do not apply. Sometimes it is so hard to fully respect the GUI coding rule: “Write for your audience, not for your peers.” (Ryan Opaz) [Free Advice]
(Also I cheated, I could not make everything self explicatory, so I made two instruction screen-casts. Now everybody is happy.)
November 24th, 2009
“Do not choose setup.exe. Choose setup. Why? By default, Windows hides common extensions and what appears to be setup.exe is actually a file called setup.exe.config and setup is actually setup.exe. Anyone with any pretensions towards technical savvy will sidestep that trap intuitively, it does begin to feel horribly familiar.“ (Mark Whitehorn) [SQL Server 2008 – from semi-relational to sublime]
The design of you code can escape into the real world. Split second decisions like: “Ok, I need a name for this configuration file. Let’s add “.config” to the executable name.” is one of one thousand decisions per day. And all these split second brethren need more than casual thought. Non coders usually don’t understand the magnitude of mental reflexes needed for this. But also they will never know the deep satisfaction it brings to fight the devil and win, to write really good code.
October 11th, 2009
Once—in 1988 to be exact—I, proudly, showed my dad the source code of a program—PAP, Pension Analysys Program, to be exact—that I co-wrote with an actuary. Not being a computer literate at all, my father looked at it with little interest, read part of it nonetheless and than said the most amazing thing to me: “Why are there so many errors?” I was baffled, many errors in my code? Looking at this one line—the one showed above to be exact—it hit me. The code was larded with
then Error(). I explained to my father that I tried to catch everything that could go wrong at the earliest possible moment and, with appropriate modesty, that it was a sign of quality code. I tried to explain, ignoring my fathers tell tale signs of boredom, that the
Error() function would hardly ever be executed in the end product. I told him all about error distributions not being normal and their heavy tails not being exponentially bounded. I thought I lost him there because my father was not a math buff, but a financial-adviser. When I had finally shut up, he proclaimed: “So all you are saying is that you do not ignore unlikely potential problems. Good for you.”
October 7th, 2009
If you write any, non trivial PHP script, that reads and writes tekst, you will need to get a feel for the magic in PHP. Because at some point, you start to wonder, where all those backslashes come from. Because quotes in text will grow backslashes with every read-write cycle, like this:
\\\\\\\\\"Sure!\\\\\\\\\". So you set out to find out what is going on:
int fwrite ( resource $handle , string $string [, int $length ] )
fwrite() writes the contents of string to the file stream pointed to by handle.
A file system pointer resource that is typically created using fopen().
The string that is to be written.
If the length argument is given, writing will stop after length bytes have been
written or the end of string is reached, whichever comes first.
Looks normal so far, but directly below than it reads:
Note that if the length argument is given, then the magic_quotes_runtime
configuration option will be ignored and no slashes will be stripped from string.
But of cause, how stupid of me, clearly if I supply a length argument, I would not want to ignore the slashes (that were added apparently by some other “magic” functionality) and be happy to have them in my file, after all they are magic quotes from the great wizard that was born in Qeqertarsuaq, how could I not want that? Or maybe I am one of those exoteric inclined people that prefer solid design over “magic” kludges? But don’t tell anyone, or the last words I will ever hear are: “Stone him! He is the endoheresiarch!”
Read the rest of this entry »