General musings on programming languages, and Java.

Wednesday, February 20, 2008

When would you choose to repeat types?

I was surprised to see that some developers would prefer to repeat code with different
names rather than using abstractions.

In other words they name types by the way they're used instead of what they are.

I always like to consider the extremes of always applying a rule or never applying it.
If we made every use its own type we'd have lots of conversion functions to write
to avoid code duplication (but of course those functions would be duplicates).

The other extreme would be only naming a type by what it is so you'd never have
NameAndAge and AddressAndYear, you'd only have StringAndInt (or Tuple[String, Int])
and the meaning would only be shown by the use.

Tony Morris generally seems to agree, but he would give names to types when the
typesystem cannot express important things about the type, such as associativity.

AssocF[Int] instead of F[Int, Int, Int]
I've seen people prefer names for types in all cases, so they would never want
tuples or function types in their languages.

I think these programmers have a fear of abstraction. What do you think?

Blog archive

About Me

A salsa dancing, DJing programmer from Manchester, England.