Re: Lambda expressions: Dangerous Madness

Tech-Archive recommends: Fix windows errors by optimizing your registry



raylopez99 <raylopez99@xxxxxxxxx> wrote:
Took a look at all the fuss about "lambda expressions" from Jon
Skeet's excellent book "C# in Depth". Jon has an example, reproduced
below (excerpt) on lambda expressions.

My n00b take: it's like SQL and those 'high level' languages that try
to be too clever by half and pack a lot of syntax in as short a space
as possible. Like Egyptian hieroglyphics, like Chinese, like those
non-alphabet languages, it's just way too much information in too
short a space. Sure, writing a program with this syntax will reduce
your source code from 100 pages to 10, but at a cost of readability.

I'd say they greatly add to readability, actually. Yes, you need to get
used to them first, but that's no reason to avoid them.

I think there's actually a shock value in how much you're able to
express in so little code - when you're used to verbose code, it can be
alarming to see how compact it can really be when you have suitable
language features. That's a perception issue though - not a
maintainability issue.

But what do I know? I only have a couple months real experience in
the language. Don't listen to me.

Many powerful features look too hard to start with. Give them a chance
- when you're familiar with them, lambda expressions are *wonderful*.
What would you rather write:

products.OrderBy(product => product.Price)

or

products.OrderBy(PriceComparison)

.... later on in code (second version only) ...

int PriceComparison(Product first, Product second)
{
return first.Price.CompareTo(second.Price);
}

? I know which one *I* find clearer and easier to modify when
necessary.

//Jon humorously states "the combination of the lambda expression
putting the test in just the right place and a well-named method means
we can almost read the code out loud and understand it without even
thinking" HA HA HA! Right. I guess beauty is in the eye of the
beholder.

I wasn't kidding. Read the code out loud - it does exactly what it
says. That's great for readability.

--
Jon Skeet - <skeet@xxxxxxxxx>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
.



Relevant Pages

  • Re: How about this syntactic candy?
    ... Well, first of all, lots of languages do okay without that. ... suggested one little syntax change. ... The changes in C# 3 actually *vastly* improve readability once you're ... While the new elements such as lambda expressions are ...
    (microsoft.public.dotnet.languages.csharp)
  • Lambda expressions: Dangerous Madness
    ... Took a look at all the fuss about "lambda expressions" from Jon ... it's like SQL and those 'high level' languages that try ... your source code from 100 pages to 10, but at a cost of readability. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: "0= if" or simply "if" ???
    ... Fortran instead of "if x". ... Adopting locutions tin Forth to make it more transparent to those accustomed to other languages makes no more sense to me that adopting locutions in English for the same reason. ... I think that in your last post the readability is opaque in both cases and would need elicitation by any person not familiar with the implementation. ...
    (comp.lang.forth)
  • Re: Ping Nick: Why Language Doesnt Really Matter
    ... I am convinced that the fact that languages like C ... pretty much the same when it comes to readability and productivity" is ... Readability is just one factor in productivity, ... availability of libraries, compiler speed, availability of an ...
    (borland.public.delphi.non-technical)
  • Re: [dfwPython] A Few More Forrester Survey Questions
    ... Robustness - bugs in Python itself are rare due to maturity from long ... Mature ecosystem of libraries, both cross platform and platform native, ... and good options for accessing libraries in other languages. ... to manage due to readability problems. ...
    (comp.lang.python)