Arnt Gulbrandsen
About meAbout this blog

Branded variables and so on

Why was Modula 3 so good?

The question has bothered me enough that I bought a new copy of Systems Programming with Modula 3 to reread. I reread, and was no wiser.

I liked the brevity of the language description. The designers explictly tried to make the language simple enough to describe in fifty pages. That may have something to do with the clarity of Modula 3 code.

I liked many of the minor features. I've mentioned the 31-bit integers before. Branded native types are another.

In Modula 3, you could define a variable as (I forget the exact syntax) branded msec cardinal timeout; and get protection against unit confusion. If you branded a string as untrustworthy user-supplied input, you couldn't just assign it to an untagged string. If you branded an integer as msec, you couldn't just pass it to a function which accepted a seconds-tagged integer. That half-type gave a pleasant amount of protection against careless mistakes.

I seem to be saying that I liked Modula 3 because it was a compiled object-oriented language with simple syntax, sufficiently expressive, with some good features and no bad ones. Put that way, I admit that's my kind of language.