Results 1 to 2 of 2

Thread: c++ functional programming

  1. #1

    Thread Starter
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014

    c++ functional programming

    Has any guru done anything with functional programming in c++ and willing to share their experiences - in particular immutable functions, when used and why useful? I'm looking into c++ functional programming and whilst I 'get' first-class functions and pure functions, I'm struggling with why immutable?

    Any discussion would be welcomed.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.9.9)

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Southern Tier NY

    Re: c++ functional programming

    While I haven't done any immutable functions in C++, I would assume the when and why of them being useful would be the same reasons as immutable functions or objects in any other language, the primary one in my mind is the thread safe nature of the function which allows for concurrency, i.e. parallel execution of the function.

    A primary reason for strings being immutable for instance, is that since the string can't be modified you can short-circuit the test for equivalency if the reference to the string is the same, which can save considerable time.

    As for other reasons, probably do a search on "why immutable" and see what you find, like this Java based 6 Benefits of Programming with Immutable Objects in Java article. Also, just looking up Immutable object in Wikipedia gives some reasons for immutability as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width