Tuesday, November 6, 2007

More wasted time today

This week, I spent (read: wasted) a lot of time.

  1. Some database did not have a foreign key constraint, and a user removed some data that was referenced elsewhere.
  2. Some customer managed to call a function, passing an object that had just the appropriate method names, but was definitely not the appropriate object.
  3. I needed to map object properties to fields in a CSV file. By name.

Why? Again because the constraints are not at the right place. When you remove data from a database, some other place that relies on that data to be present will fail. It will fail much after the original cause. And that's where you lose all your time, trying to get back in time from the error message to the actual event.

Dynamic typing is like doing that all the time. You do not get an error message when you call a method with the inappropriate arguments. It may be some totally unrelated piece of code that fails.

Now, you might say, my database was not very well tested. That is true, it's entirely my fault that the integrity constraint was not there. Or was it? The constraint can be removed at any time, by anyone. I do not have a guarantee that my constraint is still there in production code. Welcome to dynamic programming!

Not for me, thank you.

Saturday, September 29, 2007

Silliest pro dynamic typing argument to date

According to this paper (see in particular section 2.3) race conditions in multithreaded programs occur because of static typing. Dynamically typed systems are a cure for this, of course :-)

Section 2.2, we learn that having your method either handle exception RMIException, or statically declare it in its throws clause, leads to an abstraction leak. Does he realize that RMIException derives from RuntimeException, and as such does not need to be listed in the throws clause?

This, and many other hilarious fallacies (mainly if you tell the compiler that class A implements interface B, then you should be allowed to code only the part of B that you care to implement kind of stuff) makes for a good laugh.

By Grabthar's hammer, do dynamic weenies have any clue what they are talking about?

Unfortunately, this nonsense seems to emanate from a guy having some position (janitor apparently) in a known university, and presented in the standard format for academic papers, and so will be touted by Rubyist as academic proof of soundness for their beloved concepts.

Saturday, September 22, 2007

Why Java programmers are afraid of dynamic typing

Read the Ruby blogs. All hardcode Java programmers are described as being "afraid" of moving to dynamic typing. One post goes as far as saying that Java programmers feel that static typing gives them a sense of security, because they fear that their fellow Java programmers are idiots.

The article is right, but for the wrong reasons. Now I know why Java programmers are afraid of moving to dynamic typing: as long as their programs use static typing, they can rest assured that no Rubyist will join their team and make the same old mistakes in a brand new way :-)

Friday, September 21, 2007

Types as automated tests of your design

Apparently, I praised the concept of blessed interface.

No, I'm not. I'm just saying that if you rely on an interface, then explicitly define that interface instead of letting it magically appear from your coding. No, you should not predefine your interface and stick to it whatever the cost. Yes, during the development phase, the interface will evolve until it contains what you need.

But when this is done, you have defined an expected behavior. You have successfully built an abstraction. Congratulations.

Now, imagine you have trouble defining that abstraction, because you keep adding to it, or you can't possibly find a way to express what you want. Congratulations again. You have found a flaw. Do you think you've found a flaw in the concept of static typing? Think again. You have probably found a flaw in the way you try to model the problem space. You are probably writing code that is expecting too much of the object it receives.

One guy complained that once he created the concept of Ball and added a radius to it, there was no easy way of defining a rugby ball, because it was not spherical, and thus radius had no meaning. He - of course :-) - blamed static typing for his own mistake of making all balls in the world round.

Static typing requires you to think in order to find appropriate abstractions. If you can't find them, or need them to change constantly, you have an incomplete - or plain wrong - idea of the reality you try to model. Types allow you to test your design against reality. Yes, your design will be better if you use properly designed interfaces, it will relate to problem space. Yes, it is worth the cost, because this interface is no less than an automated test against your comprehension of the problem.

Friday, August 31, 2007

The conclusion indicates where you stopped thinking

In a technical article, the conclusion usually indicates where you became tired of thinking, and want to leave the rest to the reader.

When doing analysis, I need to recognize behaviour in objects. In design, the type I give to my objects is the conclusion I reach. Programmers tend to favor duck typing because it allows them to skip the part where they have to build and recognize abstractions, and they can simply implement all needed objects without actually giving them a type.

When using duck typing, if an object implements walk() and quack() they can treat it like a duck, but they do not have to define exactly what a duck is, nor do they have to explicitly recognize duck behaviour in their objects. More precisely, they longer need to reflect the is-a hierarchy using types, but simply a behaves-mostly-like hierarchy using classes. This is of course much simpler to design, as they may throw theoretical issues (like the Liskov Substituion Principle) out of the equation.

When using static typing, I have to recognize up front that my function requires duck-like behaviour, I have to precisely define what duck-like behaviour means (that is define a type, not a class, in the form of a DuckInterface) and identify precisely which classes in my hierarchy exhibit duck-likle behaviour (and make them implement the DuckInterface.)

Static typing does not limit my expressiveness. It merely forces me to think about what I'm saying before I actually say it. It means that I have to carefully identify the abstractions and design the corresponding interfaces. It means that I have to recognize the difference between subtyping and subclassing.

I am reasonably good at building and recognizing abstractions, and that is why I don't usually need duck typing. If you are not good at handling abstractions, then you will find that duck typing greatly simplifies your work. Consider it the "lite" version of object oriented analysis and design. You do not define types, you just let the reader discover them.


However, the lack of clearly defined types has its price: interfaces are the building blocks of loose coupling, so you need to design them anyway. In duck typing, interfaces will tend to emerge from the code instead of the analysis; this might not be the best way, as you usually end up with ad-hoc types instead of carefully thought ones.

Sunday, August 26, 2007

From the master himself

I know it's a long time ago, but in an interview with Bill Venners, on November 17, 2003, the master Yukihiro Matsumoto himself said:

So for day-to-day programs that aren't not as serious as enterprise systems, you don't have to be as robust. It's not worth the cost of declaring types, for example.

So he agrees: declaring types has a cost, but it adds robustness.

http://www.artima.com/intv/tuesday3.html

Saturday, August 25, 2007

Dynamic typing, the keyboard and the mouse

Dynamic typing proponents like to think that way: type errors are not frequent. It is therefore best to have a language that allows you to plug any object anywhere, and write tests that ensure your program is doing what it should, instead of restricting your choices in the first place.

Using a dynamic language is therefore like not-so-long time ago computers that had exactly the same plug for the keyboard and the mouse. At startup, if you plugged the mouse in the keyboard socket and vice versa, your computer did not emit blue smoke but it did not work either, and you had to unplug and swap the cables.

This was not user friendly. Dynamic languages are not user (where the user is the other programmer that has to use your object) friendly.

Friday, August 24, 2007

Yet another attempt at publishing my code

I registered an open source project on Google Code today. This is the n-th attempt at publising my source code reliably.

I tried SourceForge (a long time ago) and was never able to use it properly. Either you need a complicated set of tools to do SSL tunnelling (just in case someone impersonates your connection; hint: I don't care if FTP is not as secure as it should be.)

Next I tried to enable Subversion on SourceForge. Never worked.

Then I switched to GotDotNet. The source control client never worked properly. And the site was shut down shortly afterwards.

Then I gave a try to CodePlex. I was happy with that one. It had (almost) all I dreamed of. Except of course a reliable backup, so a guy hit the wrong switch and whoosh all my data was gone. This disagreement led Microsoft to discover that their backup procedure was sub-optimal (i.e. the backup could not be restored :-) Not only mine, by the way. Dozens of projects were gone for good.

Now I am willing to try again... Oh but I miss some of the CodePlex features though. Anyway, let's hope it will work this time.

http://flimbase.googlecode.com

What's in a title

Welcome to my coding blog. This is where I will rant about the features I miss in my usual programming languages, make fun of other people's errors, and sometimes say something sensible about programming. Expect topics about why I like multiple inheritance and static typing.

Now. Where does that silly title come from? From a book I owned a long time ago, titled Microsoft Basic Decoded & Other Mysteries for the TRS-80. This book contained the entire disassembly of the TRS-80 Model I, Level II Rom. It used a clever technique to avoid copyright problems. I think you can still order it... from Russia: http://www.urss.ru/cgi-bin/db.pl?cp=&page=Book&id=18425&lang=en&blang=en&list=319