Monsters from the id

Marcel Weiher reminds us that id is the default type, and that it’s perfectly legal to write code like this:

-objectAtIndex:(NSUInteger)anIndex
{
  if ( anIndex < [self count] ) {
    return objects[anIndex];
  }
  return nil;
}

Marcel also writes:

There is a subset of the language, which I’d like to call the id subset, where all the arguments and returns are object pointers, and for this it was always safe to not have additional type information, to the point where the compiler didn’t actually have that additional type information…

What’s great about the id subset is that it makes incremental, explorative programming very easy and lots of fun, much like other dynamic languages such as Smalltalk, Python or Ruby.

10 Mar 2014

Archive