Thursday, November 29, 2012

Eric Lippert is leaving Microsoft

Nothing like a fine morning with a cup of coffee and reading news articles and blogs to start off the day, which is practically forged inside my brain as a routine.

I turn on my Google Reader and bam, suddenly I felt like I got hit on the head by a hammer.

I nearly spew my coffee out my mouth when I saw Eric Lippert, a principal developer of C# compiler is leaving Microsoft. I'm sure many enthusiastic C# programmers have already seen the news:

It's pretty surprising how reading a single sentence can make a person s$!t bricks.

Eric Lippert is one of my heroes and a role model for various reasons. His seemingly endless knowledge about the C# language and compiler design is what captivated my interest on him (no homo) in the first place. To list a few posts written by him in his own blog and on Stack Overflow:

Reading each and every one of his posts constantly remind me that geniuses truly do exist in the world and how I basically know nothing when compared to the likes of Eric Lippert.

But what truly enraptured me about Eric Lippert (again, no homo) is the fact that you could make a topic that's generally perceived as dull, nerdy and/or boring then turn it into something very interesting for others to hear - His communication ability is just absolutely fantastic. 

It's really heartbreaking for me to see him leave Microsoft, but I'm also relieved to know that he will still be a part of C# community.

I wish Eric Lippert the best of luck on his new journey and I will continue to support him.

Monday, November 26, 2012

Regions are a code smell? Please!

I'm a C# developer who uses #regions on a daily basis.

There is a fair chance that the above statement threw off a lot of C# developers. Some may even start running riot, accusing me of "jumping the shark" or calling me a "cowboy coder" whatnot.

It's pretty shocking to see many C# developers hating #regions passionately. I have to admit that this has left me completely baffled for a long period of time.

Yes, even the man himself abhors regions. 

Observing all the strong opinions made by the community in programmers stackexchange had nearly convinced me into not using #regions. But then I remember seeing many code samples and tutorials written by expert programmers like Josh Smith use regions extensively. 

Then it suddenly hit my head. These people complaining about #regions have either never developed a WPF application nor deployed a tangible WPF application that utilizes the core functionality and features (MVVM, data binding, command interface etc).

Most of the code samples I've seen that uses #region blocks are from WPF applications. In fact, after much googling I think it is safe to say that it's hard to find a WPF code that doesn't utilize #regions.

The rationale for this is pretty straight forward: you and your companions will never, ever have to look at the folded lines of codes again! Ok, "Never" might be pushing it a little bit too far, but hopefully you get my point.

You might be saying "Ok, the lines of code you wrote does not have to be read again, there's something clearly wrong with the code you wrote". Don't be ridiculous, we wouldn't even have this discussion to begin with if that were the case. 

I sense an in-depth explanation is in order so I'll demonstrate an example: To reap the benefits of WPF, you are often required to do some "setups" to properly get your UI to display what you want. To use a WPF feature known as Data Binding you first need to implement INotifyPropertyChanged interface. Then you define a private variable for your property to refer to, a PropertyChangedEventHandler event, and a user defined property to perform the notification between your UI and business logic of the previously defined private variable.  (Digressing momentarily, if you are a WPF developer who doesn't know what data-binding is, this is probably a good place to stop reading this post and get yourself to really learn how to use WPF).

Here is the important bit: those properties, notification event and any other potential code to make the WPF feature to work are merely prerequisites to get your code working. In other words, once you verify the data binding working as intended, there is practically no reason to look at your setup code again. Now for those who are versed in WPF will readily recognize that all this code typically goes inside your ViewModel so consequently, that is where you see the regions used most frequently.

The following is a sample code from Josh Smith's WPF Treeview Tutorial:

Seriously, all of what's above is just noise to me. Without even having to look at the code, I expect the necessary properties and interface methods to be in the viewmodel so scrolling down through all this unnecessary, expected information is just a waste of time. 

Now what would be preferable to see is the following:

Immediately, I know that when I'm reading the code, I will probably never have to look at the folded portions, because all they do is relay the information from UI to Business Logic (Model). Everything is organized in a nice fashion, so if by any chance we really needed to fiddle around with our viewmodel, we immediately know where to add our necessary data/property/interface methods. Had the regions not been there, I would've had to scroll miles down my IDE to determine exactly where everything goes.

Admittedly, the above example might be taking things too far - it isn't necessary to literally group everything in regions. For instance, I think just wrapping the properties would've been sufficient.

But the important point I wanted to bring is this: it's OK to have a dogmatic belief or a strong preference towards a particular coding style, as long as it logically makes sense with your colleagues and it helps solving a particular problem. Part of what makes a good programmer is the ability to choose the right tool and having the correct approach to the problem you are trying to solve. The real harmful practice is to state an absolute such as "Never or Always" without considering other domains (Goto statement is an epitome of this, at least for the case of C#).Also remember that programming languages evolve continuously - what might've been a bad practice in the past can very well be the recommended approach now. 

As for the fellow developers, including Jeff Atwood whom I have a lot of respect towards, you can keep hatin' on the #regions but for us WPF developers, no thanks. We will keep using them :P

Sunday, November 18, 2012

Grand Theft Auto 5 - Soviet Russia

Why buy the game when you can play it IRL?