Le 16 janv. 07 à 19:37, David Chisnall a écrit :

On 16 Jan 2007, at 00:53, Quentin Mathé wrote:

ok. At some point, I will surely move it into EtoileFoundation.

Shiny. Nicolas and I were talking the other day about having a macros.h file somewhere that could be used for all Étoilé applications. He had some for quickly creating dictionaries and I had some for iterating over collections (a FOREACH macro semantically equivalent to the new for statement in Objective-C 2).

I have been thinking about having such foreach macro recently but haven't done anything yet.
My reasons in favor of foreach would be:
- it is badly easy to forget setting or resetting initially to nil the variable used to store the current iterator value
- it is boring to copy/paste this boilerplate code over and over
- it is painfull to refactor a method that contains more than one iteration This following blog entry <http://mjtsai.com/blog/2006/07/15/cocoa- foreach-macro/> discuss some interesting improvements like imp caching and optional type checking.

For dictionnaries or arrays, I was considering using JSON or a simple plist string to set up a new collection. Something like [NSDictionary dictionaryWithString: @"{ key = value; ... }"] and a shorcut could be [NSDictionary dict: @"{ key = value; ... }"] But in the end a macro is probably better since it defers less checks to runtime. It's surely even shorter too.

My initial idea might be still interesting with something like [NSPropertyListSerialization propertyListWithString: "a complex plist string"] that would return an object tree made of array and/or dictionary. Renaming [NSPropertyListSerialization propertyListWithString: "a complex plist string"] to [ETCollection collectionWithPListString:] may feel more intuitive. ETCollection would be some kind of generic collection abstraction.

Otherwise I think it could be quite nice to duplicate some NSString methods but with shorter names. For example [NSString concat: @"bla"] would be identical to [NSString stringByAppendingString: @"bla"]

Quentin.

--
Quentin Mathé
[EMAIL PROTECTED]


_______________________________________________
Etoile-dev mailing list
[email protected]
https://mail.gna.org/listinfo/etoile-dev

Reply via email to