Google
 

Saturday, December 29, 2007

The search for string enumerators

Of all the languages I've worked with so far, C# is by far my favourite. My list of reasons for this is quite long, but in spite of all that, I still have things I enjoyed very much in other languages that C# lacks. Simple examples are Cobol's EVALUATE statement and Visual Basic's string enumerators.

Under the hood, the EVALUATE statement is the equivalent of a series of else if statements, except that the debugger does a very elegant job of jumping straight to the else path that is true instead of stepping through every single one until it finds one that it likes. Not a big deal, but certainly something I miss.

The string enumerator, on the other hand, is sorely missed. I have yet to find a good way to implement one in C#, and so am embarking on a mission. I've seen several suggestions out there, ranging from simple ones that use string formatting to extract the names of an integer enumerator to more complex ones that use reflection.

Suffice it to say that I didn't like any of them. Too simple, too inelegant, etc. There has to be a good way out of this that will not be too complex to implement, will be elegent to code and use, and will resemble the normal enumerators as much as possible (preferably to 100%).

No comments: