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. It's interesting how much lambda, extension and anonymous methods I'm using nowadays

It's interesting how much lambda, extension and anonymous methods I'm using nowadays

Scheduled Pinned Locked Moved The Lounge
csharpphprubylinqcom
25 Posts 18 Posters 0 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.
  • M Offline
    M Offline
    Marc Clifton
    wrote on last edited by
    #1

    For example, here's a setter that updates the underlying field of a data row and fires a change event based on whether the field actually changed (UpdateField, an extension method, returns true) and whether the event has been wired (not null):

    set {row.UpdateField(model, "TableOfContents", value).Then(() => TableOfContentsChanged.IfNotNull(e => e(this))); }

    [edit] For example, the above would otherwise be written as:

    bool changed = row.UpdateField(model, "TableOfContents", value);
    if (changed)
    {
    if (TableOfContentsChanged != null)
    {
    TableOfContentsChanged(this);
    }
    }

    [/edit] Or, here's something that scans the nodes in a tree (Hierarchy being an extension method) and if it finds a match (not null) updates the title in the tree's caption:

    TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

    I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming? Marc

    Latest Article: C# and Ruby Classes: A Deep Dive
    My Blog

    L R S P D 16 Replies Last reply
    0
    • M Marc Clifton

      For example, here's a setter that updates the underlying field of a data row and fires a change event based on whether the field actually changed (UpdateField, an extension method, returns true) and whether the event has been wired (not null):

      set {row.UpdateField(model, "TableOfContents", value).Then(() => TableOfContentsChanged.IfNotNull(e => e(this))); }

      [edit] For example, the above would otherwise be written as:

      bool changed = row.UpdateField(model, "TableOfContents", value);
      if (changed)
      {
      if (TableOfContentsChanged != null)
      {
      TableOfContentsChanged(this);
      }
      }

      [/edit] Or, here's something that scans the nodes in a tree (Hierarchy being an extension method) and if it finds a match (not null) updates the title in the tree's caption:

      TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

      I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming? Marc

      Latest Article: C# and Ruby Classes: A Deep Dive
      My Blog

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

      No. Not at all, not even before I declared my independence from Mickeysoft. One reason may be my dislike of Lisp, with which I once was tortured by a sadistic egghead.

      Sent from my BatComputer via HAL 9000 and M5

      1 Reply Last reply
      0
      • M Marc Clifton

        For example, here's a setter that updates the underlying field of a data row and fires a change event based on whether the field actually changed (UpdateField, an extension method, returns true) and whether the event has been wired (not null):

        set {row.UpdateField(model, "TableOfContents", value).Then(() => TableOfContentsChanged.IfNotNull(e => e(this))); }

        [edit] For example, the above would otherwise be written as:

        bool changed = row.UpdateField(model, "TableOfContents", value);
        if (changed)
        {
        if (TableOfContentsChanged != null)
        {
        TableOfContentsChanged(this);
        }
        }

        [/edit] Or, here's something that scans the nodes in a tree (Hierarchy being an extension method) and if it finds a match (not null) updates the title in the tree's caption:

        TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

        I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming? Marc

        Latest Article: C# and Ruby Classes: A Deep Dive
        My Blog

        R Offline
        R Offline
        R Giskard Reventlov
        wrote on last edited by
        #3

        Marc Clifton wrote:

        Is you C# imperative programming starting to look more and more like function programming?

        No.

        "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

        1 Reply Last reply
        0
        • M Marc Clifton

          For example, here's a setter that updates the underlying field of a data row and fires a change event based on whether the field actually changed (UpdateField, an extension method, returns true) and whether the event has been wired (not null):

          set {row.UpdateField(model, "TableOfContents", value).Then(() => TableOfContentsChanged.IfNotNull(e => e(this))); }

          [edit] For example, the above would otherwise be written as:

          bool changed = row.UpdateField(model, "TableOfContents", value);
          if (changed)
          {
          if (TableOfContentsChanged != null)
          {
          TableOfContentsChanged(this);
          }
          }

          [/edit] Or, here's something that scans the nodes in a tree (Hierarchy being an extension method) and if it finds a match (not null) updates the title in the tree's caption:

          TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

          I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming? Marc

          Latest Article: C# and Ruby Classes: A Deep Dive
          My Blog

          S Offline
          S Offline
          Single Step Debugger
          wrote on last edited by
          #4

          I forced myself to use lambda expressions just to try the new fancy stuff few years ago but it’s not my thing. IMO readability of the code suffers from this syntax. Anonymous methods are the same thing as functionality, but a little more readable. I’m using them, but not for the sake of it, just where it’s proper. I think the only case where I use lambdas and vars now is wen working with “link to memory” (a beautiful technology).

          There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.

          1 Reply Last reply
          0
          • M Marc Clifton

            For example, here's a setter that updates the underlying field of a data row and fires a change event based on whether the field actually changed (UpdateField, an extension method, returns true) and whether the event has been wired (not null):

            set {row.UpdateField(model, "TableOfContents", value).Then(() => TableOfContentsChanged.IfNotNull(e => e(this))); }

            [edit] For example, the above would otherwise be written as:

            bool changed = row.UpdateField(model, "TableOfContents", value);
            if (changed)
            {
            if (TableOfContentsChanged != null)
            {
            TableOfContentsChanged(this);
            }
            }

            [/edit] Or, here's something that scans the nodes in a tree (Hierarchy being an extension method) and if it finds a match (not null) updates the title in the tree's caption:

            TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

            I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming? Marc

            Latest Article: C# and Ruby Classes: A Deep Dive
            My Blog

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

            I use Lambdas a lot. One heck of a lot. I'm also getting into Rx as well, and they play a huge part there.

            I was brought up to respect my elders. I don't respect many people nowadays.
            CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

            1 Reply Last reply
            0
            • M Marc Clifton

              For example, here's a setter that updates the underlying field of a data row and fires a change event based on whether the field actually changed (UpdateField, an extension method, returns true) and whether the event has been wired (not null):

              set {row.UpdateField(model, "TableOfContents", value).Then(() => TableOfContentsChanged.IfNotNull(e => e(this))); }

              [edit] For example, the above would otherwise be written as:

              bool changed = row.UpdateField(model, "TableOfContents", value);
              if (changed)
              {
              if (TableOfContentsChanged != null)
              {
              TableOfContentsChanged(this);
              }
              }

              [/edit] Or, here's something that scans the nodes in a tree (Hierarchy being an extension method) and if it finds a match (not null) updates the title in the tree's caption:

              TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

              I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming? Marc

              Latest Article: C# and Ruby Classes: A Deep Dive
              My Blog

              D Offline
              D Offline
              dusty_dex
              wrote on last edited by
              #6

              Sort of, yes. But it's quicker for me to think imperative first and make sure my code does what I expect. Then I look at my code to see if it would benefit from a functional makeover. Surprisingly it's not in most cases, but I have started to avoid mutable states more these days.

              "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

              1 Reply Last reply
              0
              • M Marc Clifton

                For example, here's a setter that updates the underlying field of a data row and fires a change event based on whether the field actually changed (UpdateField, an extension method, returns true) and whether the event has been wired (not null):

                set {row.UpdateField(model, "TableOfContents", value).Then(() => TableOfContentsChanged.IfNotNull(e => e(this))); }

                [edit] For example, the above would otherwise be written as:

                bool changed = row.UpdateField(model, "TableOfContents", value);
                if (changed)
                {
                if (TableOfContentsChanged != null)
                {
                TableOfContentsChanged(this);
                }
                }

                [/edit] Or, here's something that scans the nodes in a tree (Hierarchy being an extension method) and if it finds a match (not null) updates the title in the tree's caption:

                TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

                I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming? Marc

                Latest Article: C# and Ruby Classes: A Deep Dive
                My Blog

                D Offline
                D Offline
                Dan Neely
                wrote on last edited by
                #7

                Marc Clifton wrote:

                Is you C# imperative programming starting to look more and more like function programming?

                To steal a coworkers comment on the Office07 ribbon from a few years ago: "It's growing on me ... like a fungus."

                Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                1 Reply Last reply
                0
                • M Marc Clifton

                  For example, here's a setter that updates the underlying field of a data row and fires a change event based on whether the field actually changed (UpdateField, an extension method, returns true) and whether the event has been wired (not null):

                  set {row.UpdateField(model, "TableOfContents", value).Then(() => TableOfContentsChanged.IfNotNull(e => e(this))); }

                  [edit] For example, the above would otherwise be written as:

                  bool changed = row.UpdateField(model, "TableOfContents", value);
                  if (changed)
                  {
                  if (TableOfContentsChanged != null)
                  {
                  TableOfContentsChanged(this);
                  }
                  }

                  [/edit] Or, here's something that scans the nodes in a tree (Hierarchy being an extension method) and if it finds a match (not null) updates the title in the tree's caption:

                  TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

                  I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming? Marc

                  Latest Article: C# and Ruby Classes: A Deep Dive
                  My Blog

                  M Offline
                  M Offline
                  Maximilien
                  wrote on last edited by
                  #8

                  (C++) I find the C++ syntax of Lambdas quite difficult and obscure (and, IMO, the C# syntax is not much better). Maybe, in time, when we install and use VS2012, I will learn to use them and love them, but for now, I don't see a use for them in our production code; and most examples do not convince me of their utility.

                  Nihil obstat

                  G L 2 Replies Last reply
                  0
                  • M Marc Clifton

                    For example, here's a setter that updates the underlying field of a data row and fires a change event based on whether the field actually changed (UpdateField, an extension method, returns true) and whether the event has been wired (not null):

                    set {row.UpdateField(model, "TableOfContents", value).Then(() => TableOfContentsChanged.IfNotNull(e => e(this))); }

                    [edit] For example, the above would otherwise be written as:

                    bool changed = row.UpdateField(model, "TableOfContents", value);
                    if (changed)
                    {
                    if (TableOfContentsChanged != null)
                    {
                    TableOfContentsChanged(this);
                    }
                    }

                    [/edit] Or, here's something that scans the nodes in a tree (Hierarchy being an extension method) and if it finds a match (not null) updates the title in the tree's caption:

                    TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

                    I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming? Marc

                    Latest Article: C# and Ruby Classes: A Deep Dive
                    My Blog

                    N Offline
                    N Offline
                    Nicholas Butler
                    wrote on last edited by
                    #9

                    Yes, absolutely! Since the lambda syntax made anonymous functions elegant, I've noticed a complete change in the C# I write. Also, I learned about Expression Trees from working with EF and now rely on being able to create and modify them to write framework code.

                    www.NickButler.net

                    1 Reply Last reply
                    0
                    • M Marc Clifton

                      For example, here's a setter that updates the underlying field of a data row and fires a change event based on whether the field actually changed (UpdateField, an extension method, returns true) and whether the event has been wired (not null):

                      set {row.UpdateField(model, "TableOfContents", value).Then(() => TableOfContentsChanged.IfNotNull(e => e(this))); }

                      [edit] For example, the above would otherwise be written as:

                      bool changed = row.UpdateField(model, "TableOfContents", value);
                      if (changed)
                      {
                      if (TableOfContentsChanged != null)
                      {
                      TableOfContentsChanged(this);
                      }
                      }

                      [/edit] Or, here's something that scans the nodes in a tree (Hierarchy being an extension method) and if it finds a match (not null) updates the title in the tree's caption:

                      TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

                      I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming? Marc

                      Latest Article: C# and Ruby Classes: A Deep Dive
                      My Blog

                      M Offline
                      M Offline
                      Marco Bertschi
                      wrote on last edited by
                      #10

                      I admit that it has changed a lot. Unfortunately I haven't had the chance to work with it since I switched a bit to the C++/platform-independent stuff. It is an interesting field so I will learn the whole Lambda thing when I have to work with C#.Net again. For the moment I am developing a platform-independent generic queuing system. If it works as expected it will redefine the whole way my team is handling threads.

                      cheers Marco Bertschi


                      Software Developer & Founder SMGT Web-Portal CP Profile | My Articles | Twitter | Facebook | SMGT Web-Portal

                      1 Reply Last reply
                      0
                      • M Marc Clifton

                        For example, here's a setter that updates the underlying field of a data row and fires a change event based on whether the field actually changed (UpdateField, an extension method, returns true) and whether the event has been wired (not null):

                        set {row.UpdateField(model, "TableOfContents", value).Then(() => TableOfContentsChanged.IfNotNull(e => e(this))); }

                        [edit] For example, the above would otherwise be written as:

                        bool changed = row.UpdateField(model, "TableOfContents", value);
                        if (changed)
                        {
                        if (TableOfContentsChanged != null)
                        {
                        TableOfContentsChanged(this);
                        }
                        }

                        [/edit] Or, here's something that scans the nodes in a tree (Hierarchy being an extension method) and if it finds a match (not null) updates the title in the tree's caption:

                        TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

                        I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming? Marc

                        Latest Article: C# and Ruby Classes: A Deep Dive
                        My Blog

                        L Offline
                        L Offline
                        lewax00
                        wrote on last edited by
                        #11

                        Marc Clifton wrote:

                        What about you? Is you C# imperative programming starting to look more and more like function programming?

                        I do, but I've always been a fan of functional programming, just haven't had the time to do anything useful in one (although, the more I play with it, the more I realize Ruby is pretty much a functional language with some procedural syntax sugar).

                        1 Reply Last reply
                        0
                        • M Maximilien

                          (C++) I find the C++ syntax of Lambdas quite difficult and obscure (and, IMO, the C# syntax is not much better). Maybe, in time, when we install and use VS2012, I will learn to use them and love them, but for now, I don't see a use for them in our production code; and most examples do not convince me of their utility.

                          Nihil obstat

                          G Offline
                          G Offline
                          Gjeltema
                          wrote on last edited by
                          #12

                          I'm curious what you dont like about the C# lambda syntax. It's about as succinct as it can be without becoming cryptic, and seems pretty clear what it's doing after 30 seconds of explanation about the syntax.

                          1 Reply Last reply
                          0
                          • M Marc Clifton

                            For example, here's a setter that updates the underlying field of a data row and fires a change event based on whether the field actually changed (UpdateField, an extension method, returns true) and whether the event has been wired (not null):

                            set {row.UpdateField(model, "TableOfContents", value).Then(() => TableOfContentsChanged.IfNotNull(e => e(this))); }

                            [edit] For example, the above would otherwise be written as:

                            bool changed = row.UpdateField(model, "TableOfContents", value);
                            if (changed)
                            {
                            if (TableOfContentsChanged != null)
                            {
                            TableOfContentsChanged(this);
                            }
                            }

                            [/edit] Or, here's something that scans the nodes in a tree (Hierarchy being an extension method) and if it finds a match (not null) updates the title in the tree's caption:

                            TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

                            I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming? Marc

                            Latest Article: C# and Ruby Classes: A Deep Dive
                            My Blog

                            G Offline
                            G Offline
                            Gjeltema
                            wrote on last edited by
                            #13

                            I use it all the time now, though not quite as much as you do. I still use imperative styles a lot for ease of debugging for some things, but by and large the declarative syntax has definitely reshaped my coding - by far for the better.

                            1 Reply Last reply
                            0
                            • M Maximilien

                              (C++) I find the C++ syntax of Lambdas quite difficult and obscure (and, IMO, the C# syntax is not much better). Maybe, in time, when we install and use VS2012, I will learn to use them and love them, but for now, I don't see a use for them in our production code; and most examples do not convince me of their utility.

                              Nihil obstat

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

                              The C++11 stuff is fantastic. gcc 4.7 and Vs2012 and you're good to go for most of the new stuff

                              1 Reply Last reply
                              0
                              • M Marc Clifton

                                For example, here's a setter that updates the underlying field of a data row and fires a change event based on whether the field actually changed (UpdateField, an extension method, returns true) and whether the event has been wired (not null):

                                set {row.UpdateField(model, "TableOfContents", value).Then(() => TableOfContentsChanged.IfNotNull(e => e(this))); }

                                [edit] For example, the above would otherwise be written as:

                                bool changed = row.UpdateField(model, "TableOfContents", value);
                                if (changed)
                                {
                                if (TableOfContentsChanged != null)
                                {
                                TableOfContentsChanged(this);
                                }
                                }

                                [/edit] Or, here's something that scans the nodes in a tree (Hierarchy being an extension method) and if it finds a match (not null) updates the title in the tree's caption:

                                TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

                                I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming? Marc

                                Latest Article: C# and Ruby Classes: A Deep Dive
                                My Blog

                                F Offline
                                F Offline
                                Forogar
                                wrote on last edited by
                                #15

                                No.

                                - Life in the fast lane is only fun if you live in a country with no speed limits. - Of all the things I have lost, it is my mind that I miss the most. - I vaguely remember having a good memory...

                                1 Reply Last reply
                                0
                                • M Marc Clifton

                                  For example, here's a setter that updates the underlying field of a data row and fires a change event based on whether the field actually changed (UpdateField, an extension method, returns true) and whether the event has been wired (not null):

                                  set {row.UpdateField(model, "TableOfContents", value).Then(() => TableOfContentsChanged.IfNotNull(e => e(this))); }

                                  [edit] For example, the above would otherwise be written as:

                                  bool changed = row.UpdateField(model, "TableOfContents", value);
                                  if (changed)
                                  {
                                  if (TableOfContentsChanged != null)
                                  {
                                  TableOfContentsChanged(this);
                                  }
                                  }

                                  [/edit] Or, here's something that scans the nodes in a tree (Hierarchy being an extension method) and if it finds a match (not null) updates the title in the tree's caption:

                                  TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

                                  I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming? Marc

                                  Latest Article: C# and Ruby Classes: A Deep Dive
                                  My Blog

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

                                  Maybe I'm getting old - but your first example fails my legibility and debugging test. It's all jolly clever, and all, but if I'm trying to debug that line of code, I have to stop and think FAR harder than I do with the long-winded example.

                                  MVVM# - See how I did MVVM my way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')

                                  J D M 3 Replies Last reply
                                  0
                                  • L Lost User

                                    Maybe I'm getting old - but your first example fails my legibility and debugging test. It's all jolly clever, and all, but if I'm trying to debug that line of code, I have to stop and think FAR harder than I do with the long-winded example.

                                    MVVM# - See how I did MVVM my way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')

                                    J Offline
                                    J Offline
                                    Joe Woodbury
                                    wrote on last edited by
                                    #17

                                    I concur. To me this is yet more code masturbation.

                                    1 Reply Last reply
                                    0
                                    • L Lost User

                                      Maybe I'm getting old - but your first example fails my legibility and debugging test. It's all jolly clever, and all, but if I'm trying to debug that line of code, I have to stop and think FAR harder than I do with the long-winded example.

                                      MVVM# - See how I did MVVM my way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')

                                      D Offline
                                      D Offline
                                      dusty_dex
                                      wrote on last edited by
                                      #18

                                      This fp style is going to require more code commenting. Not necessarily a bad thing, but sort of defeats the purpose of clean minimal code.

                                      "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

                                      P 1 Reply Last reply
                                      0
                                      • M Marc Clifton

                                        For example, here's a setter that updates the underlying field of a data row and fires a change event based on whether the field actually changed (UpdateField, an extension method, returns true) and whether the event has been wired (not null):

                                        set {row.UpdateField(model, "TableOfContents", value).Then(() => TableOfContentsChanged.IfNotNull(e => e(this))); }

                                        [edit] For example, the above would otherwise be written as:

                                        bool changed = row.UpdateField(model, "TableOfContents", value);
                                        if (changed)
                                        {
                                        if (TableOfContentsChanged != null)
                                        {
                                        TableOfContentsChanged(this);
                                        }
                                        }

                                        [/edit] Or, here's something that scans the nodes in a tree (Hierarchy being an extension method) and if it finds a match (not null) updates the title in the tree's caption:

                                        TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

                                        I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming? Marc

                                        Latest Article: C# and Ruby Classes: A Deep Dive
                                        My Blog

                                        B Offline
                                        B Offline
                                        Brady Kelly
                                        wrote on last edited by
                                        #19

                                        Less like programming and more like true magic. Express the will to produced a certain outcome, without being too particular, and release to Run.

                                        1 Reply Last reply
                                        0
                                        • M Marc Clifton

                                          For example, here's a setter that updates the underlying field of a data row and fires a change event based on whether the field actually changed (UpdateField, an extension method, returns true) and whether the event has been wired (not null):

                                          set {row.UpdateField(model, "TableOfContents", value).Then(() => TableOfContentsChanged.IfNotNull(e => e(this))); }

                                          [edit] For example, the above would otherwise be written as:

                                          bool changed = row.UpdateField(model, "TableOfContents", value);
                                          if (changed)
                                          {
                                          if (TableOfContentsChanged != null)
                                          {
                                          TableOfContentsChanged(this);
                                          }
                                          }

                                          [/edit] Or, here's something that scans the nodes in a tree (Hierarchy being an extension method) and if it finds a match (not null) updates the title in the tree's caption:

                                          TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

                                          I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming? Marc

                                          Latest Article: C# and Ruby Classes: A Deep Dive
                                          My Blog

                                          B Offline
                                          B Offline
                                          BillWoodruff
                                          wrote on last edited by
                                          #20

                                          Marc Clifton wrote:

                                          I'm also noticing how my programming is becoming much more "functional" - I often pass in Func or Action anonymous methods, etc. What about you? Is you C# imperative programming starting to look more and more like function programming?

                                          Hi Marc, There is a genius, known as Marc Clifton, who used to publish many fascinating articles here on CP. I wonder if he can be extra-judicially rendered out of whatever zone he's in now, back into CP's orbit, and gently seduced into publication mode, and motivated to write an article on "C# as a Functional Language," or something like that. Clifton's previous articles were always fascinating, envelope-pushing, journeys, whether I understood them, or not. I bet Clifton could explain in:

                                          TreeView.Hierarchy().FirstOrDefault(n => n.Tag == rec).IfNotNull(t=>t[0] = rec.GetTitle());

                                          what the variable 't is used for. yours, Bill

                                          "Good people can be induced, seduced, and initiated into behaving in evil ways. They can also be led to act in irrational, stupid, antisocial, mindless, and self-destructive, ways when they are immersed in 'total situations' that impact human nature in ways that challenge our sense of the stability and consistency of individual personality, of character, and of morality."


                                          Dr. Philip G. Zimbardo, in "The Lucifer Effect" 2008: ISBN-10: 08129744

                                          M 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