Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. ROTD

ROTD

Scheduled Pinned Locked Moved The Lounge
question
29 Posts 15 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Tom Delany

    Note: Before the flamers get their blasters out, this is NOT a programming question. It is just a rant. I hate code like this:

    public IResult GetToDoItem(int toDoItemID, Action onSuccess, Action<Exception> onFail)
    {
    IsReadOnly = true;

    return CoroutineFns.AsResult(
        () => \_repository.FindToDoItemByID(toDoItemID,
                                           (r) =>
                                           {
                                               Item = r;
                                               Item.PropertyChanged +=
                                                   (s, e) => NotifyOfPropertyChange(() => CanSave);
                                               if (onSuccess != null)
                                                   onSuccess();
                                           }, onFail));
    

    }

    Lambdas in lambdas in lambdas in lambdas. I find that to be nearly incomprehensible. Gaa!! I'm sure it is written very efficiently. X| I must be getting old and turning into a curmudgeon. :~

    WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated. There are 10 kinds of people in the world: People who know binary and people who don't.

    M Offline
    M Offline
    Mladen Jankovic
    wrote on last edited by
    #21

    Hmm... so I'm the only one around here who really likes lambdas.

    T L 2 Replies Last reply
    0
    • L Lost User

      In my experience I have seen new and older programmers. The newer ones have taken to landas more naturally. Not sure if they are crammed down their throats in school or what. But in working with them I find they use them not necessarily to show off, but that is what they know. For example, I have seen code riddled with

      public event EventHandler SomeEvent = (s, e) => { };

      Where as I have always let the event be null and let the objects needing it build up the event collection (i.e. +=). Then create some wrapper for null check

      private void RaiseSomeEvent()
      {
      if(SomeEvent != null)
      {
      SomeEvent(this, EventArgs.Empty); //Or pass through the args received
      }
      }

      Maybe the new recruits are on to something. Not sure. I did some perf testing a while back and found empty delegates were more expensive than an if, however what about one empty delegate to many ifs. Not sure. But that is not the point really. They did not put this code in to 'show off' nor did they do perf testing. They did it because they knew how, and it took care of some problems (null ref). The same is true with other uses of lambda or any new technologies. A programmer finds a way to get something down, and tends to stick with it. Even if an entire framework comes out simplifying it the programmer will use their old methodolgies. When I first saw lamdas I gagged a little. But I find them quite easy to read now. Espeacially after writting some quite complicated ones that were even more complicated with out. In some cases it is easier for your thought flow in creating. Maybe it is harder for a non-Lamda user to understand after the fact, but that is not likely the programmers initial concern. I am not defending this particular code chunck, as it is not clean at all. But most likely you renamed and lost a little formatting in the post here. I have found that formatting (white space etc.) and proper naming is the key to leaving bread crumbs for your collegues (and yourself for that matter). I am defending lamdas though as I have found them quite usefull and dare I say cleaner in many cases. It just takes proper usage, but this is true with any technology.

      Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

      T Offline
      T Offline
      Tom Delany
      wrote on last edited by
      #22

      The chunk was from a vendor's sample project. Nothing was renamed. The formatting came out surpringly close (if not identical) to the original . I was not beating up on the use of lambdas in general. Just ranting that to my "old school" way of thinking, somtimes they seem very obtuse. No doubt I just need to get used to them. Getting old and set in my ways. :sigh:

      WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated. There are 10 kinds of people in the world: People who know binary and people who don't.

      L 1 Reply Last reply
      0
      • M Mladen Jankovic

        Hmm... so I'm the only one around here who really likes lambdas.

        T Offline
        T Offline
        Tom Delany
        wrote on last edited by
        #23

        I didn't say that I never use them...

        WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated. There are 10 kinds of people in the world: People who know binary and people who don't.

        1 Reply Last reply
        0
        • M Mladen Jankovic

          Hmm... so I'm the only one around here who really likes lambdas.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #24

          See my Post[^]. I like them. Many things are much easier. My with any power comes great responsibility :)

          Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

          1 Reply Last reply
          0
          • L Lost User

            In my experience I have seen new and older programmers. The newer ones have taken to landas more naturally. Not sure if they are crammed down their throats in school or what. But in working with them I find they use them not necessarily to show off, but that is what they know. For example, I have seen code riddled with

            public event EventHandler SomeEvent = (s, e) => { };

            Where as I have always let the event be null and let the objects needing it build up the event collection (i.e. +=). Then create some wrapper for null check

            private void RaiseSomeEvent()
            {
            if(SomeEvent != null)
            {
            SomeEvent(this, EventArgs.Empty); //Or pass through the args received
            }
            }

            Maybe the new recruits are on to something. Not sure. I did some perf testing a while back and found empty delegates were more expensive than an if, however what about one empty delegate to many ifs. Not sure. But that is not the point really. They did not put this code in to 'show off' nor did they do perf testing. They did it because they knew how, and it took care of some problems (null ref). The same is true with other uses of lambda or any new technologies. A programmer finds a way to get something down, and tends to stick with it. Even if an entire framework comes out simplifying it the programmer will use their old methodolgies. When I first saw lamdas I gagged a little. But I find them quite easy to read now. Espeacially after writting some quite complicated ones that were even more complicated with out. In some cases it is easier for your thought flow in creating. Maybe it is harder for a non-Lamda user to understand after the fact, but that is not likely the programmers initial concern. I am not defending this particular code chunck, as it is not clean at all. But most likely you renamed and lost a little formatting in the post here. I have found that formatting (white space etc.) and proper naming is the key to leaving bread crumbs for your collegues (and yourself for that matter). I am defending lamdas though as I have found them quite usefull and dare I say cleaner in many cases. It just takes proper usage, but this is true with any technology.

            Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #25

            Collin Jasnoch wrote:

            private void RaiseSomeEvent() { if(SomeEvent != null) { SomeEvent(this, EventArgs.Empty); //Or pass through the args received } }

            Collin Jasnoch wrote:

            They did it because they knew how, and it took care of some problems (null ref).

            Oooh, they are close and yet so far as this doesn't cope with null - what happens if SomeEvent becomes null between the test and the call (this does happen)? You end up with a null reference - the trick is to do this:

            private void RaiseSomeEvent()
            {
            MyTypeOfSomeEvent handler = SomeEvent;
            if(handler != null)
            {
            SomeEvent(this, EventArgs.Empty); //Or pass through the args received
            }
            }

            Forgive your enemies - it messes with their heads

            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

            My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

            L 1 Reply Last reply
            0
            • T Tom Delany

              The chunk was from a vendor's sample project. Nothing was renamed. The formatting came out surpringly close (if not identical) to the original . I was not beating up on the use of lambdas in general. Just ranting that to my "old school" way of thinking, somtimes they seem very obtuse. No doubt I just need to get used to them. Getting old and set in my ways. :sigh:

              WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated. There are 10 kinds of people in the world: People who know binary and people who don't.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #26

              Yeah, then your vendor is cruel. It is one thing to write code that way, and an entirely different thing to write sample code that way. And you deffinately got my point. Everyone gets set in their ways. Its more natural than diving into everything new. Most have 'phases' where they dig into the new things. But when it comes down to it, you do your time and want things somewhat stationary. You don't want to come into work every other week and be told "We are going to port this to a different environment" or lets convert everythign to using feature "Yada yadda"... yet every now and then those are words you have been dieing to hear. Other times it takes them to be first 'dreaded' words, yet after some time words you are dieing to hear on a different system. Some older programmers I know had that experience with .Net in general. No one wanted to convert the systems... Until they had the pleasure of using a .Net system.

              Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

              1 Reply Last reply
              0
              • P Pete OHanlon

                Collin Jasnoch wrote:

                private void RaiseSomeEvent() { if(SomeEvent != null) { SomeEvent(this, EventArgs.Empty); //Or pass through the args received } }

                Collin Jasnoch wrote:

                They did it because they knew how, and it took care of some problems (null ref).

                Oooh, they are close and yet so far as this doesn't cope with null - what happens if SomeEvent becomes null between the test and the call (this does happen)? You end up with a null reference - the trick is to do this:

                private void RaiseSomeEvent()
                {
                MyTypeOfSomeEvent handler = SomeEvent;
                if(handler != null)
                {
                SomeEvent(this, EventArgs.Empty); //Or pass through the args received
                }
                }

                Forgive your enemies - it messes with their heads

                "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #27

                Yeah I guess that could happen. Never thought about it actually. But to be clear, I am the culperate of that 'bad' code. The 'newer' way (using a lamda with an empty delegate) would not run into the issue, unless you were nulling your SomeEvent within the publisher of the event (it is the one that initializes using an emepty delegate). I have never seen a reason to do this though. Usually your subscribers remove their own subscriptions. I think the idea of it is that it has atleast one subscription (do nothing), rather than being initialized to null (cant do anything) and waiting on subscriptions (do something). Maybe I am missing something though.

                Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

                1 Reply Last reply
                0
                • T Tom Delany

                  Note: Before the flamers get their blasters out, this is NOT a programming question. It is just a rant. I hate code like this:

                  public IResult GetToDoItem(int toDoItemID, Action onSuccess, Action<Exception> onFail)
                  {
                  IsReadOnly = true;

                  return CoroutineFns.AsResult(
                      () => \_repository.FindToDoItemByID(toDoItemID,
                                                         (r) =>
                                                         {
                                                             Item = r;
                                                             Item.PropertyChanged +=
                                                                 (s, e) => NotifyOfPropertyChange(() => CanSave);
                                                             if (onSuccess != null)
                                                                 onSuccess();
                                                         }, onFail));
                  

                  }

                  Lambdas in lambdas in lambdas in lambdas. I find that to be nearly incomprehensible. Gaa!! I'm sure it is written very efficiently. X| I must be getting old and turning into a curmudgeon. :~

                  WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated. There are 10 kinds of people in the world: People who know binary and people who don't.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #28

                  Tom Delany wrote:

                  Lambdas in lambdas in lambdas.

                  What have you got against The Revenge Of The Nerds?

                  Michael Martin Australia "I controlled my laughter and simple said "No,I am very busy,so I can't write any code for you". The moment they heard this all the smiling face turned into a sad looking face and one of them farted. So I had to leave the place as soon as possible." - Mr.Prakash One Fine Saturday. 24/04/2004

                  T 1 Reply Last reply
                  0
                  • L Lost User

                    Tom Delany wrote:

                    Lambdas in lambdas in lambdas.

                    What have you got against The Revenge Of The Nerds?

                    Michael Martin Australia "I controlled my laughter and simple said "No,I am very busy,so I can't write any code for you". The moment they heard this all the smiling face turned into a sad looking face and one of them farted. So I had to leave the place as soon as possible." - Mr.Prakash One Fine Saturday. 24/04/2004

                    T Offline
                    T Offline
                    Tom Delany
                    wrote on last edited by
                    #29

                    Ha! I never thought of that. Of course! It all makes sense now... :)

                    WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated. There are 10 kinds of people in the world: People who know binary and people who don't.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups