The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Transient Collections

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Transient Collections Posted: Oct 14, 2004 11:13 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Transient Collections
Feed Title: David Buck - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/buck-rss.xml
Feed Description: Smalltalk can do that
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From David Buck - Blog

Advertisement

Something that I find interesting about the Collections classes in Smalltalk compared to C# or Java, is that Smalltalk collections often tend to be treated as transient objects which are never assigned to variables. For example, consider the following code snippet:

	commands reverse do: [:each | each undo]

This is possible because the reverse method copies the collection and returns the reversed collection. In C#, there is a Reverse method, but it acts destructively on a collection and has no return value. The corresponding C# code would be:

   reversedCommands = commands.Clone();
   reversedCommands.Reverse(0, commands.Count());
   foreach (Command reversedCommand in reversedCommands)
      reversedCommand.Undo();

There's actually no reason why you couldn't define a Reverse method for C# which is non-destructive and returns the new collection, but Microsoft simply didn't provide it. They don't seem to see that collections may be used transiently and you may not want to have to assign them to a variable.

In Smalltalk you see this technique used frequently with select: collect: reject: and so forth. These methods take a block and return a collection which non-destructively derives from the original. These can't currently be implemented in C# because it has no lexical closures (blocks). The next version of C#, however, will have anonymous methods and should be able to support this kind of operation. I wonder if the Microsoft view of collections will change when this becomes possible.

Read: Transient Collections

Topic: Thinking in tests Previous Topic   Next Topic Topic: Still plugging away on 3.7

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use