A weblog about programming in Python, C#, Java, Perl and C++ - and the occasional comment on PyCS development
new: discuss community servers on the CommunityServerWiki!
me
the locals
offsite
also available in XML
Copyright (c) 2002 Phillip Pearson
|
2002-7-5Extending language syntaxA few months back I started trying to design a programming language. Then I discovered Python, and realised it was far more useful than anything I was likley to come up with. Then I discovered C#, which does a lot of things better than Python, but at the same time sacrifices a lot of the things that make Python so fun to program with.
It would be an interesting task to write a preprocessor to 'extend' the C# language to let you do stuff like list comprehensions, or quick declaration of dictionaries and arrays.
Wouldn't it be cool if you could say something like:
Hashtable Foo = { "one": 1, "two": "two", "three": 3.0, "now": dateTime.Now };
... or ...
ArrayList bar = [ 1, 2, 3 ];
... or ...
ArrayList baz = [ d.Year foreach DateTime d in listOfDates ];
These would generate something like:
Hashtable foo = new Hashtable();
foo[ "one" ] = one;
foo[ "two" ] = two;
foo[ threeKey ] = three;
foo[ "now" ] = DateTime.Now;
... and ...
ArrayList bar = new ArrayList();
bar.Add( 1 );
bar.Add( 2 );
bar.Add( 3 );
... and ...
ArrayList baz = new ArrayList();
foreach( DateTime d in listOfDates )
{
baz.Add( d.Year );
}
That would probably halve the amount of code that I write in C#, bringing the overhead down to the level of Python. It will seriously kill IntelliSense though, and IntelliSense is the main reason I like C#. Hmm. Is it possible to extend the IDE to know about things like this?
In related news, my C# data object wrapper generator is working (generating lots of C# code which compiles and seems to go fine) and just needs the addition of a few 'isDirty' flags so Commit() knows what to send back to the database. I'll release the source in a few days, probably.
It's making my database code look much cleaner. I now only need to specify my DB structure once (in XML), run MakeWrappers.py, and suddenly I've got all my database fields from my queries into tblFoo available as properties of a FooRow object.
Comment on this post [ so far] |