Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. C++, Functional Programming, and Immutability
Forum Updated to NodeBB v4.3 + New Features

C++, Functional Programming, and Immutability

Scheduled Pinned Locked Moved Unsolved C++ Gurus
5 Posts 3 Posters 596 Views 4 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.
  • fcarneyF Offline
    fcarneyF Offline
    fcarney
    wrote on last edited by
    #1

    Maybe I just have not read enough about this topic, but immutability is really bothering me. The code I tend to write using this approach tends to copy things many times with multiple loops. With imperative programming the same loops can be executed once in one loop if I can mutate the data. (I don't have a concrete example on hand, but I can dig one up.) I know Qt has types that can share data, but as far as I know as soon as I mutate the benefit goes away.

    I am trying to improve my different approaches to programming and my assumptions about how smart compilers are often falls short of the things they can actually do.

    Can the compiler reason about this if the objects are immutable and produce optimized machine code? Is the compiler smart enough to see these loops and immutable objects and combine them into a single loop and set of operations?

    Note: I am in the middle of some FP books for C++ and perhaps I just need to read more. However, this really bothers me and I was hoping to get the weigh in from some of experts here in this forum. There are other benefits to FP approaches that I really like. Immutability is important for those to work. I just cannot help but wonder if FP is good for "some" types of programming and not others.

    C++ is a perfectly valid school of magic.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you reading this book ?

      If not I highly recommend it.

      And to sum up: functional programming is a good tool to have in your tool belt but it's not always the right tool to do what you want.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #3

        I think I have that book. Plus like 2 or 3 others. I need to finish reading it... It would probably answer a lot of my questions.

        C++ is a perfectly valid school of magic.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Yes, I recommend to finish the one from Ivan. It's really well written and talks about immutability.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by JKSH
            #5

            For a briefer discussion than a book, see https://softwareengineering.stackexchange.com/a/149576

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            3

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved