smalltalk

Everything old is new again

July 23, 2004 16:13:47.916

The MS guys are rediscovering yet another old Smalltalk idea - treating an object as if it were an array. Take a look at #instVarAt: and #instVarAtPut: in class Object (never mind that doing this sort of thing is typically a very, very bad idea):

http://www.csharphelp.com/archives/archive140.html

C# introduces a new concept known as Indexers which are used for treating an object as an array. The indexers are usually known as smart arrays in C# community. Defining a C# indexer is much like defining properties. We can say that an indexer is a member that enables an object to be indexed in the same way as an array.


   this [argument list]
 {
  get
  {
   // Get codes goes here
  }
  set
  {
   // Set codes goes here
  }
 }


Of course, the beauty of this is that C# had to add new syntax to do this, while the equivalent Smalltalk functionality is just another set of methods. So the C# guy has to memorize yet another set of reserved words, while the Smalltalker simply looks at the library. Sometimes I'm amazed at how Java and C# are examples of Smalltalk being re-invented - but with a crufty, inelegant syntax....

 Share Tweet This
-->