471,354 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

Re: Lambda expressions: Dangerous Madness

On Aug 14, 1:37*pm, raylopez99 <raylope...@yahoo.comwrote:
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.

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

RL

"To try and outstrip each other in the arms race, or to expect to win
a nuclear war, is dangerous madness." - Leonid Brezhnev

this is equivalent: *from C#1.0
ArrayList products = Product.GetSampleProducts(); //fills arraylist
(fanciful example)

foreach (Product X in products) {
* * *if (X.price 10m) { Console.WriteLine(X);} } [suffix m =
decimal]

now redo in C#2 mode:

ArrayList products = Product.GetSampleProducts(); //fills arraylist

Predicate <Productproducts test = delegate (Product p) {return
p.Price 10m;} ;
List<Productmatches = products.FindAll(test);

Action<Productprint = delegate(Product p) {Console.WriteLine(p);};
matches.ForEach (print);

which is actually equivalent to (lambda expressions):
ArrayList products = Product.GetSampleProducts(); //fills, as before

foreach (Product product in products.Where (p =>p.Price 10))
{Console.WriteLine(product);}

*//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.
You are, of course, entitled to your opinion, but lambdas are a part
of C# 3.0, and any C# developer has to know their ins and outs if only
to be able to maintain other people's code.

Also, every time I hear such sentiments - "generics/closures/type
inference/... are hard to understand and compromise
readability" (there were plenty of such as new major language features
were introduced, and not just in the C# land - come read some stuff
people write about Java generics, or the Java closures controversy), I
can't help but think that similar arguments took place back in 60s
during the transition to structured programming ("bah, those
newfangled loops are for lazy people who can't even be bothered to
type proper IF/GOTO - and of course, they result in utterly unreadable
code; look, the condition is checked without any IF present!"), and
then later from procedural to OOP (still plenty of flame on the Net
regarding this topic).

Luckily, there's no stopping the progress. You can invest some effort
to keep up, and join the ride, or you can retire to the same role as
people maintaining legacy COBOL systems today.
Aug 14 '08 #1
0 1027

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

53 posts views Thread by Oliver Fromme | last post: by
26 posts views Thread by Steven Bethard | last post: by
30 posts views Thread by Mike Meyer | last post: by
23 posts views Thread by Kaz Kylheku | last post: by
5 posts views Thread by Octal | last post: by
21 posts views Thread by globalrev | last post: by
20 posts views Thread by raylopez99 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.