
 	Your Abomination Is My Clever Hack - johns
http://odetocode.com/Blogs/scott/archive/2009/11/30/your-abomination-is-my-clever-hack.aspx
======
aidenn0
Is this really seen as an abomination in the C# community?

My argument for why this is good seems pretty simple:

1) The code that does this isn't _that_ hard to understand

2) All code that uses it becomes much more readable

3) The total of all code in #2 is going to be modified more often by several
orders of magnitude than the code in #1

~~~
aidenn0
After reading the stack overflow discussion, it's clear there are some
reasonable arguments, particularly that it is not good for interoperating with
other languages on the CLR.

However, it also appears that most people on that discussion would disagree
with my point #2 (code using this becomes more readable). That's probably
where the interesting things come in to play.

For me, I don't care about abuse of syntax, etc. as long as code does what a
casual observer would guess it does. Perhaps I'm spoiled by working somewhere
where people actually write readable code, and if I worked somewhere else, I
would want to forbid any syntax magic whatsoever, but more likely I would just
be updating my resume :)

------
amix
Python's optional arguments feature is useful for these kinds of polymorphic
usages - and I miss them every time I program in other languages (especially
Java). In JavaScript I miss named arguments (e.g. _def fun(name, age,
gender=1, height=None)_ ), which is very useful especially if one calls stuff
like _Person("Bob", 13, height=150)_.

Generally, I don't think these kind of improvements are appreciated in C# as
they are polymorphic and make it much harder for the compiler.

    
    
      The optional arguments feature is to define a function like def fun(..., **kw)

~~~
StrawberryFrog
C# 4 has exactly this feature.

------
mhansen
Blogspam, devoid of content. See the original for a much more thorough
discussion.

[http://stackoverflow.com/questions/1718037/abuse-of-c-
lambda...](http://stackoverflow.com/questions/1718037/abuse-of-c-lambda-
expressions-or-syntax-brilliance)

~~~
gjm11
Clearly not blogspam by any reasonable definition, but I agree that the Stack
Overflow post has more interesting content.

------
bitwize
Way to break alpha-substitutability, guys. I expected this from the Rails
crowd, but somehow I thought better of the .NET community.

Or, as Steve Summit put it to me when I told him about this, "The audience
leaps to its feet and shouts 'NO!'"

------
jrockway
I don't really get it. Is => not a pair constructor in C#?

~~~
StrawberryFrog
What's a pair constructor?

"=>" is the C# lambda operator, which makes an anonymous function. Args go on
the left of it, the return value on the right. In most cases, the names given
to args don't matter.

~~~
jrockway
Ah, then no, it's not a pair constructor.

~~~
jrockway
(I should also say that in Perl it is, and that's why this code looks
perfectly normal to me. I imagine it's frightening to a C# programmer!)

~~~
StrawberryFrog
_I imagine it's frightening to a C# programmer_

C# programmers everywhere are heartened by your condescension. Not. Thinking
of it as a pair is not going to help you understand it.

from TFA:

 _The syntactic trick is how the API uses the name of the lambda’s parameter
as the name of the HTML attribute_

If your function is passed a function of one parameter, then it is a bit of a
hack to vary behaviour based on the _name_ of that parameter. But I'm OK with
it, since it works quite well.

------
wlievens
I don't get what the problem is. This seems equivalent to Hibernate using
reflection on fields in Java classes. Distilling your own syntactic sugar can
be a great thing.

------
aaronblohowiak
As a rubyist who also programs in c#, i'd say that this is pretty gross.
Internal DSLs are part of the ruby culture. In c#, the ability to look at code
and understand its execution _and_ its intent is the objective. With syntax
manipulation like this, the underpinnings of the language that are normally
hidden now must be considered... it is out of character.

~~~
jrockway
Isn't LINQ, an internal DSL, one of C#'s main selling points?

~~~
StrawberryFrog
LINQ is an internal DSL, and it's a big selling point of the C# 3.5 release. I
don't think I'd go as far as to call it " one of C#'s main selling points".

The thing is, c# coders cannot build their own LINQ-style DSLs in c#. Rubyists
do build thier own DSLs in Ruby.

------
clistctrl
I personally do not like it. My problem with it is not readability (because it
looks very clean) but consistency. When developing an API I always strive to
make it as intuitive to use. My #1 goal is always, could you use this without
documentation? This hack would make me answer no, its too inconsistent from
the norm. I can only hope he mentions how to use it in the ///<summary>
comment

