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. Why functional programming should be the future of software development

Why functional programming should be the future of software development

Scheduled Pinned Locked Moved The Insider News
functionalquestion
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

    IEEE Spectrum[^]:

    It’s hard to learn, but your code will produce fewer nasty surprises

    Won't you take me to func-y town?

    D O 2 Replies Last reply
    0
    • K Kent Sharkey

      IEEE Spectrum[^]:

      It’s hard to learn, but your code will produce fewer nasty surprises

      Won't you take me to func-y town?

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

      Quote:

      Back then, this was a radical idea, and many programmers resisted the loss of a statement that they had grown to rely on. The debate went on for more than a decade, but in the end, the GOTO went extinct, and no one today would argue for its return.

      That's debatable. Here's some code from my Wordle solver that loops through the letters of a word, and if one of those letters matches a list of letters at that position which have been eliminated from the running it skips to the next word using a goto. I'm certain it could be done with another construct, but the time to figure out that other construct is a waste when this approach is so simple and directly mirrors the problem's solution:

              foreach (string str in currentPossibilities) {
                 isPossibility = true;
                 for (int i=0; iOf course I would never go back to the spaghetti-code `goto` use, and don't use it often. But when it comes to mind first, and is simple, use it and get on to the next problem.
      

      Our Forgotten Astronomy |

      S R 2 Replies Last reply
      0
      • D David ONeil

        Quote:

        Back then, this was a radical idea, and many programmers resisted the loss of a statement that they had grown to rely on. The debate went on for more than a decade, but in the end, the GOTO went extinct, and no one today would argue for its return.

        That's debatable. Here's some code from my Wordle solver that loops through the letters of a word, and if one of those letters matches a list of letters at that position which have been eliminated from the running it skips to the next word using a goto. I'm certain it could be done with another construct, but the time to figure out that other construct is a waste when this approach is so simple and directly mirrors the problem's solution:

                foreach (string str in currentPossibilities) {
                   isPossibility = true;
                   for (int i=0; iOf course I would never go back to the spaghetti-code `goto` use, and don't use it often. But when it comes to mind first, and is simple, use it and get on to the next problem.
        

        Our Forgotten Astronomy |

        S Offline
        S Offline
        Super Lloyd
        wrote on last edited by
        #3

        I really can't stand the nay-sayer, consequently I have been very vocal about my, errmm... 3? goto statements in the last 20 years, haha! Not that I care much... I am just annoyed by the anti goto bigotry! ;P A few cool use for goto I can think of right away, one that doesn't break logical flow or understanding, is escaping multiple nested loops, ... also maybe goto in switch statement too? although that one might be confusing...

        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

        D 1 Reply Last reply
        0
        • S Super Lloyd

          I really can't stand the nay-sayer, consequently I have been very vocal about my, errmm... 3? goto statements in the last 20 years, haha! Not that I care much... I am just annoyed by the anti goto bigotry! ;P A few cool use for goto I can think of right away, one that doesn't break logical flow or understanding, is escaping multiple nested loops, ... also maybe goto in switch statement too? although that one might be confusing...

          A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

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

          goto theHeadOfTheClass;

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

          1 Reply Last reply
          0
          • D David ONeil

            Quote:

            Back then, this was a radical idea, and many programmers resisted the loss of a statement that they had grown to rely on. The debate went on for more than a decade, but in the end, the GOTO went extinct, and no one today would argue for its return.

            That's debatable. Here's some code from my Wordle solver that loops through the letters of a word, and if one of those letters matches a list of letters at that position which have been eliminated from the running it skips to the next word using a goto. I'm certain it could be done with another construct, but the time to figure out that other construct is a waste when this approach is so simple and directly mirrors the problem's solution:

                    foreach (string str in currentPossibilities) {
                       isPossibility = true;
                       for (int i=0; iOf course I would never go back to the spaghetti-code `goto` use, and don't use it often. But when it comes to mind first, and is simple, use it and get on to the next problem.
            

            Our Forgotten Astronomy |

            R Offline
            R Offline
            Richard Deeming
            wrote on last edited by
            #5

            Depending on the types, why not simply:

            foreach (string str in currentPossibilities) {
            isPossibility = !p1NonChar.Contains(str[0])
            && !p2NonChar.Contains(str[1])
            && !p3NonChar.Contains(str[2])
            && !p4NonChar.Contains(str[3])
            && !p5NonChar.Contains(str[4]);

            if (isPossibility) reducedPossibilities.Add(str);
            

            }

            If the non-char values are strings, and you're using .NET Framework which doesn't have the Contains(char) overload[^], you can use IndexOf instead:

            foreach (string str in currentPossibilities) {
            isPossibility = p1NonChar.IndexOf(str[0]) == -1
            && p2NonChar.IndexOf(str[1]) == -1
            && p3NonChar.IndexOf(str[2]) == -1
            && p4NonChar.IndexOf(str[3]) == -1
            && p5NonChar.IndexOf(str[4]) == -1;

            if (isPossibility) reducedPossibilities.Add(str);
            

            }

            The && operator is short-circuiting, so it will stop testing when it reaches the first non-char.


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            D 1 Reply Last reply
            0
            • R Richard Deeming

              Depending on the types, why not simply:

              foreach (string str in currentPossibilities) {
              isPossibility = !p1NonChar.Contains(str[0])
              && !p2NonChar.Contains(str[1])
              && !p3NonChar.Contains(str[2])
              && !p4NonChar.Contains(str[3])
              && !p5NonChar.Contains(str[4]);

              if (isPossibility) reducedPossibilities.Add(str);
              

              }

              If the non-char values are strings, and you're using .NET Framework which doesn't have the Contains(char) overload[^], you can use IndexOf instead:

              foreach (string str in currentPossibilities) {
              isPossibility = p1NonChar.IndexOf(str[0]) == -1
              && p2NonChar.IndexOf(str[1]) == -1
              && p3NonChar.IndexOf(str[2]) == -1
              && p4NonChar.IndexOf(str[3]) == -1
              && p5NonChar.IndexOf(str[4]) == -1;

              if (isPossibility) reducedPossibilities.Add(str);
              

              }

              The && operator is short-circuiting, so it will stop testing when it reaches the first non-char.


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

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

              Richard Deeming wrote:

              why not simply: ...

              Did not know about those functions. If they are inline, great! And they can eliminate the boolean 'isPossibility' variable! Thanks for sharing!

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

              1 Reply Last reply
              0
              • K Kent Sharkey

                IEEE Spectrum[^]:

                It’s hard to learn, but your code will produce fewer nasty surprises

                Won't you take me to func-y town?

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

                I attempted to read this article. Talk about hogwash interspersed with issues relating to the misuse of language features. As far as I could tell the bottom line of this article was a sales attempt for a new "functional" language.

                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