Brushing teeth and static checks
The three-year-old at home doesn't like having his teeth brushed. I don't blame him. It's hard at that age to see why someone would get to mess around with a brush in your mouth, when you'd rather be reading a bedtime story, or play with your toys.
But I, a crafty father, have developed a trick. Experienced parents will recognize this as a kind of distraction tactic.
<masak> Noa, I'm going to paint inside your mouth.
<noa> Red, and white, and blue, and pillow.
What he has specified here is a list of colors (different each morning or night), but the last item is not a color. I start brushing, and slowly list the colors he has picked:
* masak brushes noa's teeth
<masak> Red... white... blue...
<masak> ...pillow... HEY, WAIT A MINUTE!
* noa laughs, toothbrush in mouth
Voilà, a boring chore has an element of silly in it, and is much easier for both parent and child.
In programming terms, the item "pillow" doesn't belong in a list of colors. (It doesn't typecheck.) My scripted mock surprise at this makes the three-year-old feel like he has somehow outsmarted the tooth-brushing routine — instead of being an involuntary recipient, he is an active participant (and a mischievous one at that). He's a tooth-brushing renegade.
Some programming languages are permissive like that: they accept any (syntactically correct) program, start running it, and only later exclaim "HEY, WAIT A MINUTE!" when your program runs into some fairly obvious trap or other. The programmer's reaction is usually "oh right, shucks, better fix that", possibly after some thinking and tracing around the code.
Other languages are more strict, and disallow many such mistakes at compile-time (or earlier). The checks are often type checks, but could also be other things, such as reachability checks.
There are long-winded discussions and arguments on either side about which type of language is better suited for various tasks. Briefly and a little bit inaccurately, those can be summarized by weighing flexibility/freedom on the one hand against correctness and safety guarantees on the other.
But my first thought was Most or all of these problems would be caught by TypeScript. At least if you use TypeScript with enough strictness turned on (such as the options
strictNullChecks), and provided you don't cheat and manually type variables as
My second thought was Why do we do this to ourselves?
So, yeah, go check out TypeScript if you haven't already. You might like it. TypeScript's designer Anders Hejlsberg (of C# and Delphi fame) once described TypeScript as a value proposition it's not rational to refuse. It has only benefits, and no drawbacks. That about sums it up for me.
null was a billion-dollar mistake, here's a wild idea but maybe we should try using a language without them?)
News & feeds
Focus on Business Value with Scrum
How do we, as a company, keep our focus on Business Value, when we our teams are dominated by technical people and developers, who are not always even expected to see the bigger picture. How can Scrum be at help?Read more >
Take a course in Prague
We are proud to announce that, starting from May, Edument will also offer courses in Prague. Now you can enjoy and be energized by spending time in one of Europe's most beautiful cities, at the same time as attending one of our popular courses!Read more >
Edument 8 years!
8 years ago Acke Salem and Tore Nestenius started Edument AB. To celebrate this we're offering great discounts!Read more >
Brushing teeth and static checks
The three-year-old at home doesn't like having his teeth brushed. But I, a crafty father, have developed a trick.Read more >
CSS selectors are evil and JS is the solution
A pragmatic demonstration of the drawbacks with CSS selectors, and how inline styles through JS solves these problemsRead more >