When I read the article from OdeToCode about the abuse of a programming language to create shortcuts, I felt the need to respond.
What is it about ?
Simply stated, it is about using some clever tricks to make it easier for the developer to reach his goal. The example was a stackoverflow post : Abuse of C# lambda expressions or Syntax brilliance?
Which discusses code that looks like this :
.Attributes(style => “width:100%”)
What is the issue here ?
The issue was that the reaction of the c# language designers. They said it was unacceptable to use such a shortcut, since it was not originally intended in the language design. According to them, one should never use such a construct. I firmly disagree…
Why should one be allowed to abuse a development language ?
Simply stated : because you can. Every single thing that can help a developer to make cleaner/safer/better code (in his/her opinion) should be allowed. Why do we develop most of our applications in c#/java/ruby/PHP and not in assembly ? Because using these languages is considered cleaner/safer/better then using assembly. So while the original language designers might not like the idea, the hacks provide an extra cleaner/safer/better way to address a certain implementation subdomain. After all, the language is there as an intermediate between the developer and the hardware, and anything that allows better communication between the developer and the hardware, should be considered a plus… Which brings us to our next point of attention.
Who is saying that the approach you use here is cleaner/safer/better ?
Actually : nobody. That is something that you need to find out yourself. While some people might like to use the shown constuct, others might like the more verbose way of expressing things. Most of the time, these shortcuts are there as an alternative to the “common” way to do something. In most cases, the fact whether you like or dislike something is based on your background/knowledge/reference frame .
The fact that the alternative was built means that somebody had the intention of providing a better/safer/cleaner way of doing something. Whether you agree or disagree with this person is completely up to you… (Although I must admit that I certainly agree with this person). If you look at the dynamicobject feature (another heavy point of discussion), then you might see that this actually does something simular as the shortcut used here, so the language development team is actually doing the same.
So, to conclude, if you think you can make your own life easier by using certain ‘abusive’ constructs : please do !!!