NULL’s a Bitch

No Comments »

Anyone that wrote any non trivial SQL query with an outer join, will know: NULL‘s a bitch. By the time you learn to write:

SELECT * FROM T  -- contains bitches.
    WHERE IFNULL(A = B, FALSE) OR (A IS NULL AND B IS NULL);

your hair has turned gray, if you did not pull it all, that is. When the ω—the symbol for ‘unknown’—was introduced by Codd, I guess he basically tried to support ternary logic. Later, he must have realized that ω, in non boolean columns, can stand for many different problem specific meta-values. In version 2 of The Relational Model for Database Management (Chapter 8), he tried to remedy the problem by splitting NULL (ω in SQL) into A-mark (applicable-value mark) and I-mark (inapplicable-value mark). But first, this sinned against Bruce MacLennan’s zero, one, or infinity principle and second, almost nobody adopted it. Hence different SQL implementations handle non trilogic usage of NULL differently. For example the expression 'A' || NULL || 'C' has different values in different SQL implementations. The same goes for aggregates, COUNT(*), NULL / 0, and indexing. Also a whole host of NULL related functions were invented like COALESCE(). Since any usage of NULL can be mimicked by adding a boolean column and some careful code, I am of the opinion that the introduction of NULL was a huge mistake, and the current standard and implementations aggravate the problem by implementing a lot of undefined or implicit behavior. Other solutions that would have been better are (user-definable) meta- or default-values. Anything but NULL.


Forget My Number

No Comments »

Sometimes impossibles find their way into your code specs, like an intuitive GUI component that will make complex selections simple, or a wrapper that will make application objects into distributed objects, transparently. The list is endless. This is when all those theory courses, finally, pay off. You just know it is impossible instantly, where you otherwise would waste days trying the impossible. Or worse, you actually implement something. Because of the world wide web, nowadays, you can skimp on theory classes and use Google. For example, Merchants who take credit cards over the Internet for payment need to get rid of the number the microsecond after they’ve placed a hold on the funds, because it is impossible to store that number in a form that is both searchable and secure. (Cranky IT Guy) [How to secure a credit card number] (via: DI) You don’t have to know, anymore, about Knuth, Shannon, Dijkstra, Chomsky, Turing, Erdős, Parnas, Minsky, and the many others. But they are still fun!


Move It Up

5 Comments »

CitydiscIn 1992, I coded the first incarnation of yellow pages on-a-map, CityDisc, the brainchild of Ben Hoefnagels, a great guy and visionary. I really liked to work for him. He would tell me what he wanted, and let met code. In those days, software had to run on a 6 MHz Intel 80286 from a 720kB floppy disc. I explained to Ben than in order to fit 3000 streets (and 30.000 addresses) on one floppy, we should use vector graphics. So Ben told me: “OK, go do it!” This first prototype was rather slow. So Ben told me: “Make it faster!” Profiling showed that 92% of the run time was consumed by one function: sqrt(). Small wonder, coding vector rendering is all about Pythagoras. For hours I, fruitlessly, tried to make a fast my_sqrt(). Then I moved the problem up one layer of abstraction. If I could not speed up sqrt(), I might find a way to speed up the function that used it: the length() function. On a hunch, I tried:

#define length(x,y) ((x > y) ? (x + y/3) : (y + x/3))

I hit <Ctrl><F9> (Yes, Turbo C.) and BANG there was the map, almost instantaneous. I never forgot that lesson: Problems can be hard on one level of abstraction but easy on an other.


The Art of Redundancy

4 Comments »
            [oo ]    [oo ]    [oo ]    [oo ]
            <   >    <   >    <   >    <   >

            [ oo]             [ oo]    [ oo]
             > <               > <      > <

            [oo ]    [oo ]    [oo ]
            <   >    <   >    <   >
 
               V
                         V

                                V
                                   ^



                                <_I_>

In 1981 I coded a Space Invaders clone for the Apple ][ Europlus. I knew I should not have used Microsoft’s super slow Applesoft BASIC, but I just did. It was an animated ASCII-art program with a main-loop moving 12 invaders, the defender, the up-bullet and the five down-bullets. The latter two with collision detection and scoring. However it was not fast enough. I then tried, what I now would describe as redundancy. I replaced the code that printed the 12 invaders one at a time with one that would print 4 at a time (i.e., a whole row). I used ON (II%*2+FF%) GOSUB to go to any of the (2^4)*2 “subroutines” that would print the correct row. That made the game totally playable. It taught me that redundancy is not always a bad thing.


Actions are Buttons, Places are Links

1 Comment »

Picture 1Three 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.)


Choosing a Language

No Comments »

Managers often are confronted with a need to choose a programing language. Usually they ask themselves questions like: “How simple is it to learn language X?”, “Do our coders like to switch to language X?”, “How well does our IDE support language X?”, “How well known is language X?”

These questions, however, might not be all that relevant. While a Turing Machine can be used to code graphic animations, probably a more abstract and domain specific language like Processing would be more productive (and fun). However a Turing Machine might score better on the questions above. The more relevant questions for selecting a language focus on two terms domain and abstraction. I won’t try to explain why, or even define these two terms (click the link, Luke). Suffice it to state that: Experienced coders use more abstract features to make more compact code and, thus, be more productive. Domain specialists use more domain specific features to code quicker and, thus, be more productive.

One could be forgiven the mistake of thinking that the more abstract a language is the less domain specific, and vice versa. A random counter example is PostScript, a powerful, abstract, concatenative language, used almost exclusively in the domain of printers.

So if you employ a domain specialist (count your blessings and) choose a domain specific language. If you employ a code wizard (count your blessings and) choose an abstract language. About the worst you can do, is pick a abstract, general-purpose, multi-paradigm language like Python for a mathematician to code math models. Best case this will eventually lead to a huge and clunky library stack like Python(x,y), that dictates every other aspect of all the code that interfaces with it. Very soon, the lack of flexibility will drive everybody back to using a spreadsheet for their modeling. Maybe a better choice would be a language like R, or indeed that spreadsheet.


One Thousand Cuts Per Day

No Comments »

musashi-sDo 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.


Oil to Voice

No Comments »


In our category CodeReuse, today, the step from oil-echo-location to auto-tune. And yes, you can have it on your iPhone [I am T-Pain].


Look Ma No Web Developer Toolbar

No Comments »

I use the following bit of CSS to help visualize the structure of an XHTML (or HTML) document by putting a colored outline around the border of every element. At each level in the hierarchy the color changes so you can see when “depth” changes.

  * { outline: 2px dotted red }
  * * { outline: 2px dotted green }
  * * * { outline: 2px dotted orange }
  * * * * { outline: 2px dotted blue }
  * * * * * { outline: 1px solid red }
  * * * * * * { outline: 1px solid green }
  * * * * * * * { outline: 1px solid orange }
  * * * * * * * * { outline: 1px solid blue }

I usually keep this block of rules at the top of a stylesheet, commented out with /*…*/, which I remove when I want to see the structure. (Chris Page) [A Handy CSS Debugging Snippet] Almost as handy as Web Developer Toolbar Add-on for Firefox. [via: DI]


Breaking Software Development

No Comments »

Why are programmers so fussy about their employers’ morals? Partly because they can afford to be. The best programmers can work wherever they want. They don’t have to work for a company they have qualms about. […] And it’s not fun for a smart person to work in a place where the best ideas aren’t the ones that win. (Paul Graham) [Apple’s Mistake] True that. If you want the best programmers, be the place they want to be at hardest. If you want the smartest programmers, don’t give them a manager that want’s to win, give them one that wants to serve. [via: DI]