Semantics, James Thurber notwithstanding, is not a town in Ohio.

I think when Rich says "semantics" he means something that can't
really be checked by a machine -- the "purpose or function," as it
were.

I do sometimes wish there were a way to detect semantics -- but the
best we could do is simply remove the problem a step further.

Warning: I'm tired, so I'm not expressing myself as well as I might
at a different time of day.


For example, imagine that we are concerned with a conceptual "append"
operation. We want to know whether an object is capable of being
appended onto.

Well, a string is "appendable." So is an array. So is a file.

   str  << x
   arr  << x
   file << x

Aha! Why not just check for << existing?

Oops. There's a Fixnum#<< which does a left shift!

In short, the first three have very similar semantics, but the
last is very different.

I have at times (almost) wished for a thing rather like Java interfaces:

   obj.implements?(Append)   # where Append is some sort of interface
                             # whose conceptual semantics are agreed on

Sure, modules in Ruby can serve that purpose. But it's rather
inefficient to have 10-15 modules included in a class (especially when
most methods will be redefined anyway).

But even if we had #implements? -- would it really solve anything? Not
necessarily. We would still have to deal with programmers who were
careless, ignorant, or misinterpreted the docs.

Just the random firings of my neurons. Ignore at your leisure.


Hal Fulton