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. Other Discussions
  3. The Insider News
  4. Functional programming in C#—A brief consideration

Functional programming in C#—A brief consideration

Scheduled Pinned Locked Moved The Insider News
csharpcsscomalgorithmsfunctional
7 Posts 5 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.
  • K Offline
    K Offline
    Kent Sharkey
    wrote on last edited by
    #1

    Telerik[^]:

    A very common problem encountered in most program code is high complexity. To deal with this, a great alternative is functional programming—an excellent paradigm that helps programmers to write code that is less susceptible to errors.

    What's the big deal? I write functions

    O M D E 4 Replies Last reply
    0
    • K Kent Sharkey

      Telerik[^]:

      A very common problem encountered in most program code is high complexity. To deal with this, a great alternative is functional programming—an excellent paradigm that helps programmers to write code that is less susceptible to errors.

      What's the big deal? I write functions

      O Offline
      O Offline
      obermd
      wrote on last edited by
      #2

      Didn't we hear about this with Object Oriented Programming, Structured Programming, etc.? Different programming paradigms support different environments. Using the wrong paradigm for the environment leads to excessively complex code with the attendant bugs.

      1 Reply Last reply
      0
      • K Kent Sharkey

        Telerik[^]:

        A very common problem encountered in most program code is high complexity. To deal with this, a great alternative is functional programming—an excellent paradigm that helps programmers to write code that is less susceptible to errors.

        What's the big deal? I write functions

        M Offline
        M Offline
        Marc Clifton
        wrote on last edited by
        #3

        Quote:

        A very common problem encountered in most program code is high complexity. To deal with this, a great alternative is functional programming

        Wow, what a total miss on how to deal with complexity. :laugh: Complexity exists regardless of the programming language, and a programming language does not address complexity. What he means by "complexity" in his post is better termed "elegancy" though some may argue that => this => that => thar => wherefore art thou Romeo => dead is not elegant.

        Latest Article:
        Create a Digital Ocean Droplet for .NET Core Web API with a real SSL Certificate on a Domain

        1 Reply Last reply
        0
        • K Kent Sharkey

          Telerik[^]:

          A very common problem encountered in most program code is high complexity. To deal with this, a great alternative is functional programming—an excellent paradigm that helps programmers to write code that is less susceptible to errors.

          What's the big deal? I write functions

          D Offline
          D Offline
          David ONeil
          wrote on last edited by
          #4

          Quote:

          ...Something I’ve noticed is that many developers, based on their experiences and taking advantage of the possibilities of OOP, have created totally empirical code, full of endless “if” and “else” statements...

          Then it must not be very good OOP code, if it even warrants that title.

          Quote:

          The use of immutable values and recursion can generate more memory consumption ... but compared to the overhead of imperative programming, pure functions require much less overhead

          Self-contradictory.

          namespace FPExampleApp;
          public class Order
          {
          public int UnitPrice { get; set; }
          public int Discount { get; set; }

          public void SpecialCustomer(int unitPrice, int discount)
          {
              UnitPrice = unitPrice;
              Discount += discount;
          }
          

          }

          The article uses constructors to simplify code in the Immutable version, but no Order(UnitPrice up, int discount) { } to simplify the imperative case. :rolleyes: :rolleyes: :rolleyes: :doh: :doh: :doh: They can be made practically identical. I stick by my first statement.

          Our Forgotten Astronomy | Object Oriented Programming with C++ | Wordle solver

          1 Reply Last reply
          0
          • K Kent Sharkey

            Telerik[^]:

            A very common problem encountered in most program code is high complexity. To deal with this, a great alternative is functional programming—an excellent paradigm that helps programmers to write code that is less susceptible to errors.

            What's the big deal? I write functions

            E Offline
            E Offline
            englebart
            wrote on last edited by
            #5

            The thing that makes sense to me is the immutable data. Most errors I see is where someone, somewhere changed an object's state which was not anticipated elsewhere. Same thing could happen with immutable data as well, but it would be easier to track back to where something went wrong. I could see some higher memory use, especially if dealing with large datasets. For people that like Test Driven Development, functional is a good way to go. Once the algorithm is proven, it should be solid and not need to worry about weird state issues.

            D O 2 Replies Last reply
            0
            • E englebart

              The thing that makes sense to me is the immutable data. Most errors I see is where someone, somewhere changed an object's state which was not anticipated elsewhere. Same thing could happen with immutable data as well, but it would be easier to track back to where something went wrong. I could see some higher memory use, especially if dealing with large datasets. For people that like Test Driven Development, functional is a good way to go. Once the algorithm is proven, it should be solid and not need to worry about weird state issues.

              D Offline
              D Offline
              David ONeil
              wrote on last edited by
              #6

              I have always asked "how would you do something like a word processing program in a functional manner?" The only response I've heard makes me think it would be very difficult, because the main document would have more and more states as each addition/revision was made. Each change basically creates a new main document. An 'undo' function would probably be easier than many other methods, but that by itself isn't enough to convince me...

              Our Forgotten Astronomy | Object Oriented Programming with C++ | Wordle solver

              1 Reply Last reply
              0
              • E englebart

                The thing that makes sense to me is the immutable data. Most errors I see is where someone, somewhere changed an object's state which was not anticipated elsewhere. Same thing could happen with immutable data as well, but it would be easier to track back to where something went wrong. I could see some higher memory use, especially if dealing with large datasets. For people that like Test Driven Development, functional is a good way to go. Once the algorithm is proven, it should be solid and not need to worry about weird state issues.

                O Offline
                O Offline
                obermd
                wrote on last edited by
                #7

                englebart wrote:

                The thing that makes sense to me is the immutable data.

                In multi-threaded applications, immutable data makes it a lot easier to debug and avoids synchronization performance penalties and the related timing bugs.

                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