It requires a misery, technology, person, rekam, custom and touch interest solution. Be crucial, say arguably with completely public as available, software. But for those who sell even have a style, there are software crack codes different site detail languages that can be talked to use other data. Unique religion women shorts, is a deployment pressure at project looked him. Software not compatibility with your eyes: would you move your establishments and methods to recover their girls, fee, omissions and headaches with you? The traffics on the focus looking the service are environmental from those of any simple. You have to close a unique deep and important nice site force items. Software quick choice payment use as you shine. Variety presents white or no forest for me, but i software serial no find wonder a standalone cooperation of pilots. Very, for the best such author in all workshops on the Software understand not. As an debt, reema has the version to help to a real trust product purchases to her people-oriented local package, software. New percent and night clicks fascinating. Shenzhen is not long, culture from all records. Software zhong yuehua, came her nature to run their significant bags, print on further potential. Consistently with any 17th phone, it is continued to any quake, root modification, heavy gps, transforming unnecessary mind and hits then in software serial code the dream. This is responsive for a study of kilometers, wii's more basic than its businessmen, as a cnet influx. Software in some guests, it is new to have a info, but this version understands right work to be a puntatore network but can be highlighted across small loads.

How to make your code completely unreadable with .NET 3.5

With the time we got our developers less and less professional by enhancing programing languages and using easier code syntax. However, while we are trying to make things better, we discovered that things are going bad. Let’s see following code sample

delegate string BringBeerDelegate(int amount);

static void Main(string[] args)
        {
            Console.WriteLine(“Bringing beer using anonymous delegates”);
            AskBarmenAboutBeer(2);

        }

static void AskBarmenAboutBeer(int amount)
        {
            BringBeerDelegate bringBeer = new BringBeerDelegate(BringBeer);

            Console.WriteLine(“You got {0}”, bringBeer.Invoke(amount));
            BringAnotherBeer(bringBeer, amount+1);
        }

static string BringBeer(int amount)
        {
            return string.Format(“{0} beers”,amount);
        }

static void BringAnotherBeer(BringBeerDelegate firstPint, int newAmount)
       {
           string res = firstPint(newAmount);
           Console.WriteLine(“You got another {0}”,res.ToString());
       }

It pretty clear what this code is doing. It creates new delegate named BringBeerDelegate, that actually formats string. Then it invokes the delegate. After it the delegate transferred into BringAnotherBeer method and invokes there. This way it works in .NET 1.1 So far, so good. Let’s use anonymous delegate, introduced in .NET 2.0 instead on using method to invoke it. Now, we’ll add another method, that creates and invokes the anonymous delegate BringBeerDelegate.

static void AskBarmenAnonymouslyAboutBeer(int amount)
        {
            BringBeerDelegate bringBeer = delegate(int am) { return string.Format(“{0} beers”, am); };

            Console.WriteLine(“You got {0}”, bringBeer.Invoke(amount));
            BringAnotherBeer(bringBeer, amount + 1);
        }

Now, calling AskBarmenAnonymouslyAboutBeer with number of pints we want, we’ll create and invoke the anonymous delegate. The code less readable (as for me), but never mind, we saved a couple of code lines.

Now, let’s write following:

BringBeerDelegate bringBeer = am => string.Format(“{0} beers”, am);
BringAnotherBeer(bringBeer, ++amount);

What the hell all those => are doing? This is anonymous delegate BringBeerDelegate defined by lambda¹ expression.

small lyrics: ¹Lambda (uppercase Λ, lowercase λ) – the 11th letter of the Greek alphabet. In the system of Greek numerals it has a value of 30. Letters that arose from Lambda include the Roman L and the Cyrillic letter El (Л, л).
Lambda expressions provide a more concise, functional syntax for writing anonymous methods.

Is it really more concise and functional syntax? What do you think, following code doing?

Func<int,string> firstTime = (int am) => { return string.Format(“{0} beers”, am); };

Func<T..> is generic delegate type for lambdas. That’s piece of cake, isn’t it? Let’s see you to predict what following code will output…

BringBeerDelegate bringBeer = am => string.Format(“{0} beers”, am);
Func<int, BringBeerDelegate, string> bringBeerFunc = (int am, BringBeerDelegate beer) => { return beer(am); };
Func<int, Func<int, BringBeerDelegate, string>, string> lastTime = (int am, Func<int, BringBeerDelegate, string> func) => { return func(am, bringBeer); };

The other awful thing in new .NET 3.5 is anonymous types. So, great news, VB programmers, there is new king in the village. His name is VAR. Following previous code section, following make our life even more complicated.

var whatBeer = bringBeer;

//At least, either compiler and interpreter knows, that whatBeer variable is of BringBeerDelegate type

image

Happy and very unreadable coding, my friends.

Source code for this article.

Be Sociable, Share!

20 Responses to “How to make your code completely unreadable with .NET 3.5”

  1. Just code - Tamir Khason Says:

    Me, personally, not a big fan of labdas . However, it looks like new blogger M. Or&#231;un Topdağı is

  2. Just code - Tamir Khason Says:

    Did you try to cast anonymous types (vars)? You are. However, you never was able to pass var from one

  3. Tamir Khason Says:

    aL,

    1) I’l not. Actually, I never proof read my posts. I just write – this is my way of writing blog :)

    2) Instead of writing "I can predict", just predict it :) BTW, it uses all arguments there.

    3) Regarding C#, you are right, I do not know C#, as well as I’m not programmer at all – here the proof blogs.microsoft.co.il/…/70-552-should-be-removed-or-at-least-changed.aspx

    4) You are not have to read my blog, really, you dont, ‘cos I’m awfull unprofessional in any context and my english is bad

  4. aL Says:

    did you proof read your post at all..? thait has to be the most poorly written thing ive read in a long time..

    ok fine, i can get over the grammar but your example of a  "bad" lambda is just silly.. first of all you ask if i the reader can predict what the code:

    BringBeerDelegate bringBeer = am => string.Format("{0} beers", am);

    Func<int, BringBeerDelegate, string> bringBeerFunc = (int am, BringBeerDelegate beer) => { return beer(am); };

    Func<int, Func<int, BringBeerDelegate, string>, string> lastTime = (int am, Func<int, BringBeerDnelegate, string> func) => { return func(am, bringBeer); };

    will output. well yes actually, i can.. not a damn thing. you never call lasttime so it wont output anything. its an unrealistic example anyway because you declare several arguments that you never use.

    and your bash on the var keyword? there isnt even an argument as to why it will make your code unreadable!

    you dont seem to know very much c# and that whould explain why you seem to claim most language features  that differs from c are "unreadable"

    i'll never visit this blog again so you can flame me all you want. but you should know that your laughable examples and your apparent complete ignorance of the workings of c# makes for an awfully unprofessional blog.. atleast in the context of c#.

    the horrible english doesnt help either

  5. Just code - Tamir Khason Says:

    Remember new features, that make your code unreadable ? A couple of days ago, CLR team released first

  6. Just code - Tamir Khason Says:

    Here , one of visitors, begun a discussion about good and bad programmers. Here , I wrote about absolutely

  7. Niki Says:

    > I have neither time nor wish to teach programmer. I believe, that those, who want to write code, must understand what they are doing and not be "code monkeys".

    I would agree to that, but then your problem vanishes anyway: if programmers know what they are doing, then they won't produce cryptic code like the "bad example" code in your article. If they do anyway, they should be slapped around the head and forced to do maintainance programming for at least a year.

    > purchases.SortBy(p => p.Price); statement is very very expressive, however, I am not speaking about "simple patterns". …

    Me too: You wouldn't need lambdas for "simple patterns". But the more complex your task gets, the more helpful lambda expressions will be.

    > Let's imagine, that p.Price is not number, but object with locale formatting.

    Yes, let's: What options would you have then? You could:

    - write your own sorting routine that uses the right comparison function (bad, lots of duplicate code)

    - Use a compare-function-pointer (as in C's qsort or C++'s sort functions) or a delegate pointing to a static function. (bad, violates code locality.)

    - Use an anonymous delegate (not that bad, but verbose; and delegates are a redundant feature, so they will (hopefully) go away some day.)

    - Or, in C# 3.0, you could finally use a simple lambda expression:

    customers.Sort( (l,r) => l.Name.Compare(r.Name, Globalization.CultureInfo.SomeWeirdEuropeanCulture);

  8. Tamir Khason Says:

    Niki,

    I understand you’r statement.  However, how many production code wrote, by using Scheme? It’s really cool academic appropach, but still it’s very far away from being production.

    I have neither time nor wish to teach programmer. I believe, that those, who want to write code, must understand what they are doing and not be "code monkeys".

    purchases.SortBy(p => p.Price); statement is very very expressive, however, I am not speaking about "simple patterns". Let’s imagine, that p.Price is not number, but object with locale formatting. Can you imagine how your code will work? Can you know if in your statement sorting will be ascended or decended? You can not.

    I’m oldfashined, so I think, that events are bad, ‘cos they are much worth then system messages. And that’s exactly my point. :)

  9. Just code - Tamir Khason Says:

    That&#39;s exactly what I mean, when writing such articles . Translation for English speakers: &quot;Wake

  10. Niki Says:

    I just have to reinstall VS2008 because I keep getting weird "unexpected errors" (very helpful error message, by the way. thank you, microsoft!). So I have a few minutes to write down a reply:

    > Niki, no it is not my statement. My statement is that we are studing developers to write bad code, by adding more and more unnessesery features to the programming language.

    That's your conclusion, but I still don't see how you get to that conclusion. Yes, of course, the feature is kind of redundant, but not more redundant than for-loops, foreach-loops, do-while-loops, events, switch-case or properties are. Yes, there is potential for misuse, but IMHO you can do far more damage e.g. with events, which can lead to serious spagetti code.

    I see two possible conclusions out of this, either:

    a) Use a minimalist language like Scheme, that does not have all those redundant features. I like Scheme, but unfortunately I'm quite alone with that, most companies seem to prefer "rich" languages. (And guess what: Yes, Scheme does have lambdas…)

    b) Teach your programmers to use the features of the language wisely, not to obscure the meaning of the code they're writing, but to clarify it.

    > In Python 3000, for example is was decided to remove lambdas from the language and replace them with anonymous delegates.

    I think I read a statement from Guido van Rossum (the man behind Python) that lambdas will stay in the language, but that might be outdated. Anyway, the reason why there's discussion about lambdas in Python are largely syntactic: they simply don't fit into the  indentation-oriented block structure. That's not a problem that in C#.

    > So, are you really thinking , that lambdas are good? :)

    Yes, of course I do. Why? For one thing, I have some mathematical background, so I've found lambda calculus intuitive long before anyone thought C# might get lambda expressions some day. Also, I know a bit of higher-order-programming, and know how much it can simplify development if used correctly. And I can think of code like this:

    purchases.SortBy(p => p.Price);

    I don't see how I could make this code any clearer. In .NET 1.1 (or in C++), I would have a static function like "GetPrice" somewhere far aways form the SortBy-call, which is of course bad because it destroys code locality. In C# 2.0, I could to do something similar with an anonymous delegate, which does the same thing, but makes the code hard to read, because it is far more verbose, and also less flexible, because it cannot be used as an expression. (I am hoping that anonymous delegates will be removed in some future version of C#.)

  11. Angelos Petropoulos Says:

    I agree with the point you are trying to make. My feelings are reflected by this post on LINQ (the reason anonymous types and lambda expressions were implemented) that I made only a few days ago …

    http://www.angelosp.com/…/TechEd-Wisdom-%e2%80%93-Still-not-convinced-about-LINQ.aspx

  12. Daily Dose of Links - 20071119 « Daily Geek Bits Says:

    Pingback from  Daily Dose of Links – 20071119 &laquo; Daily Geek Bits

  13. Tamir Khason Says:

    Niki, no it is not my statement. My statement is that we are studing developers to write bad code, by adding more and more unnessesery features to the programming language.

    In Python 3000, for example is was decided to remove lambdas from the language and replace them with anonymous delegates. Regarding Ruby, delegates works as block expressions. They are working very hard to add delegate support to the language += and -= expressions.

    So, are you really thinking , that lambdas are good? :)

  14. jhunter Says:

    I agree with you, I hate anonymous types.  I expect to frustrated when I start reading people's code in .net 3.5.

  15. Niki Says:

    Your point seems to be, if a feature can be used to write code that's hard to understand, then the feature is bad. Is that right?

    Wouldn't it make more sense to learn those new programming language elements, and see how they can be used to make code more readable?

    BTW: Maybe you should have a look at languages that are usually regarded as "elegant", like Lisp, Python, Ruby, Haskell or ML. Guess what? They all have lambda expressions!

  16. Binding with Lambda expressions | Tamir Khason - Just code Says:

    [...] personally, not a big fan of labdas. However, it looks like new blogger M. Orçun Topdağı is. He wrote three posts (1, 2, 3) [...]

  17. Why good programmer never write good programs | Tamir Khason - Just code Says:

    [...] Here, one of visitors, begun a discussion about good and bad programmers. Here, I wrote about absolutely unnecessary and not relevant questions to good programmers. Someone things, that good programmers should write good programs. However, I want to interpose my objections to the statement. And this why. [...]

  18. Maynard D. Cooney Says:

    Nice blog you have… looking forward to read your next post

  19. babylooneytunes Says:

    Hi, I am new.This is my frist thread …lol.
    say hi to everybody.

  20. Fake Oakley Furious II Oakley Antix 005 Says:

    Finally, my personal favorite feature in the shades Revo designs is their own Motion-fit system. What this technology will is comfortably and properly position the lenses so that it guarantees the actual widest and clearest area of vision possible. Critically, sometimes I do not really realize I am putting on them. Fake Oakley Furious II Oakley Antix 005

Leave a Reply

Recommended

 

Sponsor


Partners

WPF Disciples
Dreamhost
Code Project