The World According to Nick |
My take on Software, Technology, Politics, and anything else I feel like talking about. |
Friday, April 16, 2004
My Syntactic Sweet ToothI haven't done a general programming rant in quite a while...so you'll have to forgive me for this one. I'm a fan of little syntax shortcuts in programming languages. You know what I mean, those little things that are assumed in code that a lot of people hate because "they make your code unreadable" or "less understandable". Of course I think that's B.S. It just means that you don't know the language as well as I do :D. Its like saying that saying "I'm" is less understandable than "I am". Unfortunately it seems like these gramatical perfectionists are winning out in C#. A lot of the nice syntactic sugar that I took for granted in C++ is gone in C#. Case in point... null object checking. In C++ you could write the following:
The syntactic sugar here is that an object can be referenced like a bool. If obj is null, then the if statement fails and DoSomethingWithSomeObject() never gets called, otherwise it does. However in C#, you can't do that. There is no implicit cast to bool in this case so you have to write this:
You may say... what's the big deal? Wait... you would actually have to say... what is the big deal. Nothing... its syntactic sugar. But... when you have lots of objects that could possibly be null that you want to check for in order to avoid null reference exceptions, it's nice not to have to constantly, and explicitly say you're checking for null. Plus I think the code visually looks better, and it is generally understood what being accomplished there. And while I'm at it... what's with C#'s inconsistancy in bracing rules?
Ok... that's enough for now.
|
About Me
Name: Nick Home: Wauwatosa, WI, United States I'm a Software Consultant in the Milwaukee area. Among various geeky pursuits, I'm also an amateur triathlete, and enjoy rock climbing. I also like to think I'm a political pundit. View My Profile Archives
Home PagePrevious Posts
Why Gmail Will FailThe Real Reason Behind All the Microsoft Bloggers? More on UNSCAM The Degeneration of the Democratic Party Apparently George Bush Now Runs Every State Canada is a Pleasently Authoritarian Country The French Love Bush After All Short Straw is Mayor? General Sets and Disjoint Sets Someone Explain This to Me Personal Links
Carnival of the Badger
The Coding Monkey del.icio.us Links Flickr Photos Blog Critics Reviews Blogroll Me! music books video culture politics sports gaming www.flickr.com
This is a Flickr badge showing public photos from Nick_Schweitzer. Make your own badge here.
Credits
Design By maystar |