Slashdot Mirror


Ask Slashdot: Do You Like Functional Programming? (slashdot.org)

An anonymous reader writes: Functional programming seems to be all the rage these days. Efforts are being made to highlight its use in Java, JavaScript, C# and elsewhere. Lots of claims are being made about it's virtues that seem relatively easy to prove or disprove such as "Its use will reduce your debugging time." Or "It will clarify your code." My co-workers are resorting to arm-wrestling matches over this style choice. Half of my co-workers have drunk the Kool-Aid and are evangelizing its benefits. The other half are unconvinced of its virtues over Object Oriented Design patterns, etc.

What is your take on functional programming and related technologies (i.e. lambdas and streams)? Is it our salvation? Is it merely another useful design pattern? Or is it a technological dead-end?

Python creator Guido van Rossum has said most programmers aren't used to functional languages, and when he answered Slashdot reader questions in 2013 said the only functional language he knew much about was Haskell, and "any language less popular than Haskell surely has very little practical value." He even added "I also don't think that the current crop of functional languages is ready for mainstream."

Leave your own opinions in the comments. Do you like functional programming?

283 of 418 comments (clear)

  1. It has its uses by RightwingNutjob · · Score: 5, Insightful

    but I'm skeptical about functional as the hammer for every nail. Generics and lambda expressions in C++ can make some niche problems disappear entirely by making the compiler do all the work for you, Scheme and Lisp and the like are useful for some very narrow and very academic use cases. As the go-to tool in the tool box? Not so much.

    1. Re:It has its uses by beelsebob · · Score: 5, Insightful

      There's two big things that have come out of the recent move towards more functional programming which are really important.

      1) People are understanding that reducing the amount of state that any particular bit of code carries reduces the complexity of working with it. Less state means more testability, more easy reasoning about the code, more clarity, more easy debugging, and fewer edge cases to consider. That's not to say that you should never has state, as pure functional programming would have you believe, but reducing state dependance pretty much helps make your code better universally.

      2) People are realising that inheritance is not the be-all and end-all of modelling code that the OOP world would have you believe. They're realising that inheritance is what screws up type systems, and makes them hard to work with. They're realising that deep inheritance hierarchies often lead to complex code which is tricky to understand exactly what code is going to execute when, and where you're going to jump to when you're reading it. Again - this isn't to say you should never use inheritance, but people are realising that composition can work equally well, or better, and that using it over inheritance has some substantial benefits.

      As to the bandwagon of "write javascript, it's a functional language, that makes it brilliant". Fuck off... That's just yet another of the latest fads towards pascal on trains; nodeHaskell; and reactMonkey. I'll happily sit here continuing to write ancient languages, but trying to apply some of the concepts from FP to make my code simpler and more readable.

    2. Re:It has its uses by beelsebob · · Score: 2

      The same problem they solve in any other language - they allow you to easily express a function that captures values from a dynamic scope.

    3. Re:It has its uses by thogard · · Score: 3, Insightful

      I see lambdas as the opposite end of the pendulum swing from the goto statement.

      They have their place but they both lead to lots of confusion with poor coders who are trying to maintain very old code.

    4. Re:It has its uses by Goondra · · Score: 1

      Exactly! What is trying to be solved? With garbage collection debugging is greatly reduced. With strong typing many errors are caught at compile time. LISP is nice but I never need it.

      --
      DGDanforth
    5. Re:It has its uses by plopez · · Score: 2

      *2) People are realising that inheritance is not the be-all and end-all of modelling code that the OOP world would have you believe*

      In the GoF book they flat out state that they prefer aggregation to inheritance. There is a reason you cannot do diamond inheritance in Java. Am I the only one who got the memo?

      --
      putting the 'B' in LGBTQ+
    6. Re:It has its uses by Dutch+Gun · · Score: 5, Interesting

      Few "in the OOP world" (whatever that means) promotes inheritance as the end-all-be-all these days. I think that went out of style fifteen or twenty years ago. The notion of eschewing inheritance whenever possible has its own Wikipedia entry, and was described in detail in the famous "Design Patterns" gang of four book.

      That being said, there's a time when reality can intrude on "theoretically" clean designs or programming paradigms. Functional programming and unit testing are things you don't see widely used in the videogame development world, at least that I've seen. Not all paradigms and patterns apply to all types of problems. Ultimately, I think that's the most valuable thing I've learned over time. Use the tools and techniques most appropriate to the problem at hand you're trying to solve. Religious wars over programming techniques and methodologies are for pedantic fools.

      --
      Irony: Agile development has too much intertia to be abandoned now.
    7. Re:It has its uses by jandrese · · Score: 3, Insightful

      There is certainly value in reducing the amount of state you are managing, but too often it seem like Functional programmers are willing to declare it gone when they've just swept it under the rug. Sure you don't have a variable now, but instead you have the logic tied up in your stack. This is especially true when the language does pattern matches on the parameters to determine which function to call. In the end you have to keep track of that iterator somehow, and I tend to think something like a for loop tends to be clearer than looking through the function headers to figure out how the loop is initialized and when it terminates.

      --

      I read the internet for the articles.
    8. Re:It has its uses by Anonymous Coward · · Score: 1

      As far as I've seen, it's primary use is to allow people to write the least efficient and most memory hungry code possible to handle tasks better approached with OO . It's a shame that more people don't understand what's going on under the hood when they use FP.

    9. Re:It has its uses by dcollins · · Score: 2

      "People are realising that inheritance is not the be-all and end-all... They're realising that deep inheritance hierarchies often lead to complex code which is tricky to understand exactly what code is going to execute when..."

      I'm pretty sure it was 1990 when one of my professors said, "We used to worry about spaghetti GOTOs; now we have to worry about spaghetti inheritance".

      --
      We know where leadership by an anti-intellectual "strongman" who scapegoats minorities and likes boisterous rallies goes
    10. Re:It has its uses by jbolden · · Score: 1

      I'm not sure what you mean having to keep track of an iterator. Can you provide an example?

    11. Re:It has its uses by Anonymous Coward · · Score: 1

      Scheme and Lisp and the like are useful for some very narrow and very academic use cases

      Scheme and Lisp aren't functional programming languages, although they support programming in a functional style.

    12. Re:It has its uses by dgatwood · · Score: 1

      Functional programming and unit testing are things you don't see widely used in the videogame development world, at least that I've seen.

      I'd expect functional programming to be used quite a bit in that space, but only for very small chunks of performance-critical code, such as massively parallel bits down in the guts of raytracing engines. Now whether they actually use functional programming languages or not is another question.

      Unit testing is something you don't see widely used in software development, period, unfortunately. But the industry is getting better. Slowly. Very slowly. Very, very slowly. Glacially, really.

      --

      Check out my sci-fi/humor trilogy at PatriotsBooks.

    13. Re:It has its uses by Z00L00K · · Score: 4, Insightful

      Strong typing with static declarations may seem to be cumbersome to many but the good thing with the strong static typing is that you get slapped already when compiling and not late during execution when an obscure obnoxious condition is fulfilled. Of course unit testing should capture even obscure obnoxious conditions but since not every test is updated when the code is updated then it's easy to miss.

      However sometimes lambdas are also useful - but they shall be used with care. There's no golden solution that can capture everything, instead different parts of an application shall be implemented in different ways to get the most effective solution. It will of course mean that developers have to know more than one programming language and paradigm.

      --
      If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
    14. Re:It has its uses by Anonymous Coward · · Score: 1

      Lambdas are function literals, in the same way that 2 is an int literal. For some situations, it's less work and clearer to put a function directly where it's needed, rather than creating a new named function elsewhere. Example, to check if all elements of a std::vector<int> are positive:

      std::vector<int> foo = { /* stuff */ };
      bool all_positive = std::all_of(foo.begin(), foo.end(), [](int x){ return x > 0; });

      In the same way that 0 does not need to be put into a variable, the test function is better placed inline as a lambda, as it is obvious what it does. It's use is pretty niche, as anything more complicated probably deserves to be written as a standalone function, but it serves a purpose.

    15. Re:It has its uses by Z00L00K · · Score: 2

      And spaghetti inheritance is especially prevalent in some solutions where there's an unnecessary amount of interfaces declared - so that everything is just declared and accessed through badly documented interface items so you can't figure out how to create new objects when you need them.

      Don't get me wrong - interface declarations are good too, but they have to be documented so others can understand how the objects they carry are constructed. The overall system design strategy is also something that has to be well thought out. Too much work put into abstracting away the physical world can create a system that's hard to maintain too. Layers upon layers hiding how stuff really works means that nobody will be able to understand it after a while.

      --
      If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
    16. Re:It has its uses by RightwingNutjob · · Score: 4, Insightful

      It ain't f'ing unnecessary. If it's a spaghetti or gotos it'll be a spaghetti of inheritances or a spaghetti of lambda's. At some point, the complexity of the task the program is executing requires complex code. Goto's can be done so that they're easy to understand. So can inheritance. So can lambda's. But you've got to be aware of the fact that some things are just plain hard to understand because they're hard, no matter how good of a communicator the programmer is.

    17. Re:It has its uses by RightwingNutjob · · Score: 1

      I could say the same thing about OO. And frequently do. Touche, AC.

    18. Re: It has its uses by Anonymous Coward · · Score: 5, Interesting

      Lambdas are simple and nice. It's just overhyped and people get confused because hype generates fanboi noise that hide the actual facts.

      One good use of Lambdas is to implement the GOF strategy pattern. You can do it without Lambdas, but it's really verbose and hard to read in Java due to the amount of interface and one time use classes and objects simply to define a processing strategy. Lambdas make it much more concise and simple.

      Its important for frameworks to allow others to specify processing "strategies". Some frameworks like Spring use such techniques very extensively. When you use a framework you want others to write less code and reduce boilerplate, so people who write frameworks find Lambdas awesome. When I write frameworks and engines I get irritated by the sheer amount of boiler plate to do strategy pattern and comment the code so that people can understand my code. Good code should be self readable and strategy pattern on Java isn't readable to less savvy programmers.

      For users of the frameworks it's just a few lines less code which they "cut and paste" anyway and many don't see why they have to spend time learning Lambdas so they can save a few lines here and there.

      I think Lambdas are a good feature to make coding in Java more elegant. Coding elegance has a long pay off and inflict short term pain to change which is why people who don't understand hate it. They hate it even more at the level of hype something with so little immediate value gets forced fed to them.

      I woul agree that if you have less than 5 years left in your coding career, Lambdas are a waste of time.... but hey think of the children!

    19. Re: It has its uses by thsths · · Score: 2

      The beauty of Lambda expression is that it moves features that are classically considered key language elements into a library: if-then statements, loops, etc can all be library functions. And it makes typical library function like optimization algorithms or other analysis methods much easier to use. In numerical computing, Lambda expressions certainly have their place.

      Of course in GUI development, Lambda can also be very convenient. But you need to make sure that you keep concerns together, and that can be a challenge.

      Coming back to the original question of Java: Java was a good language, but a poor implementation. What really kept it back was the license: Java (like Flash) was always designed as a plug-in, running side by side with the browser, not an integrated part of the browser. The Javascript engine is much more powerful in terms of interaction with the browser (DOM and stuff), and that is the reason it succeeded.

    20. Re:It has its uses by arglebargle_xiv · · Score: 1

      I would have expected that everyone wants functional programming. Well, except for people being specifically paid to fix up dysfunctional programming, but I'll take functional code any day of the week.

    21. Re: It has its uses by MichaelSmith · · Score: 1

      But with two or three promise implementations, and now you have multiple versions of each control structure.

    22. Re: It has its uses by countach · · Score: 1

      Nobody's ever made a type system that doesn't need ways to get around it in a non trivial program. Admittedly the type system ends up still being useful.. up until it isn't.

    23. Re:It has its uses by DrXym · · Score: 2
      They're a relatively concise way of creating a reusable anonymous function and binding values to them and having the code inline and next to the functionality it's relevant to. This isn't a new concept since C has always allowed function pointers to be passed around (e.g. for qsort) and boost has had function bindings well before C++11. But now they're part of the language and therefore more useful.

      But like all things they should be used with due consideration. C++ doesn't help itself by having horrible syntax for iterating collections.

    24. Re:It has its uses by K.+S.+Kyosuke · · Score: 1

      2) People are realising that inheritance is not the be-all and end-all of modelling code that the OOP world would have you believe. They're realising that inheritance is what screws up type systems, and makes them hard to work with. They're realising that deep inheritance hierarchies often lead to complex code which is tricky to understand exactly what code is going to execute when, and where you're going to jump to when you're reading it. Again - this isn't to say you should never use inheritance, but people are realising that composition can work equally well, or better, and that using it over inheritance has some substantial benefits.

      I'm not really sure what this has has to do with functional programming specifically, as operator dispatch strategies seem to be a completely orthogonal issue from mutable state reduction (or elimination). Just because contemporary "purer" functional programming languages don't support the same kinds of constructs that, say, CLOS does, it not seem to follow that a functional language has to have only rudimentary facilities for code arrangement.

      However, as Sussman has noted in the wizard book, more complicated ontologies do appear to require the kind of automated reasoning and mechanized common sense which we haven't sufficiently tackled (yet, at least), so in languages with stricter requirements for ahead-of-type checking, more complicated constructs can indeed be mutually exclusive with said checking.

      (Some special cases do come to mind where a more specialized operation can be more computationally efficient but is semantically equivalent, therefore there is no violation of type checks even if you don't know what will get executed. Imagine operations on special types of matrices taking shortcuts delivering the same result as a more generic operator, only faster. These are often predicate classes, though, so the type system and the language would have to be significantly extended in many cases anyway.)

      --
      Ezekiel 23:20
    25. Re:It has its uses by angel'o'sphere · · Score: 1

      Are you really that dumb?
      When you are using Lambdas in C++: you are doing functional programming. (*facepalm*)

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    26. Re:It has its uses by silentcoder · · Score: 4, Interesting

      The value of a lambda is greatly reduced in a language like python (though it supports them) where functions are first-class objects - when you can store functions and pass them around as variables the benefits of named functions hugely improve and much of what a lambda does can be done more cleanly by using data structures.

      So, for example, by storing functions as values in a dict you can build complex structures of execution without using any conditional codes . A long cluster of nested if-statements can be reduced to a single dictionary accessor. This is one of the standard ways to the common python-challenge of implementing Conway's game of life without using any if statements.

      This, in fact, was what I found most annoying working in Ruby as opposed to python - the fact that functions are not first-class objects force you to use things like lambdas even where more elegant solutions may otherwise have been available.

      --
      Unicode killed the ASCII-art *
    27. Re:It has its uses by silentcoder · · Score: 3, Interesting

      I would argue that OO remains the best paradigm we have for constructing data presentation - especially when the data represents something that exists in the real world (or a reasonable facsimile as in GUI programming or video-game dev). Functional programming on the other hand - is often the best paradigm we have for data processing, especially big data processing. Use them each in their own domains and break these rules-of-thumb whenever it makes sense to.

      --
      Unicode killed the ASCII-art *
    28. Re:It has its uses by dcollins117 · · Score: 3, Insightful

      They have their place but they both lead to lots of confusion with poor coders who are trying to maintain very old code.

      If you're using poor coders to maintain very old code then perhaps the choice of programming style is not your biggest problem.

    29. Re:It has its uses by TheRaven64 · · Score: 4, Informative

      In C++14 in particular, lambdas with auto parameters dramatically reduce copy-and-paste coding. If you have a couple of lines of code that's repeated, it isn't worth factoring it out into a separate templated function (in particular, you'll often need to pass so many arguments that you'll end up with more code at the end), but pulling it into a lambda that binds everything by reference and has auto-typed parameters can reduce the amount of source code, while generating the same object code (the lambda will be inlined at all call sites).

      --
      I am TheRaven on Soylent News
    30. Re: It has its uses by angel'o'sphere · · Score: 1

      Any examples for that?

      I never had the need to circumwent the type system, and I used plenty of languages, where you simply can't circumvent it.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    31. Re:It has its uses by TheRaven64 · · Score: 3, Interesting

      This needs moderating up. Talk to an Ocaml programmer and a Haskell programmer about what makes a functional language and you'll see very different opinions and these two are languages that were actually designed as functional languages: the bits that end up in other languages are a tiny subset.

      Coming from the Haskell side, I see functional programming as programming without side effects and with monads. You can implement monadic constructs in other languages, but it rarely makes code cleaner. Just having higher-order functions doesn't make a language a functional language any more than having structs makes C an object-oriented language.

      If the question is 'do you think using higher-order functions simplifies the expression of some algorithms' then the answer is obviously 'yes': programmers have a lot of tools to choose from and most of them are useful at least some of the time.

      --
      I am TheRaven on Soylent News
    32. Re:It has its uses by angel'o'sphere · · Score: 1

      The STL had/has an apply() function (perhaps called slightly different, e.g. for_each() ) since its inception.
      Obviously it had no real lambdas, and relied on overwritten "operator()" methods. You called that "functor objects".
      So boost was by far not the first one offering that.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    33. Re:It has its uses by Big+Hairy+Ian · · Score: 5, Funny

      Religious wars over programming techniques and methodologies are for pedantic fools.

      Us Pastafarians would disagree! We prefer to write Spaghetti Code :D

      --

      Build a Man a Fire, and He'll Be Warm for a Day. Set a Man on Fire, and He'll Be Warm for the Rest of His Life.

    34. Re:It has its uses by Moridineas · · Score: 2

      I remember back in school writing a (very rudimentary) MIPS emulator for a class assignment. Since most of the students had never used C before school (and were, in any case, more used to C++ references than pointers), apparently I was the only person in ~10 years that implemented the emulator using an array of function pointers (indexed on op codes). I thought it was a pretty cool innovation, then I read about jump tables.

      Still cool :-)

    35. Re:It has its uses by silentcoder · · Score: 2

      That's actually a very similar technique - and its a perfectly valid one, it's also a very FAST one since accessing an array element (or for that matter a dictionary value by key) is an atomic operation that only requires a single CPU instruction. Python making functions first-class object is, effectively, a very elegant way of bringing the capabilities of C's function-pointers into a high-level object oriented language, and a bit easier to work with since you're not (visibly) dealing with pointers since you can address the function by name.

      def test( str ):
          print("Hello %s" %str)

      test('John') #Calls the function - prints 'Hello John'
      mydict = {'X': test} # Address the function, stores it as a value in the dictionary, does not run it
      mydict[X]('Mike') #Prints 'Hello Mike'

      It is also possible to use a function as the KEY in a dictionary - though I've never seen anybody actually do that and I would be hard pressed to come up with any use-case for doing so.

      --
      Unicode killed the ASCII-art *
    36. Re:It has its uses by Wootery · · Score: 2

      very small chunks of performance-critical code, such as massively parallel bits down in the guts of raytracing engines. Now whether they actually use functional programming languages or not is another question.

      Looking at OpenCL/Vulkan/Direct3D/OpenMP/etc, the answer seems to be a clear no. The lots-of-'threads'-running-sequential-C-code model seems to work pretty well though, and programmers are essentially forced to think about state. You don't stand much of a chance messing about with globals in those environments (but I guess you could try it).

    37. Re:It has its uses by beelsebob · · Score: 2

      Games dev actually avoids OOP like the plague these days. Anything that runs on the GPU is purely functional, much of what runs on the CPU is purely functional, and data oriented rather than object oriented. Games devs care more about whether you can keep everything in cache, and crunch through it, rather than whether its modeled nicely.

    38. Re:It has its uses by beelsebob · · Score: 1

      You're right - it is orthogonal. But it's something that comes with the territory. Almost every single functional programming language out there uses some variant on ADTs to model data, not inheritance hierarchies. People start realizing that there are other (better) ways to model concepts when they're temporarily forced to think that way.

    39. Re: It has its uses by Anonymous Coward · · Score: 2, Interesting

      This was the subject of Brian W. Kernighan's paper: Why Pascal is Not My Favorite Programming Language, where he analyzes converting software tools to Pascal. His conclusion summarized the problems I was having in being forced to use ADA for DOD. Of course in the DOD's case, they deliberately closed the language, and that's why C passed it by.

            9) There is no escape.

      This last point is perhaps the most important. The language is inadequate but circumscribed, because there is no way to escape its limitations. There are no casts to disable the type-checking when necessary. There is no way to replace the defective run-time environment with a sensible one, unless one controls the compiler that defines the ``standard procedures.'' The language is closed.

      People who use Pascal for serious programming fall into a fatal trap.

      Because the language is so impotent, it must be extended. But each group extends Pascal in its own direction, to make it look like whatever language they really want. Extensions for separate compilation, Fortran-like COMMON, string data types, internal static variables, initialization, octal numbers, bit operators, etc., all add to the utility of the language for one group, but destroy its portability to others.

      I feel that it is a mistake to use Pascal for anything much beyond its original target. In its pure form, Pascal is a toy language, suitable for teaching but not for real programming.

      http://www.cs.virginia.edu/~evans/cs655/readings/bwk-on-pascal.html

    40. Re:It has its uses by silentcoder · · Score: 1

      I could see that in performance heavy FPS's and such - but the idea of trying to code an RPG without objects seems mindbogglingly painful.

      --
      Unicode killed the ASCII-art *
    41. Re:It has its uses by luis_a_espinal · · Score: 1

      I see lambdas as the opposite end of the pendulum swing from the goto statement.

      They have their place but they both lead to lots of confusion with poor coders who are trying to maintain very old code.

      That's not a function of lambdas, or gotos for that matter. I've seen elegant, clear solutions using gotos that made code simpler to read. Same with lambdas. As a matter of fact, same with everything in a programming tool set.

      It's not what you use to write code, but how you write code, how you compose it. That's what makes code maintainable, not the lack or usage of some feature.

    42. Re:It has its uses by jandrese · · Score: 1
      Sure, lets look at two examples:
      Iterative program:

      variable loop_counter;
      for ( loop_counter = 0; loop_counter < 10; loop_counter = loop_counter + 1 )
      {
      do_stuff()
      }

      Functional program:

      function do_stuff_loop(x, x)
      { }
      function do_stuff_loop(x, y)
      {
      do_stuff()
      do_stuff_loop(x + 1, y)
      }
      do_stuff_loop(0, 10)

      In the iterative example you have a variable which changes, causing pain to functional programmers who gaze upon it. In the second your iterator is still there, but it's hidden in the stack instead of being explicitly declared.

      --

      I read the internet for the articles.
    43. Re: It has its uses by Lije+Baley · · Score: 2

      Heresy! How dare you take the focus away from the almighty Tool? You are practically taking food right out of the mouths of authors and trainers! And don't forget the psychic damage to the gurus! Why won't you think of the gurus??

      --
      Strange things are afoot at the Circle-K.
    44. Re:It has its uses by DarkOx · · Score: 1

      You can do this just fine in Ruby, using the method method, ie to get foo you'd do method :foo. You could do something like

      myhash[f:oo] = method :foo
      myhash[:foo].call arg1

      so you can build the same structure you are describing in Ruby without much difficultly, although admittedly this might be one of the few places where Python might actually be syntactically superior.

      --
      Repeal the 17th Amendment TODAY! Also Please Read http://www.gnu.org/philosophy/right-to-read.html
    45. Re: It has its uses by silentcoder · · Score: 1

      Thats not a first class object. Having an approximate work-around for one use-case is good - but not comparable. In python I can all methods on methods, and access their attributes, in clean and elegant ways with no hackishness.

      --
      Unicode killed the ASCII-art *
    46. Re: It has its uses by lgw · · Score: 2

      I never had the need to circumwent the type system, and I used plenty of languages, where you simply can't circumvent it.

      Not sure what language you're using, but most have either void* or Object. The more refined version is "downcasting" a base type to a derived type. Any time you set the type of an object dynamically at runtime, you're bypassing strong type checking. And don't get me started on reflection.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    47. Re:It has its uses by lgw · · Score: 2

      Explain to me, what problems do lambdas solve in C++?

      Lambda make for sane "list comprehension", that is, transforming a list in some simple way, or taking a simple action for each item in a list (or any other collection).

      C++ was years behind pretty much every other mainstream language but C in list operations. You should never need to code a for loop to do something simple to or with each item in a list.

      Also, more generally, lambdas are useful everywhere for defining function that are short, and only called from one place. As a sibling post points out, they are "function literals", and with other sorts of literals, code is more clear if your literals are simply in-line in your code, not defined elsewhere (when the value is only used once).

      Returning a lambda as the result of a function is where is gets dubious: usually at that point, it's going to be more clear and easier to debug to make a named class/interface that expresses the captured functionality, with a named method. More typing, but self-documenting. Any time a lambda is used from where you can't see the definition, it's a warning sign the code may be confusing.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    48. Re: It has its uses by angel'o'sphere · · Score: 1

      In languages like Java or C# type safety during a downcast is not compile time enforced ... however it is still type safe (you get runtime exceptions).
      It should be avoided of course, but there are situations where you can't. (Have non at hand at the moment, as I wrote my last down cast ages ago and don't remember why it was needed)

      Regarding reflection: using reflection is still type safe, so what are you referreing. too?

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    49. Re:It has its uses by swillden · · Score: 1

      There's two big things that have come out of the recent move towards more functional programming which are really important.

      You missed the biggest one: Eliminating mutable state makes code inherently safe for concurrency. Not an inconsiderable issue, since the direction of hardware progress seems to be towards ever more cores.

      Of course, pure functional programming eliminates mutable state by creating massive numbers of copies. Actual functional programming languages (e.g. Haskell) are quite clever about optimizing out nearly all of those copies, but the result of that is that the generated code has mutable state. Still, this may very well be the best way forward... automatic parallelization of imperative code is very hard. It may well be that it's easier to automatically decide how to split work up by analyzing data copying, and then apply copy optimization to each thread.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    50. Re:It has its uses by hey! · · Score: 1

      At some point, the complexity of the task the program is executing requires complex code.

      This is a more profound statement than it appears at first. I'd say that the minimal complexity of the code necessary to accomplish a task defines the complexity of the task itself.

      As for GOTO the issue isn't GOTO per se, but implicitly building other control structures like loops using GOTO as a primitive -- a legacy of the very earliest machine languages in which you implemented algorithms using a very limited instruction set. The flexibility of GOTO makes it a good choice if you have only a few control structures to work with; but that same flexibility imposes the cognitive load of figuring out what the original programmer (possibly yourself) meant.

      But even if more structured (i.e., limited) control structures available, there are problems where GOTO is the natural way to express them. State machines for example. I've seen them implemented with long if-then-elseif chains or case conditional constructs, but that's just thoughtless programming that obscures what is going on. A state machine is much more clearly implemented with GOTOs, although tail recursion can be a reasonable alternative.

      --
      Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
    51. Re:It has its uses by jbolden · · Score: 1

      That's just bad functional code. What you are describing (though the notation is hard to follow) sounds like a fold. https://wiki.haskell.org/Fold
      That has final and initial values.

      The other thing is you don't want to be "doing stuff" and iterating. You want to be computing stuff and then "doing stuff" on the entire set of output. The system as it pulls output will drive the iteration on the computation. What you have above is sequenced. Getting rid of explicit sequencing is part of writing functional code.

    52. Re:It has its uses by Anonymous Coward · · Score: 1

      Sometimes the poor coder is an excellent coder who needs nudging and mentorship to bring that coder out; but we don't train our devs anymore.

      I came from an old-school shop. I was not expected to know everything as soon as I sat down. I was, in the truest sense of the world, extremely *junior*. And the Sr. Developer, who had been coding for longer than I'd been alive, sat down for my monthly status updates, and the one thing he always impressed upon me was that I wasn't writing code for myself; I was writing it for the next developer. Thus, the avoidance of "tricks" and "cleverness", which only serve as a form of mental masturbation. If you ever write a piece of code and feel particularly clever? Rewrite it because the next dev won't have the same context you had when you had your "a-ha!" moment. Unless you absolutely have a reason to have it (and as a jr. developer, that will never be the case. and as a Sr. Developer, you know better than to do so).

    53. Re: It has its uses by spongman · · Score: 1

      Object is still strong. It's just not static.

    54. Re:It has its uses by Opyros · · Score: 1

      I'd say that the minimal complexity of the code necessary to accomplish a task defines the complexity of the task itself.

      Indeed.

    55. Re:It has its uses by jellomizer · · Score: 2

      The computer scientist in me loves functional languages, the MBA in me doesn't.
      Functional languages makes very tight code. Which for the programmer and the computer scientist is great. Less coding, a solid routine with little effort.
      However it makes it difficult to maintain a program over a life time. As it is always near one feature away from a full rewrite, vs just slapping some if conditional in the code which while inelegant, is easy to code, easy to see the change, and easier to test.
       

      --
      If something is so important that you feel the need to post it on the internet... It probably isn't that important.
    56. Re: It has its uses by jbolden · · Score: 1

      The classic example is church number subtraction. (I should mention Haskell solves this now via. rank 2 types, but very few languages have this).

      So just to define terms church numbers take two arbitrary values: think f = (+1), z = 0 for the trivial case
      zero f z = z
      one f z = (f z)
      two f z = f ( f z)
      three f z = f (f (f z))
      etc..

      given two church numbers
      minus n m should be the church number for their difference
      ie, for all f, z
      (minus three one) f z = two f z

      generally this is done by using the predecessor function
      pred n f z = snd $ n f' z' where
          f' (a,b) = (succ a, a)
          z' = (zero, zero)

      and then
      (minus m n) f z = (n pred m) f z

      minus is not expressible as a rank-1 type in any language. Since most languages don't have rank-2 types...

    57. Re:It has its uses by beelsebob · · Score: 1

      You do realise that "objects" are not the only way to encapsulate data, right?

      The thing that makes OOP OOP is inheritence, not the fact that you have a structure that represents some object - all programming languages have encapsulated data, whether they're OO or not.

    58. Re:It has its uses by beelsebob · · Score: 1

      The one core concept that makes functional programming different from anything else is "referential transparency". Referential Transparency is the property that you can substitute a call to a function with a given set of arguments with the result of that function in the program, and the behavior won't change at all.

      To put it another way - when you call a function, its result has to be determined based *only* on the arguments you pass in, not any external state that might be floating about. It's not allowed to go and fetch an instance variable; it's not allowed to poke a singleton and grab state out of it; it's not allowed to print something; and it's not allowed to launch missiles.

      What that gives you is:

      1) It's very easy to test those functions - you define a set of arguments, you define a correct result, and you say 'call this, and you should get this result'.

      2) It's very easy to parallelise these functions - since they're not affecting any outside state, no locking is necessary, you just run them side by side, and you're done.

      3) It's very easy to debug these functions, since you have a defined input, and a defined correct output, you can sit there and easily understand what's going on.

      4) it's very easy to reason about these functions, since you never read a chunk of code in them and go "god, what could all the values of this external state be?"

      5) It makes code clearer, since you can easily document exactly what that bit of code is doing, without any reference to any external parts of the system, or any prerequisites.

    59. Re: It has its uses by beelsebob · · Score: 1

      Actually, pure functional behaviour is exactly what *gives* you scalability.

      By removing state, you make it possible to run things on thousands and thousands of servers without having some shared memory bottleneck that everything needs to talk to.

    60. Re:It has its uses by HiThere · · Score: 2

      Functional languages are a bit more difficult to think about, but that may be a combination of my inexperience and the implementations I've seen. OTOH, some problems do not deal with with lack of state. I'd really like to use Erlang, e.g., but I need mutable state. You can do it in Erlang, but you've got to fight the system to do it.

      Note: I don't need externally visible mutable state. That's clearly dangerous in a concurrent system. I need internally mutable state. In Erlang that means either storing things in a hash table, a database, or a block of uninterpreted bytes. All ways that are clumsy to handle (and, I presume, slow). That Erlang allows this indicates that it is seen as something that is concurrently safe. But the difficulty in doing this shows that the designers of Erlang didn't see this as anything important for their use cases.

      Now it's a good question whether or not you consider immutability a part of the definition of functional programming. Lisp allows mutable state, so does Scheme. So does Erlang. But they all discourage it and make it difficult to use. It's my contention that the definition should restrict itself to shared mutable state, but I'm not sure that this is the consensus.

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
    61. Re:It has its uses by Anonymous Coward · · Score: 1

      ... the fact that functions are not first-class objects force you to use things like lambdas even where more elegant solutions may otherwise have been available.

      I think you misunderstand what it means to be a first-class object. Lambdas *are* first-class objects. The *only* difference between a lambda function and a named function object is that the lambda function is anonymous (i.e., has no name). *All* lambda functions in *all* languages that support lambdas are first-class objects.

    62. Re:It has its uses by Anonymous Coward · · Score: 1

      The thing that makes OOP OOP is inheritence, not ...

      Utter nonsense. You can do OOP programming without ever having a class hierarchy more than one level deep.

      The essence of OOP is having different classes, having encapsulated data, and having per-class (and sometimes per-object) methods to operate on that data. Inheritance is nice, but is absolutely not essential to doing OOP. In fact I've written many OOP programs where I never even used inheritance.

    63. Re: It has its uses by lgw · · Score: 1

      Static type checking is where all the value comes from. Finding errors at the most convenient time. But every mainstream language has an escape hatch.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    64. Re:It has its uses by RightwingNutjob · · Score: 1

      I personally like case or switch statements for my state machines. But that's just a prettified mess of goto spaghetti, especially if it looks like
      while(1){
      report_condition(condition);
      switch(condition){
      case CASE1:
      condition = do_case1();
      break;
      ...
      }
      Which it frequently will for complicated transition logic.

    65. Re:It has its uses by silentcoder · · Score: 1

      I never said it was the *only* way to do encapsulation - I said it was arguably the best way we have.

      --
      Unicode killed the ASCII-art *
    66. Re:It has its uses by xski · · Score: 1
      Agreed.

      IMO, once you move beyond manipulating primitive types, that is, once you start using things like arrays or some C 'struct'-like grouping of data you *are* using objects. Now you can either use good OOP for your purpose not so good OOP (it ain't just a river in Egypt).

    67. Re:It has its uses by xski · · Score: 1
    68. Re: It has its uses by DarkOx · · Score: 1

      It is a first class object. I passed an argument to it but there are all the usual methods on that method object. You absolutely can do something like:

      mymethods[:foo].name

      its valid and you'd get back its original name in this case. You could even define new methods on the object! It is a first class object in every way but how you happen to access it syntactically.

      --
      Repeal the 17th Amendment TODAY! Also Please Read http://www.gnu.org/philosophy/right-to-read.html
    69. Re:It has its uses by xski · · Score: 1
      That belongs on a T-shirt.

      Or maybe as the quote for one of those motivational posters you see hanging around cube farms.

      Or better yet, the inside of the eyelids of every human who even thinks about writing computer programs.

    70. Re: It has its uses by silentcoder · · Score: 1

      We are discussing syntax. That rather makes it an important consideration to the discussion.

      --
      Unicode killed the ASCII-art *
    71. Re:It has its uses by GuB-42 · · Score: 1

      The simplest one is a comparaison function for a generic "sort" function.
      It is much more convenient with lambdas.

    72. Re:It has its uses by lgw · · Score: 1

      None of that sounds right. Every heard of currying? There's no real difference between a lambda and an object full of state, beyond the syntax. Lambdas capture arbitrary state. (Plus, in real software, the results of some functions is often some measurement of some changing real-world thing.)

      --
      Socialism: a lie told by totalitarians and believed by fools.
    73. Re:It has its uses by beelsebob · · Score: 1

      Currying doesn't violate referential transparency. curry is a function that accepts a multiple argument function, and returns a one argument function. It always returns the same function when it's given the same function as an argument. That's referentially transparent.

      The difference isn't about being "full of state" it's about accessing state external to you. Again - if a function relies only on its arguments to determine its result, then it is referentially transparent, aka "purely functional".

    74. Re: It has its uses by DarkOx · · Score: 1

      Right but other than capturing the reference to the method in the first place, even the syntax is the same.

      Your only real complaint here (and I agree its valid) seems to be the return value of a "def" block is nil rather than the method object.

      --
      Repeal the 17th Amendment TODAY! Also Please Read http://www.gnu.org/philosophy/right-to-read.html
    75. Re:It has its uses by JesseMcDonald · · Score: 2

      There's no real difference between a lambda and an object full of state, beyond the syntax. Lambdas capture arbitrary state.

      When functional programmers talk about state they're referring to mutable state. What you are describing is simply data. Capturing immutable data provided through function arguments does not violate referential transparency. You still get the same result for the same arguments.

      Plus, in real software, the results of some functions is often some measurement of some changing real-world thing.

      That isn't a function, not in the mathematical sense. In Haskell it would be referred to as an I/O action. In functional programming objects exist which describe "impure" actions, such as sampling a sensor or printing to the console; these objects can be manipulated by pure functions, e.g. combining two actions to make a larger action, or mapping a function over the result, but are only executed (logically speaking[1]) by an impure external interpreter in the language runtime. The program itself is pure, even the parts which evaluate to IO actions—barring abuse of specific constructs like unsafePerformIO. The runtime, inevitably, is not pure, since has the responsibility of interfacing between the pure program and the real world.

      [1] For performance reasons, of course, the compiler actually "inlines" the interpreter, generating impure object code similar to a traditional compiled imperative program. The external interpreter, like the C virtual machine model, is merely an aid for thinking about the code, not a concrete implementation.

      --
      "The state is that great fiction by which everyone tries to live at the expense of everyone else." - Bastiat
    76. Re:It has its uses by lgw · · Score: 1

      When functional programmers talk about state they're referring to mutable state. What you are describing is simply data.

      That isn't a function, not in the mathematical sense.

      Until functional programmers start speaking the same language as people in industry, we'll keep rolling our eyes and ignoring you.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    77. Re:It has its uses by jandrese · · Score: 1

      The notation is simplified Erlang omitting the syntax I wasn't using and tweaking the glyphs a bit to make it look similar to the other example. Even if you wouldn't implement this example this way, it is the general way you program in a regex-argument functional language.

      --

      I read the internet for the articles.
    78. Re:It has its uses by jandrese · · Score: 1

      Someone else is going to come in and say the iterative version should be do_stuff().iterate(10) next.

      I'm trying to illustrate the difference in the language, not give a course on abstraction primitives.

      --

      I read the internet for the articles.
    79. Re:It has its uses by JesseMcDonald · · Score: 1

      ... we'll keep rolling our eyes and ignoring you.

      It's your loss. BTW, the mathematical definition of a "function" as a fixed mapping from objects in the domain to objects in the range has been around a whole lot longer than the (mis)use of the term to describe procedures or subroutines in (some) programming languages. The idea that "state" implies mutation is commonplace even within the more mainstream areas of the computer programming industry, not just among functional programmers.

      --
      "The state is that great fiction by which everyone tries to live at the expense of everyone else." - Bastiat
    80. Re: It has its uses by Anonymous+Brave+Guy · · Score: 1

      On the other hand, if you've used a language that is designed to support functional programming, you probably wouldn't be in much doubt.

      For example, here's the all-positive check written in Haskell:

      all_positive = all (>0) [1, 2, 3, 5, 8, 13]

      which is just a convenient notation for:

      all_positive = all (\x -> x > 0) [1, 2, 3, 5, 8, 13]

      where the backslash is Haskell's general syntax for introducing a lambda.

      Criticising the ideas of functional programming because, for example, C++'s syntax for lambdas is horrific is like criticising OOP because setting up dispatch via vtables is a bit messy in assembly language. It's just not the right tool for the job, and it's unlikely to give great results no matter what you do with it. You have to look at the underlying principles to see whether they're useful or not.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    81. Re:It has its uses by Anonymous+Brave+Guy · · Score: 1

      That's just bad functional code.

      It was a simplified example, but I think the point would still be valid in some more complicated case that doesn't fit one of the everyday functional programming patterns. The state is still there, it's just conveyed by accumulating function argument(s) in recursive, functional code instead of storing it in loop control variable(s) in imperative code.

      The other thing is you don't want to be "doing stuff" and iterating. You want to be computing stuff and then "doing stuff" on the entire set of output. The system as it pulls output will drive the iteration on the computation.

      I think you're conflating lazy evaluation with functional programming here. In any case, I think that sort of claim needs some qualification. Haskell-style laziness is nice for composition in theory and sometimes it lets us write very elegant code in practice, but it can also become a liability, particularly if you're working with very large amounts of data or anything time-sensitive.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    82. Re:It has its uses by Anonymous+Brave+Guy · · Score: 1

      Until functional programmers start speaking the same language as people in industry, we'll keep rolling our eyes and ignoring you.

      I'm pretty sure maths has been around longer than programming, so who is really redefining the language here?

      Also, false dichotomy is false. Functional programming concepts are widely and effectively used in industrial programming. The idea that what we're talking about is some academic, ivory tower idea is decades out of date.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    83. Re:It has its uses by Tablizer · · Score: 1

      Us Pastafarians...prefer to write Spaghetti Code

      That explains it! The coder who came before me at this org must have been a [bleepin'] Pastafarian. Next time I'll apply at a Catholic org.

    84. Re:It has its uses by jbolden · · Score: 1

      I'm going to argue there are no special cases that don't fit.

      Basically
      the set of all possible for loops (no side effects) \subset the set of all possible hylomorphisms (generalizations of map reduce) \subset of all possible recursions.

      That's why I wanted to see a real example, because of mathematically they can't exist.

      As for accumulators over loops those can be usually handled via. a fold providing the reduction operation is associative. The initial and final state never present a problem.

      ___

      I'll agree I was considering lazy part of functional. At this point I think purity allows for laziness and laziness demonstrates a lot of the advantages of purity. Otherwise you are backed to mixed paradigm which I dealt with other places in this thread. As for lazy with large amounts of data, Hadoop is lazy. So I'm not sure what you are saying.

    85. Re:It has its uses by Anonymous+Brave+Guy · · Score: 1

      I'm going to argue there are no special cases that don't fit.

      In a strictly mathematical sense, yes, various things are equivalent and various patterns are universal. However, that's a bit like saying you can do anything with sequencing, selection and repetition. While true in a sense, realistically it doesn't necessarily represent the clearest way to express everything. In practice, I have sometimes found that while I might build individual parts of a complicated algorithm from tools like folds, it may be clearer and easier to write the "big picture" using explicit recursion rather than trying to adapt everything to fit some standard algorithm.

      As a practical example, not so long ago I was working on some code that would take some information in a certain format as input, and update a rather complicated graph-like data structure to incorporate that extra information. This algorithm involved walking the graph, and depending on the properties of each node reached and of the information to be merged in, either updating that single node "in place" or changing the structure of the graph around it. Each such step would typically transfer some of the remaining information into the graph, and then continue walking the rest of the graph to merge in the rest of the information until one or the other ran out. No doubt with enough mathematical machinations this could have been shoe-horned into some standard pattern, but in practice it was far simpler and more transparent to write a small set of mutually recursive functions that implemented the required behaviour at each step. And of course each of those functions then received information about the state of the graph walk and the state of the information being merged in through parameters.

      At this point I think purity allows for laziness and laziness demonstrates a lot of the advantages of purity.

      If you only care about the result of evaluating a function, sure, but if you also care about the performance characteristics of your program, I don't think it's so simple. Laziness can be both a blessing and a curse.

      As for lazy with large amounts of data, Hadoop is lazy. So I'm not sure what you are saying.

      In short, unrestricted laziness can cause huge increases in the amount of working memory required to run a program, until finally something triggers the postponed evaluations and restores order. As I recall, there was even a simple tutorial example in Real World Haskell that could wind up exhausting the available memory just by scanning a moderately large directory tree because of the accumulated lazy thunks.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    86. Re:It has its uses by jandrese · · Score: 1

      That doesn't illustrate tail recursion though. Also, nobody who is not already a functional programmer is going to have a chance of following that.

      --

      I read the internet for the articles.
    87. Re: It has its uses by squiggleslash · · Score: 1

      Java (like Flash) was always designed as a plug-in, running side by side with the browser, not an integrated part of the browser. T

      Uh, what?

      Just because Sun developed a Java plug-in doesn't mean that Sun's vision was ever that Java was primarily supposed to be used that way. Java has always meant to be used as a standalone programming language, and the percentage of Java development targeted at the plugin is absolutely tiny. Most of it is focused on back-end applications, websites, and the occasional desktop app.

      I'm not sure where this "Java = applets" thing comes from, and it's especially hard to understand why software developers would think this given it's pretty hard to work in this industry for more than a few years without being given a Tomcat/etc application hosted in a JBoss environment to fix up.

      --
      You are not alone. This is not normal. None of this is normal.
  2. Dysfunctional programming by FrankHaynes · · Score: 5, Funny

    seem to be the prevalent choice on the web these days.

    --
    slashdot: A failed experiment.
    1. Re: Dysfunctional programming by Anonymous Coward · · Score: 1, Insightful

      Your code must be clean and maintainable, otherwise you won't get shit done for long. You'll just have shitty code.

    2. Re: Dysfunctional programming by prefec2 · · Score: 1

      That is why they all use JavaScript and PHP. Thanks.

  3. Lots of claims are being made about it's virtues by Anonymous Coward · · Score: 1

    A properly placed apostrophe has its virtues as well. it's means it is.

    It's amazing that people that can learn dozens of languages all more complex than the previous can't seem to grasp the humble apostrophe.

  4. functional composition by motorsabbath · · Score: 2

    I like functional composition, it certainly has its uses (at least as middleware). I disagree with the notion that it makes code more readable though, in general. It only makes code more readable if you're familiar with it (functional programming).

    --
    The heat from below can burn your eyes out
    1. Re:functional composition by Pseudonym · · Score: 2

      It only makes code more readable if you're familiar with it (functional programming).

      Well that's a truism. Object-oriented programming is the same: it only makes code more readable if you're familiar with it.

      The main distinction between the two, however, is that object-oriented programming was invented, but functional programming was discovered.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    2. Re:functional composition by Pseudonym · · Score: 1

      My impression is that functional programming comes from Lambda calculus which was introduced in the 1930's.

      Mostly correct. The Lisp family of languages borrow the lambda notation, but they're not based on lambda calculus in the Church/Tarski sense.

      The differences (and the differences between functional programming and the theory of sets-and-functions that we teach to high school students) don't really matter at a basic level.

      How are functional programs translated into machine code?

      Here you go. This book is 30 years old, but the basic principles are the same.

      That same complex algorithm that is simplified thanks to lambda calculus techniques might be so difficult to translate to machine code that the resulting program is less efficient.

      For what it's worth, the same is true of any high-level language. CPUs don't understand virtual dispatch natively, either.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
  5. Scala by Anonymous Coward · · Score: 3, Interesting

    I prefer to use functional programming where it makes sense (most of the time). One reason I like Scala is that it's not pure. You can always write a for loop if you need to. Haskell, is a bit less forgiving.

  6. As Bruce Lee said by Z80a · · Score: 2

    Use only that which works, and take it from any place you can find it.

    1. Re:As Bruce Lee said by Z00L00K · · Score: 1

      He's not truly dead until he's forgotten.

      --
      If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
    2. Re:As Bruce Lee said by DickBreath · · Score: 1

      Bruce Lee also said: If you spend too much time thinking about a thing, you'll never get it done.

      So he must have been an expert at avoiding work. And this quote is "that which works". (Or rather doesn't work.) And I did take it from any place I could find it . . . using google to find Bruce Lee quotes.

      --

      I'll see your senator, and I'll raise you two judges.
  7. "Like"? by eyenot · · Score: 5, Insightful

    I don't get what you mean by "like".

    Procedures are procedures, period.

    Sometimes it's helpful to have some procedure (or subroutine) store some value in some location before popping the stack.

    What I really don't get in this write-up is the insinuation that a focus on (purely) functional programming is a "recent trend". That implies that the majority of today's coders have no fucking idea how coding has progressed through the last few decades (which I've been there to see firsthand).

    That's the only interesting thing about this article.

    --
    "Stratigraphically the origin of agriculture and thermonuclear destruction will appear essentially simultaneous" -- Lee
    1. Re:"Like"? by gl4ss · · Score: 2

      That implies that the majority of today's coders have no fucking idea how coding has progressed through the last few decades

      ..and you were unaware of this? how in the hell?

      --
      world was created 5 seconds before this post as it is.
    2. Re:"Like"? by lucm · · Score: 4, Insightful

      What I really don't get in this write-up is the insinuation that a focus on (purely) functional programming is a "recent trend".

      There is a new area where functional programming does shine, and it's large scale analytics. Sometimes when you think about solving a specific problem, you can go about it in a few different ways, but almost every time if your solution later needs to be parallelized (i.e. running on a Hadoop cluster) the functional programming way will be easier to adapt.

      For instance, let's imagine a situation where you have a small e-commerce website and the marketing team wants to know what are the most common sequences of pages visited by users. You could write a quick & dirty python script that parses the logs and creates a hash of every possible sequence, then you could use that to "rank" sequences by time, browser, location, etc. Or you can play the fancy card and use something like Petri nets in a map-reduce-ish kind of way. Both approaches work.

      But then your small website becomes a big success, and grows and grows and grows, and one day your script runs out of steam. So you figure, let's run that bitch on a big Hadoop cluster. Well guess what, a script that is map-reduce friendly will be a lot easier to adapt for that.

      I'm not saying every single situation warrants for this kind of thinking. But that qualifies as a kind of problem that is fairly new for mainstream programmers.

       

      --
      lucm, indeed.
    3. Re:"Like"? by dgatwood · · Score: 1

      In the long run, I'd expect the tools to adapt to solve those problems more transparently, e.g. through the use of standardized libraries that hide the parallelization behind procedural wrappers so that developers can write seemingly procedural code, but gain the benefits of massively parallelized code for the pieces that matter.

      Or not; hard to say.

      --

      Check out my sci-fi/humor trilogy at PatriotsBooks.

    4. Re:"Like"? by angel'o'sphere · · Score: 1

      You don't know what functional programming is.
      That is clear from your comment.

      Hence you don't get the question about "like".

      Hint: there is wikipedia.

      And using "procedures" or "functions" in Pascal or C: that is not functional programming.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    5. Re:"Like"? by swillden · · Score: 2

      I don't get what you mean by "like".

      Procedures are procedures, period.

      Indeed they are. And purely functional programming languages don't have procedures.

      The grafting of functional programming constructs onto imperative languages is interesting and useful, but every programmer should spend some time learning to program in a purely functional style, even if they then go back to imperative languages for their everyday work. It opens up a whole new way of thinking about code.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    6. Re:"Like"? by jbolden · · Score: 1

      You really do have to start over and write code very differently. That's unavoidable. Procedural languages are good at sequencing things for a von-Neumann architecture. Parallel systems are not von Neumann Architectures. Procedural code encourages bad thinking habits which create runtime problems. To do massive parallelism you want all your code to not not specify order of operations (so the runtime engine can decide) and not involve state changes till the end (since these require synchronizing between computing nodes). If you think about the first thing you learned when you learned to program it was: " a program is a sequence of steps" (order of operations). The second think you learned was print (state change).

      You have to reorganize your code in a way consistent with a new paradigm. No library is going to solve that.

    7. Re:"Like"? by lucm · · Score: 1

      Business Requirements that expect the same code be running in 10 years on a massively different scale are usually a not very good idea.

      Twitter, Facebook, Amazon...

      --
      lucm, indeed.
  8. It's not that I want to brag I'm old... by gwolf · · Score: 3, Insightful

    But it seems that I will.

    Around ten years ago, I started writing a column for a magazine. My first article was precisely a way to use functional programming for "real" code, using a multi-paradigm language (Ruby).

    I didn't jump on the Functional bandwagon first time I saw it; it took me around ten years to understand and embrace what it can do. So we are talking about 20 years of hype. At least.

    I am far from proficiently thinking functionally, although I have used it for many interesting things. It is a cool, and very different, way to work. It can make many things faster and simpler, but if you completely bite the bullet and make it your dominant paradigm, it will kill your productivity (with many other things that are not best served by that paradigm.

    It has a clear spot under your programmer belt. But it should not be The Only Way to approach a program - unless you are Truly One with the Tao.

    1. Re:It's not that I want to brag I'm old... by TheRaven64 · · Score: 1

      Add to that, the defining feature of a functional language is the set of things that it disallows, not the set of things that it permits. A multi-paradigm language, by definition, has to permit anything that the various paradigms permit and so doesn't gain the benefits that you get from being able to reason about your code in a language that doesn't permit unconstrained mutability or side effects.

      --
      I am TheRaven on Soylent News
    2. Re:It's not that I want to brag I'm old... by michael_wojcik · · Score: 1

      functional programming is probably close to 50 years old

      It was 50 years old nine years ago.

      That's assuming you count from when a programming language with explicit functional constructs was introduced. Conceptually it goes back at least to lambda calculus.

      But certainly you're correct that the promotion of functional programming is not new. The earliest example that comes to my mind is Friedman's The Little Lisper, and that was published in 1974 (and is still in print). That's the first widely-circulated text I can think of that embodied the idea that functional programming is a different paradigm (though I don't think Friedman used that word) from procedural programming.

      So the bandwagon has been rolling for around 43 years.

  9. I do to an extent by reanjr · · Score: 2

    While I wouldn't want to program in a pure functional, no side effect language, a good mix of differing paradigms seems to me to be the way to go. Java and .NET went overboard on the OOP, and it leads to these poor abstractions in many cases (I.e. AbstractFooProcessor), which are much better approached with some FPd

    Pure functional code is super easy to reason about, though, especially asynchronous code. OOP has its role, but oftentimes you find yourself on loose footing, with its focus on always changing state. This can be addressed with good practices, which leads you down class hiearchy hell. Throwing some FP in the mix gives you (mostly) the best of both worlds.

    1. Re: I do to an extent by reanjr · · Score: 1

      You don't know what you're talking about. Just because a program has side effects does not mean the functions have side effects.

      f(S) = S'

      You pass in the current machine state, and you get back a new machine state. The original state is not modified. There are no side effects.

  10. It depends on the use by nanolith · · Score: 5, Insightful

    Functional programming languages like Haskell, ML, and Gallina can be very beautiful. The problem is that they have a steep learning curve that has less to do with the syntax of the language and more to do with the semantics. If one is well versed in category theory or has spent a significant amount of time working with functor spaces, monoids, and monads, then it's much easier to understand a non-trivial application written in Haskell than the equivalent object hierarchy in an object-oriented language. The up-front cost is greater in terms of study and learning the semantics, but the end result is significantly more powerful.

    I love functional programming. I went from C++ to Haskell and C as my go-to languages for personal projects. However, in my professional work, I tend to factor long-term language popularity into my decisions. So, I'm more inclined to use languages like Java, C#, Go, Python, and Ruby when I'm paid to write software. I have to consider the total cost of ownership in my professional work, and part of that cost is finding people to maintain it years from now.

    I think that FP has an elegance that makes it a worthy model, and I hope that some day, FP becomes more popular than OOP. But, I'm old enough to understand that technical superiority rarely wins out to popularity. Popularity matters. This sort of calculus is one of the reasons why FP has not gained much traction despite all of the buzz.

    1. Re:It depends on the use by Pseudonym · · Score: 1

      If one is well versed in category theory or has spent a significant amount of time working with functor spaces, monoids, and monads, then it's much easier to understand a non-trivial application written in Haskell than the equivalent object hierarchy in an object-oriented language. The up-front cost is greater in terms of study and learning the semantics, but the end result is significantly more powerful.

      I strongly suspect (but can't yet prove) that the supposed up-front cost in understanding Milner-esque functional languages is just the same as the up-front costs for Simula-style object oriented languages. The difference is that in the case of Simula-style object oriented languages, most of the up-front cost has already been largely paid by the time you come to them.

      If it's any help, consider that there seems to be a significant learning cost in wrapping your brain around "real" object-oriented languages such as Smalltalk when coming from "broken Simula" object-oriented languages such as Python or C++.

      We teach set/function theory and basic logic to high school students. It shouldn't be that much harder to make the very small amount of generalisation to explain the fundamentals of a modern logic-based type system.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    2. Re:It depends on the use by nanolith · · Score: 4, Interesting

      I don't disagree with your assessment. However, if your assessment is valid, then a functional language is still going to be quite foreign to someone who has only been taught object-oriented programming. I agree that we can go deep down the rabbit hole with OOP as well. The minimal interface that has been extracted from the science behind OOP and introduced to programmers in general is a mere shadow of the works of folks like Barbara Liskov.

      FP has yet to have this generational winnowing. It is still fresh and academic. We can build people up to understand this, or we can pull these concepts down to their most basic versions that are still useful. I suspect that both will have to happen before the industry can meet in the middle with FP. We are seeing this happen already as mainstream languages are adopting bits and pieces of functional concepts. I think it's more likely that we will see functional applications of OOP, such as in languages like Scala, than OOP superseded by FP. That's okay. There are already plenty of examples of non-mutable objects with copy-on-write semantics. We are seeing functions treated more and more like first-class objects. There are examples of the FP-as-style movement taking off.

      I believe that we should teach higher math in high school and even as a requirement for engineering or information systems disciplines. Currently, most universities top out bachelor degree seeking students specializing in these disciplines to calculus, differential equations, and linear algebra if they are lucky. It would be nice to see abstract algebra and some category theory taught as well. When I advise people genuinely interested in pursuing software development as a career, I strongly recommend that they minor in mathematics so they can have the opportunity to take these more advanced classes.

      That being said, there's nothing that prevents people from studying this for self-improvement. Learning either or both OOP and FP will fundamentally change the way that one organizes software. I'd love to see high school kids exposed to these concepts and the mathematics behind them. Then again, I'd also love to see high school kids taught how to build their own CPUs from 74-series logic ICs. Understanding the theory of computation at an intuitive level will do incalculable good for most of these kids through the rest of their careers. If I were to teach a class to high school level students, it would be along this line. I can guarantee that they will never look at a computer, embedded device, or "smart" device the same way again.

    3. Re:It depends on the use by jbolden · · Score: 1

      FP is already more popular than OOP. The world's most popular programming language (Excel) is functional. Think of a spreadsheet as just a bunch of out of order function definitions...

    4. Re:It depends on the use by vtcodger · · Score: 2, Funny

      "The world's most popular programming language (Excel) is functional"

      Is that intended to be an argument in FAVOR of FP?

      --
      You can't see ANYTHING from a car, You've got to get out of the goddamned contraption and walk...Edward Abbey
    5. Re:It depends on the use by jbolden · · Score: 1

      Yes. I think it counters the "functional programming is too hard to learn for most people" argument fairly well. It shows an example of a functional programming language that lots of low skill developers (i.e. general office workers) use quite comfortably. There are of course more interesting functional languages but because they are more interesting they require more learning.

    6. Re:It depends on the use by hajile · · Score: 1
      You may have a point about Haskell, but not about ML. Further, SML basically gets everything right that Haskell gets wrong.

      SML isn't lazy. Humans don't think in terms of lazy evaluation. Even though Haskell is much more popular and has much better tools, MLton will usually compile faster code.

      SML allows side effects. Haskell talks about purity, but the presence and reliance on unsafePerformIO shows that purity has limits. The practical answer is to write without side effects then add them to designated parts of the codebase which gets you most of the benefits of purity without all the overhead and headaches for the last 5% of your program.

      SML is immutable by default, but allows mutation if needed. Making everything immutable is great for some problems (eg, concurrency), but is generally bad for performance (determining when in-place mutation can occur instead of a new allocation is a hard, branchy problem).

      The biggest question is why SML isn't ruling the world. Consider golang vs SML. SML is about as fast, has a similar concurrency model in CML extensions, has a much better type system, and has much more simple syntax (despite being a more powerful syntax). Golang is used because the tooling is very nice, but why did Google choose to pour resources into golang (or even make it in the first place) when a better solution exists? Because familiar beats everything.

      In schools where SML is taught as a first language, nobody has problems learning it (compared to imperative languages). A lot of such people I've talked to even prefer the syntax. Most schools teach a language with a C-derived syntax and approach, so those devs learn to prefer that (and usually never even see ML-style syntax). Haskell has issues with popularity because of complexity. SML has issues with popularity because "popularity begets popularity".

    7. Re:It depends on the use by vtcodger · · Score: 1

      Maybe. But in my experience, Excel spreadsheets tend to be slow, clunky and, most annoying, very buggy. I don't think those are admirable characteristics. Nor do I think those problems are essential to the FP paradigm.

      AFAICS, the principle value of non-trivial spreadsheets is the ability Excel, Oocalc, etc to generate pretty graphs for presentation purposes with less aggravation than other alternatives. And, I guess maybe under some circumstances a spreadsheet is a viable alternative to a small database.

      --
      You can't see ANYTHING from a car, You've got to get out of the goddamned contraption and walk...Edward Abbey
    8. Re:It depends on the use by jbolden · · Score: 1

      ML is a cool language. I don't agree with you that SML issues are driven by lack of popularity. I think the problem was premature specification (essentially the same thing that happened to Common LISP). The spec requires consensus to change and thus SML stagnated. Others in the ML family like F# continue to good work SML started. Arbitrary length integer operations, expression type declaration, string formatting, translations, string joining... Those and many more are real issues.

  11. Wrong question by gweihir · · Score: 3, Insightful

    The right question would be "Do you understand functional programming?". And when you see about 99% of all "coders" having no clue, then you could ask the rest why they invested the time.

    --
    Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
    1. Re:Wrong question by bzipitidoo · · Score: 2

      A more basic question: "Do you understand recursion?" Lot of programmers really struggle with recursion, and avoid it like the plague. A common mistake is thinking that exiting the function means exactly that, rather than exiting only the current invocation of the function.

      --
      Intellectual Property is a monopolistic, selfish, and defective concept. It is "tyranny over the mind of man"
    2. Re:Wrong question by gweihir · · Score: 1

      Ah, yes. Lots struggle even with basic concepts of coding. Sad, but true.

      --
      Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
    3. Re:Wrong question by lgw · · Score: 1

      "To understand recursion in programming, first we must discuss recursion in programming".

      To understand recursion, first we must understand recursion, and then we must understand tail recursion.

      To understand recursion, we must incrementally increase our understanding of primitive recursion.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    4. Re:Wrong question by gweihir · · Score: 1

      Well, first, you can often do it "rolled out" and with no per-level storage. You would need to document that you actually do recursion, just optimized for stack usage. But that is for cases where this (complicated) implementation is still easier to understand than a conceptually iterative one.

      But second, I do agree. Stack usage is something any real coder needs to understand. Unfortunately, the modern stuff most people know exclusively (Java, modern scripting) hides that and as soon as such people do run into memory constraints they have no clue what happened and are completely lost.

      --
      Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
    5. Re:Wrong question by gweihir · · Score: 1

      Recursion is not about performance. In fact, any recursive program can be made faster by transforming it to iterative form and good compilers actually offer that as optimization. Recursion is about simplicity of the code, which in turn is about reliability, maintainability and security.

      --
      Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
  12. Re:My answer by ewibble · · Score: 3, Interesting

    yes,

    OK a bit more detail, there are advantage to not having state, or at least making the system deal with it it lead to some really elegant code.

    Just like most languages it has it limits, mainly input and output.

    I have used haskell and I think it has some really good concepts but is plagued by people using being to terse and cryptic, 1 character names for types are not good yes you can work out what it is doing but you shouldn't have to, and the use of random definable operator like '' makes it unreadable without a reference manual for beginners. A part of good code is being clear, being cleaver isn't usually as important as being understandable. At least the uses I have seen generally been quite cryptic.

    If the haskel community want haskel to popular they should make an better effort to make it more understandable.

  13. What is functional programming? by corporate+zombie · · Score: 4, Interesting

    Wow. Really?

    Functional programming.

    1. Prefer non-mutable data. No more action at a distance bugs. Hand off a reference to your data structure and don't have to care. Replay any data transform at any point as a unique structure.
    2. Prefer a defined and well known API often involving transforms that take a function as an argument to provide the predicate (e.g., filter), transform (e.g., map), aggregation (e.g., foldLeft/Right), or whatever building block.
    3. Prefer data structures that you can reason about based on a well-known set of patterns. (Best quote ever: "You say `patterns' and everyone is warm and fuzzy. You say `monad' and every loses their f-ing minds.)

    Given (2) in a language you'll often see in a language that functions are first-class data.

    Functional programming is just (a set of) best-practices. It's scary when the big words are new. Once you use it a bit you'll wonder why when you say, "use a flatMap", folks freak out because all you've said is, "You are transforming the elements of some container into values that are themselves an instance of the same container but you want to flatten everything back from nested containers. [E.g., Container is C with element type A; thus C[A]. You've run a transform that will create C[C[A]] but want to end up with C[A] at the end]." Now you could say that second part but that's a lot of words. Because of points (2) and (3) above we just say, "use a flatMap" (or however you spell `bind` in your language of choice).

    Nothing to see here. Please move along. (And yes. I like functional programming. A lot.)

    1. Re:What is functional programming? by mikaere · · Score: 2

      I'm a C# and BI developer I was paid to learn Clojure (a LISP) for a cloud-based contact centre platform project. I really liked it, but it did take me a while to get my head around the different patterns

      If you have a problem that can be solved using functional programming (e.g. operating on sets of data) then it can be a good choice. For example, I reckon it would be extremely useful in a business intelligence transformation layer.

      --
      It's good luck to be superstitious
  14. Drink the "kOOl-aid" by michael.karl.coleman · · Score: 2

    Not sure whether that was an intended pun or not, but I'm using it...

  15. I like functional aspects not functional languages by brian.stinar · · Score: 3, Informative

    I got my master's degree with this guy, and I had to take a Haskell course, or seminar, every semester. I was, and still am, pretty terrible at Haskell.

    However, what I attempted to learn helped my Python out a lot. Map and filter are two of my favorites, and the other functional paradigms are occasionally useful to me as an actually working, productive, programmer. I'm happy I was exposed to those concepts, since they tend to come in handy. Yes, everything is Turing complete, and you can accomplish the same things without functional programming, or without high level language, or without computers, but that doesn't mean they are all equally useful to solving the problem at hand.

    I recommend everyone become familiar with functional concepts in some way, if only to make them more well rounded. I don't advocate writing your next web application in Haskell though...

  16. Re:Moderate usage okay by west · · Score: 1

    I have a usage pattern where I end up pairing them with enums and it simplifies so many things (e.g. You practically never need a switch statement ever again).

    Care to share the pattern (or a reference)? I googled a bit, but there didn't seem to be one stand-out pattern and I'm quite curious (if you have the time)

    Thanks.

  17. Sure, why not... by ndykman · · Score: 1

    It's a very useful way of thinking about certain problems and it is often simpler that a lot of pattern heavy code. Take something like a template method. With functional programming just provide the functions to the method or instance. It accomplishes the same thing without an explosion of subclasses.

    There's a lot of other classic OO patterns that aren't needed or just done a lot more cleanly with higher order functions and other functional programming paradigms. It's also unfortunate that people assume functional programming is embodied in one language. Haskell is indeed a functional programming language (a highly opinionated one), but so is LISP and Scheme, which have completely different approaches.

    And FP paradigms are more and more common. List comprehensions in Python are just bog standard adoptions of map and filter higher order functions from functional programming.

  18. Has its uses. by RedMage · · Score: 1

    Not a panacea by any means. Sometimes it's harder to apply to general business programming in a meaningful and useful way - immutable objects aren't necessarily the best fit for data objects, to my mind anyway. Applied correctly and maybe less-than-completely the patterns and thinking from functional programming can be a good thing - but I'm not really a fan of pure functional programming and prefer the hybrid approaches like Scala.

    --
    }#q NO CARRIER
    1. Re:Has its uses. by angel'o'sphere · · Score: 1

      While you are right "immutable objects aren't necessarily the best fit for data objects", however they often are the simplest approach.

      Just think about "rewriting" a single threaded application into a multithreaded one. It helps imensly to have a clear understanding which data is immutal and which is not.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  19. Re:I like functions... by mrchaotica · · Score: 3, Insightful

    Yes, it means your functions aren't allowed to have side effects (i.e., all parameters are passed by value and the only result is the value returned to the caller).

    Personally, I like it because it's a good way to manage complexity -- kind of like the encapsulation of object-oriented programming, except applied to the verbs instead of the nouns.

    --

    "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

  20. The worst thing about function programming by OrangeTide · · Score: 1

    Are the people who won't stop talking about it.

    --
    “Common sense is not so common.” — Voltaire
  21. Yes, I like functional programming. But like most other things, it depends on the problem you're trying to solve. If you mosty deal with nails, you'll want to use a hammer. If you mostly deal with screws, you'll want to use a screwdriver. Hammers make lousy screwdrivers and vice-versa.

    Functional languages are great for highly parallelized computation because well-behaved functions don't have side effects, and that eliminates entire classes of race condition and locking issues. Functional languages are also good for abstracting higher-order patterns, since you can manipulate data and other functions without having to care about their lower-level details. Specific functional languages like Scheme, where code and data share the same form, are great for creating custom syntactic structures and writing self-modifying code.

    If you aren't doing any of those types of things, then functional programming may seem pointless to you, and that's OK. But every developer should be aware of the tools available to them in case the day comes when they might benefit from using them.

  22. Do I like Functional Programming? by gawdonblue · · Score: 1

    Sometimes, but just like Object-Oriented Programming it sucks when it's used as The One Paradigm To Rule Them All.

    Preferences: Use OOP for GUI, and FSP (functional/structured programming) for services/backed. Use round pegs in round holes.

  23. immutability and no global state by dseleno · · Score: 1

    You can do a functional style of programming in just about any language, but using a true functional language brings you some added benefits.

    Immutable data and pure functions make reasoning about your application so much simpler because there is no external state. With the same input, your functions always produce the same output. Testing is easier, debugging is easier, designing is easier, refactoring is much easier.

    Another way to think of functional languages vs procedural, is describing to a computer how data moves through your program vs telling a computer what to do step-by-step.

  24. Re:Lots of claims are being made about it's virtue by OneHundredAndTen · · Score: 1

    A properly placed apostrophe has its virtues as well. it's means it is.

    Or it has.

    It's amazing that people that can learn dozens of languages all more complex than the previous can't seem to grasp the humble apostrophe.

    I violently agree. The rule is very simple: If you mean "it is" or "it has" then you can write "it's". Otherwise, it is "its". Why so many out there seem to be unable to comprehend such a simple idea is something deserving of a study.

  25. Functional is useful when not pure by PhrostyMcByte · · Score: 4, Insightful

    The best functional programming to me, is the kind being integrated into various primarily procedural languages. I use it daily in C# at work, and find it invaluable in performing complex transformations on data. Python, C#, etc. have the best of both worlds -- the choice to use whatever is best for your situation.

    I'll expand further, maybe to start an interesting conversation because I'm sure someone will disagree: purely- or mostly-functional languages are the original hype-driven languages. A lot of people say they're amazing, but don't actually do anything useful with them. Sure, some are making great apps with them, but they're clearly the exception. At the end of the day most of the people I've talked to who preach about how awesome their favorite functional language is have only gone skin-deep. Their experience is limited to the academic or experimental, and has never gone into the practical.

    The few times I've tried to really master these languages, I've been left with no epiphanies. I've found it extremely useful for some problems, like data processing mentioned above. But for most everything else, it doesn't get me anything useful. On some level it is nice having the flow of immutability -- it "feels" right, like you've discovered something special. The same way adding an extra layer of abstraction on top of something might feel. But when I'd look back on it and ask myself what I gained from having it, there's really very little to be found. It is, mostly, a dogma.

    1. Re:Functional is useful when not pure by OzJimbob · · Score: 1

      Yep. I like functional programming, but it's a tool. But then OO is just a tool as well. It's not suitable for everything, and attempting to apply OO principles to problems that don't really need them is just a waste of everyone's time, just as being forced into a functional pattern when it's not necessary is useless.

      I'm mostly familiar with functional programming in R, where it's an extremely useful part of the language, but you don't have to use it. But once you get used to it, loops end up looking like ugly, clunky constructions when you could just apply a function of a vector. Once you're in this mind-space, going back to language that actually require you to nest loops to get anything done feels annoying as hell.

      --
      -"I still believe in revolution; I just don't capitalize it anymore." - srini!
  26. There is no "The Only Way" by davidwr · · Score: 1

    But it should not be The Only Way to approach a program - unless you are Truly One with the Tao.

    Unless you are a total newbie who has only been exposed ot one tool, or a hypothentical/mytical code-master-of-all-code-masters who is "Truly One with the Tao," then you know there is no "Only [one reasonable] Way" to approach a program/problem, at least not one of any reasonable complexity.

    --
    Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
    1. Re:There is no "The Only Way" by lucm · · Score: 1

      there is no "Only [one reasonable] Way" to approach a program/problem, at least not one of any reasonable complexity.

      One day maybe you will think differently. After all, "what is appropriate for the Master is not appropriate for the novice."

      --
      lucm, indeed.
    2. Re:There is no "The Only Way" by micahraleigh · · Score: 1

      "Appropriate" is a glossy disguise for mediocrity.

  27. It is great, just don't make a religion out of it by jma05 · · Score: 3, Interesting

    All programming paradigms have useful abstractions to offer. Eventually, they will all come together. Object orientation is great, until one overdoes it in design pattern hell. Likewise with functional programming. There are great many ideas in academic programming languages that will be made more accessible and integrated into mainstream programming languages. Functional programming is a dead end only in the sense SmallTalk was a dead end. People may not use SmallTalk much today, but its ideas live on in nearly every language we use today. Functional programming is here to stay. It won't replace imperative and object-oriented programming, but will add to them.

    First and foremost, programming languages are for people, not computers. So if regular programmers who form the bulk of the workforce can't grok them, the languages need to be fixed, not people. Haskell is too hard for most. But it has many wonderful ideas that can be distilled into simpler forms and adopted and integrated elsewhere. Python got list comprehensions from it and perhaps the indentation.

    C# is absorbing some features and Java is doing that less elegantly. Scala is a good balance and has already established itself. But people still find the type system complicated. So there are attempts to bring forth a simpler Scala - Kotlin, Ceylon etc.

    We all agree that things like compact syntax, first order functions, lambdas, streams, type inference etc that functional languages pioneered, belong in every language. We still haven't sorted out how to make more advanced type systems, provability, strict programming without side effects etc more approachable. We should not need to have this much trouble explaining what a monad is or isn't. We'll get there, eventually.

  28. Re:Lots of claims are being made about it's virtue by davidwr · · Score: 1

    The rule is very simple: If you mean "it is" or "it has" then you can write "it's". Otherwise, it is "its".

    Unless you are using the word out of context: There are too many it's in this discussion, don't you think?

    --
    Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
  29. Performance .... anyone? by thesjaakspoiler · · Score: 1

    If a programming language is functional by design I can image that it will also be optimized as part of the development. But does anyone know what happens if functional programming concepts are added to a non-functional language? Is there also any performance merit besides enjoying the merits of functional languages as a user? Or does it have performance implications due to the non-functional nature of the language?

  30. I couldn't get past "how do you write a game"? by Jeremi · · Score: 5, Interesting

    When I was learning about functional programming in college, I got about as far as learning about the avoidance of side effects, at which point I started asking myself, "how would one write a video game in an FP language if you're not supposed to e.g. update the player's on-screen position in response to a keystroke"? The answer I got was to either generate an entire new game-state for each update (which seemed unwieldy), or work around the problem using monads, which admittedly I never really understood. I went back to procedural programming since that looked like the more straightforward way to implement the kinds of programs I wanted to write.

    My question now is, do people ever actually write video games using functional programming? And if so, how would an FP-based arcade-style video game realistically handle things like updating the state of the player and the monsters at 60fps, as the game progresses?

    --


    I don't care if it's 90,000 hectares. That lake was not my doing.
    1. Re: I couldn't get past "how do you write a game"? by tigersha · · Score: 1

      You just sketched the worst-case for FP, true. FP is bad for that scenario.

      But it is better at modelling the small state transitions in the objects themselves

      --
      The dangers of excessive individualism are nothing compared to the oppressiveness of excessive collectivism
    2. Re: I couldn't get past "how do you write a game"? by Anonymous Coward · · Score: 1

      All cases are worst-case for functional programming. It's a retarded paradigm that gives turbo-nerd techno-weenies something to jerk off to and feel better about themselves over. You say "modeling the small state transitions blah blah" and I say "I just want the goddamn program to work." I don't give two shits about modeling object transitions or anything else. I want to write a series of directions for my computer to perform a task: "get input, check input, take actions based on input and current program state." There is no need for all this extra complexity and "elegance." Learn C. Never look back. If C is too hard, it should probably just be a shell script.

    3. Re:I couldn't get past "how do you write a game"? by phantomfive · · Score: 2

      I would do it by making a function something like, newGameStateScreen() which is a function of the old screen, and the current state (maybe even the old state). That part is fine enough.

      Then I would cheat and optimize it to actually update in place. Conceptually it would still be functional, but every useful functional program ever written mutates state.

      But if you have FP, then you have repeatability. Given a particular game state, combined with a given input, you can know what the next game state will be, every time. It's testable, provable, and helps you make sure that every possibility is covered.

      --
      "First they came for the slanderers and i said nothing."
    4. Re:I couldn't get past "how do you write a game"? by jbolden · · Score: 2

      Functional reactive programming came out of the functional community. Assume you had an array of all the inputs the end user entered for a game that already happened. Then the engine can create an array of all the corresponding outputs. That's your engine. Now wrap the construction of those two arrays in a stateful monad (IO).

      This book ( https://www.amazon.com/Haskell... ) is out of date but it will teach the ideas well. You'll create a video game and a music player.

      In general though, no video games don't generally get written in functional languages they are too messy and stateful. Video game engines though can easily be written in functional languages.

    5. Re:I couldn't get past "how do you write a game"? by Dutch+Gun · · Score: 3, Insightful

      As a professional videogame programmer, I can assure you that I haven't heard functional programming discussed much at work or among other peers in the industry. Videogames are giant, data-intense state machines, with lots and lots of state to track and manage. My feeling is that it's really not a great fit for functional programming. Traditional object-oriented programming is *heavily* used (C++ is the defacto industry standard language), because that's a reasonable and proven way to encapsulate complex, independently-operating entities into well-behaved packages of data + code.

      It's the same reason that the industry doesn't extensively use unit testing for engines and game code (not broadly at least), which may surprise some programmers in other fields. The reason is simple: many game engine tasks can't be boiled down into simple algorithmic data transformations that can be checked and verified by a simple function. For instance, how would one write a unit test to ensure audio is playing correctly, or a graphic shader is working as intended, or a physics engine "looks" correct in realtime interactions? It's not really practical. Thus, videogames tend to rely on integration tests using QA team members to spot anomalies.

      In short, not every programming paradigm can be effectively applied to every problem. That's not to say you *couldn't* write a game purely in a functional language, of course. I just don't think you'd be working to FP strengths.

      --
      Irony: Agile development has too much intertia to be abandoned now.
    6. Re: I couldn't get past "how do you write a game"? by Anonymous Coward · · Score: 1

      The idea is to seperate purely functional code from code that needs states. I/O, by definition, need states. Efficient data structures also need mutability. Most of the remaining stuff does not need either, but we tend to use states and mutations for everything anyway. Functional composition is a powerful tool, even without first class functions. FP is useful, if understanding it helps you to get rid of unneeded states in any code, and using composition of functions when designing your program, in any language.
      FP with something like Haskell is really cumbersome if your code has higher proportion of manipulating state code than actually doing computation (rarely the case) or that your computation requires mutability for performance (usually the case.)

    7. Re:I couldn't get past "how do you write a game"? by Gorobei · · Score: 1

      Well, you could read Anthony Courtney's Yampa Arcade paper: it describes the implementation of an arcade game in a functional system.

    8. Re:I couldn't get past "how do you write a game"? by zifn4b · · Score: 1

      As a professional videogame programmer, I can assure you that I haven't heard functional programming discussed much at work or among other peers in the industry. Videogames are giant, data-intense state machines, with lots and lots of state to track and manage. My feeling is that it's really not a great fit for functional programming.

      This is complete nonsense. It doesn't have to be ALL object oriented programming or functional programming. First of all, Mr. high and mighty C++ programmer, have you heard of Boost? Boost has some functional programming semantics and they are quite useful. C++11 even has freaking lambdas now! Or perhaps you've heard of lodash that can be used in conjunction with nodeJS or javascript. C# has functional programming syntax using lambdas. Geesh, this isn't a contest for the one programming language/style to rule them all anymore. If you still think that, it's probably time for you to retire.

      --
      We'll make great pets
    9. Re:I couldn't get past "how do you write a game"? by ripvlan · · Score: 1

      Microsoft created a game on XBox using F#. So it is possible. There's an F# compatible release of XNA. I can't remember the game - maybe "Go" ?

      Hunt in DotNetRocks for the topic - there have been multiple episodes over the years discussing this. Google "XBox F#" - there's a slideshare on the topic.

  31. Re:Tools are tools by Pseudonym · · Score: 1

    Asking whether you like functional programming is like asking whether you like phillips head screwdrivers.

    I do not. Give me JIS screwdrivers any day.

    --
    sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
  32. Re:It is great, just don't make a religion out of by Pseudonym · · Score: 1

    So if regular programmers who form the bulk of the workforce can't grok them, the languages need to be fixed, not people.

    I know what you're saying, but there's a real danger here that the industry will find itself caught in a local extremum. An engineer of 1880 could easily have said that if regular engineers who form the bulk of the workforce can't understand this "electricity", then it needs to be fixed to conform to the world of steam.

    The worst thing we can do as an industry is think we know what we're doing. And in a sense, we're already there.

    --
    sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
  33. Re: My answer by nasch · · Score: 1

    I don't think Iranian is a language.

  34. Re:My answer by slickwillie · · Score: 1

    "being cleaver"

    Beaver? I told you not to hang around with the Eddie Haskell.

  35. Re:I like functions... by __aaclcg7560 · · Score: 1

    Yes, it means your functions aren't allowed to have side effects (i.e., all parameters are passed by value and the only result is the value returned to the caller).

    I generally program that way in Python. I'll have to add functional programming language to my bucket list.

  36. you mean like lambda calculus, sonny? by retiarius · · Score: 1

    emil post's rewriting systems were tres reserche, too.
    and mccarthy's "lots of tiny parentheses", as well.

  37. Re:Tools are tools by lucm · · Score: 1

    Asking whether you like functional programming is like asking whether you like phillips head screwdrivers.

    I do not. Give me JIS screwdrivers any day.

    If you like JIS, you like Phillips. If you like Phillips, you may not like JIS. It's like rectangles and squares.

    --
    lucm, indeed.
  38. Didn't Like It At First by Philotomy · · Score: 1

    I didn't like functional programming at first, but after using it for a while I started seeing the benefits of things like first class functions and immutable state. Even if you don't think functional programming is a silver bullet, it's worth learning and understanding how the functional approach differs in solving programming problems. Adding another way to think about programming problems to your arsenal isn't a bad thing.

  39. Functional Programming Considered Harmful by doom · · Score: 4, Funny

    I tried a websearch the other day on "functional programming considered harmful" and found remarkably few hits. If anyone is so inspired, there's an opportunity there to gain some fame while earning the emnity of the hordes of javascript kids and half of the Computer Science digirati.

    1. Re:Functional Programming Considered Harmful by dgatwood · · Score: 4, Interesting

      It needs to be done and done well. Very tempting. But alas, just like drug use, there's only so much any sane person can write about the subject, because anyone who knows functional programming well enough to fully explain why it is harmful is probably mentally damaged beyond the point of being able to understand why it is harmful. :-D

      The thing is, functional programming is a good paradigm for students to be exposed to in school. Briefly. It forces you to think about data flow through your program, and forces you to think about your software as a giant state machine and visualize how the states change as your software does work. It is not the only way to teach that concept, but it is a halfway decent way. And once you pick up those concepts, you'll start to understand why singletons are so useful (approximately the polar opposite of functional programming, but often the software equivalent of the data you'd be passing around in a functional world).

      So basically, there's a time and a place for everything, and it's called college. But just like with drugs, if you continue to do significant amounts of functional programming after that, don't be surprised if the rest of us ask what you're smoking. Functional programming as a real-world paradigm tends to be almost invariably a disaster, because it neither fits the way we think about problems (human thinking is almost entirely procedural) nor the way machines do work (computers are inherently procedural). It can provide useful extensions to procedural programming languages that serve specific purposes (e.g. closures), but calling functional programming useful for that reason is akin to calling a diesel-electric freight train a perfect commuter car that saves fuel because a Prius is also hybrid hydrocarbon-electric.

      About the only space where functional programming techniques might really make sense is when working in a massively multithreaded environment, e.g. creating really efficient implementations of certain massively parallelizable functions (such as FFTs). But for the most part, that functional programming is limited to creating components that are then utilized as small (but performance-critical) parts in what is otherwise on the whole still procedural (or OO) software.

      Outside of those very limited scopes, though, the theoretically ivory-tower-pure, zero-side-effect functional programming model is pure garbage. Real world systems don't just have side effects; they are side effects, whether you're talking about storing data on disk, sending it over a wire, drawing it on the screen, reading data from a keyboard, or whatever. The notion of treating all of those "side effects" as some giant state object that mutates as it gets passed around is fundamentally antithetical to real-world use of the data, because state must be stored to be useful. And the entire notion of passing around the complete state of real-world software is so far beyond infeasible that the concept is utterly laughable. Cell phones have a gigabyte of RAM, not a petabyte. There's simply no way to write something like MS Word in a pure functional language, because it would take all the computing resources on the planet to barely run a single instance of it.

      Using functional programming in most real-world environments, then, cannot possibly do anything but cause brain damage, because the whole functional paradigm is wrong for the problem space. It is like cutting the grass on a football field using only a single pair of nail clippers—theoretically possible, but completely infeasible. To that end, although I wouldn't say that functional programming is inherently considered harmful, it should be approached with approximately the same level of skepticism as goto statements, and for approximately the same reason. When used correctly, in a very limited way, it is a powerful tool to have in your toolbox that can seriously improve your software. When overused or misused, it is a black hole that consumes infinite amounts of programmer time while emitting very little.

      --

      Check out my sci-fi/humor trilogy at PatriotsBooks.

    2. Re:Functional Programming Considered Harmful by Algan · · Score: 1

      Funny, I've been using functional languages for the past 10 years to put out successful commercial products and didn't even know it was supposed to be impossible. Now I am afraid I must be brain damaged.... or smoking some very good shit.

      --
      If con is the opposite of pro, is Congress the opposite of progress?
    3. Re:Functional Programming Considered Harmful by jbolden · · Score: 1

      What you are describing is not remotely how state is handled in functional languages today. What's done is there is a stateful monad (either State, Read, Writer, IO or State&IO) which allows for an imperative style language. That imperative language handles stateful objects and makes function calls to an engine. The engine is stateless. No one is passing around the entire state of the world.

      Here is a classic paper from a quarter century ago that summarizes this approach: https://www.microsoft.com/en-u...

    4. Re:Functional Programming Considered Harmful by Tablizer · · Score: 1

      I tried a websearch the other day on "functional programming considered harmful" and found remarkably few hits...

      That's old-school. Try searching "Functional Programming Sucks". Most won't know about the "considered harmful" reference when issuing criticism.

      (By the way, they never objectively proved goto's are "harmful". Their model is merely an assumption about how human programmer brains work. I don't necessarily entirely disagree with the model, but it's never been scientifically validated.)

      I've had heated debates at the c2.com wiki (now half-defunct) with FP fanboys. I will agree there may be legitimate niches, but the value of it is greatly over-hyped as a general-purpose technique. As I've stated elsewhere in this topic, most "realistic" examples are a result of comparisons to bad API's and/or languages. They are often defending FP against strawmen.

    5. Re:Functional Programming Considered Harmful by Tablizer · · Score: 1

      I've been using functional languages for the past 10 years to put out successful commercial products and didn't even know it was supposed to be [problematic as described]

      The real test is when you leave that company and somebody else has to read and maintain your code.

      If I wrote my code using just my favorite paradigms and techniques, it would probably kill the future maintainer.

    6. Re:Functional Programming Considered Harmful by doom · · Score: 1

      ... it's never been scientifically validated

      Wait. You don't expect a Computer Scientist to get experimental results, do you? What do you think they are, scientists?

    7. Re:Functional Programming Considered Harmful by Tablizer · · Score: 1

      "Computer Science" is indeed not really computer science. It's math + speculation. It should be renamed to "computology": the study of computers and computations.

    8. Re:Functional Programming Considered Harmful by doom · · Score: 1

      They're not really up to the Computology level yet, they should start out with Computonetics.

    9. Re:Functional Programming Considered Harmful by Tablizer · · Score: 1

      If you work on Chevies when everyone else is working on Fords, then you may have difficulty finding mechanics for your customized Chevies. I've yet to see evidence FP is objectively "better" in enough circumstances and niches to justify narrowing staffing options except for certain specialties. (I've complained about lack of practical demonstrations elsewhere on this story.)

  40. ML - it just worked! by Flu · · Score: 1

    The only time I've tried functional programming was during a class at the Uni. My memory from that class, was that when I finally got a progam through the compiler, it simply worked. No flaws or bugs at all. Of course, a single class doesn't make me qualified to neither promote nor dismiss it. Having said that, I prefer Python for simple PC-based tasks, C (or the non-obscure parts of C++ if the resources permits) for my daily work as embedded designer on ARM Cortex-M and smaller MCU's.

    1. Re:ML - it just worked! by elfprince13 · · Score: 1

      Seriously, I've written multihundred LoC Scala programs at a go before, and when they compiled, they worked (and I was typing them in Scala IDE, so they compiled as soon as I was done typing, because it does the type-checking in real time). It's almost disappointing when you think of a lot of clever error messages for bugs that never materialize.

  41. The Haskell people are all over this already by Anonymous Coward · · Score: 1, Informative

    https://wiki.haskell.org/Game_Development

  42. Re:Functional programming is trendy hipster garbag by brantondaveperson · · Score: 3, Insightful

    Programming is about translating what you want a computer to do into a set of instructions that the computer understands that mean the same thing.

    That is half of what programming is, at most. The other half is, at least, making that set of instructions easily understandable by another human being. Your code will be read thousands more times than it is written, and readability is far more important than your statement suggests.

  43. Most Things Have Their Place by NicknameUnavailable · · Score: 1

    Anyone who is all for functional, OO, actor-model, etc programming is incompetent. Different paradigms work in different scenarios and being a good programmer is mostly about knowing what to use when/where.

  44. Re:Lots of claims are being made about it's virtue by dgatwood · · Score: 1

    For that to be even ostensibly correct, you're missing one single quote mark and some double quotes, e.g.

    "There are to many 'it's, don't you think?" he said.

    And even that is arguable, because those aren't really apostrophes; they just happen to use the same key on the keyboard, typically.

    With only two exceptions, the plural of any word is always spelled with an 's', not an apostrophe followed by an s. The exceptions are:

    • The plural of a lowercase letter (e.g. there are too many i's here).
    • The plural of an abbreviation that contains periods or mixed case (e.g. there are too many Ph.D.'s here).

    And even then, those exceptions might depend on what style guide you go by.

    --

    Check out my sci-fi/humor trilogy at PatriotsBooks.

  45. Clipper (no, not the chip) by chthon · · Score: 1

    My first encounter with both OO and functional programming was Clipper 5.0, the dBase compiler. It incorporated parts of OO and parts of functional programming, lambdas actually, called code blocks. Both have their uses.

  46. Scala and Scala.js by trenobus · · Score: 1

    I started using Scala in 2011. The tooling was very rough at first, but I really liked the language as an alternative to Java. Since then I've adopted a progressively more functional style in Scala, and found it to be a very natural way to think about code. Some of my code is multi-threaded, and using immutable data structures, I find I spend a lot less time worrying about locking. And the tooling is now fairly reasonable in my opinion. Scala's interoperability with Java was a big selling point in the early days, but the Scala ecosystem is now getting to the point where it stands on its own rather well.

    A really great development in the Scala world is Scala.js, which transpiles Scala to JavaScript. I despise JavaScript for any development larger than a page of code, so Scala.js was a welcome relief. If you work on large JavaScript apps, do yourself a favor and check out Scala.js. I look forward to the day when WebAssembly matures enough to be a target for Scala compilation. Hopefully then JavaScript will fade away, and someday it will just seem like a bad dream.

    1. Re:Scala and Scala.js by Philotomy · · Score: 1

      Thanks for the info about Scala.js; I wasn't up-to-speed on that. I tried out Scala around the same time you started (i.e., 2011), and was impressed (Scala provided my introduction to functional programming concepts). Unfortunately, I never had the opportunity to use Scala, much, and I lost track of what is going on with it. These days I'm working with a lot more JavaScript. I don't mind it (it's not bad if you use ES2015/Babel and avoid iffy parts of the language), but it can be pain on larger team projects with developers of mixed experience with JavaScript. Anyway, the Scala.js project sounds like it's something I'd like to check out.

  47. Realistic examples missing by Tablizer · · Score: 1

    I've yet to see realistic examples of improvements, at least for domains I work in. Those pushing FP either invent contrived "lab toy" circumstances where FP shines, use vague buzzwords that don't describe any concrete benefit, or merely expose the weakness of a particular language or API design (such as Java's poor OOP model).

    If you want to convince people, show them realistic examples and explain the benefits in concrete and measurable terms. Is that asking too much?

    They may say, "If you use it long enough, you'll finally get it"; but there are so many tools and ideas competing for our time that I'll have to ask for more up-front evidence, if you don't mind.

    1. Re:Realistic examples missing by yes-but-no · · Score: 1

      A seed planted yields fruit after a few months/years; it needs to be watered and cared for until it grows to that big tree. There are certain things in existence that can't be shown; you have to do it to see it happen to you. If someone hesitates to walk the path because of a lack of proof likely will miss a lot. As Morpheus says, there is a difference between knowing the path and walking the path. It's a about taking a leap of faith; not based on logic.

    2. Re:Realistic examples missing by Tablizer · · Score: 1

      Assuming that's true, there are 50 or so "great ideas" on my desk. I don't have time to try them all for an extended period of time. Why should I assume FP is more fruitful than the others?

      There are certain things in existence that can't be shown

      Bullshit! When I found benefits in something I was able to articulate and show realistic examples. Some of it turned out to be purely personal preference, but I say so if that's the case. My eyes and brain prefer certain things organized a certain way that doesn't always match other brains/eyes.

      If it cannot be shown objectively, something is probably wrong on the claimer's side. Sorry, I find "can't explain" an anti-scientific copout. You should study benefit articulation over a long period until you finally "get it". Touche!

    3. Re:Realistic examples missing by jbolden · · Score: 1

      The problem domains it shines in are niche: data parallelism, GPU programming, compiler construction. Those fields are dominated by functional languages.

    4. Re:Realistic examples missing by Tablizer · · Score: 1

      Regarding data parallelism: most rank-and-file big-scale data chomping is expected to be done by the database. For example, if you request "ORDER BY" in an SQL query, the database engine may indeed use parallelism under the hood to sort. But that's typically not a concern of the app developer or query writer. The DB engine builder worries about that. (It does help to know a bit about parallelism when considering query performance profiles.)

  48. Functional programming has its purpose by prefec2 · · Score: 1

    It is helpful in context of walking data model trees in OO languages. It also allows to write stateless code which supports parallelism. It helps with reactive systems including UIs and PLCs. It also sucks in some high performance areas. When people think Optional is a good idea to avoid if then else as code construct and replace it by function calls.

  49. Makes you think of data design more by yes-but-no · · Score: 2

    In my experience FP style (in python), makes me spend lot more time in the design phase. The emphasis is on data/data-structure more than the code/algorithm/operations [the spotlight of imperative languages]. You start thinking more about how your data gets transformed from input to output. I felt this way of separating data representation from the code/operation lead to more robust code; also much faster implementation phase. FP surely changes the way you think at a higher plane of the problem at hand.

  50. Re: I like programming that works by stridebird · · Score: 1

    A triple "it's" / "its" error in one sentence. Good work, AC.

  51. Two ideas by Boronx · · Score: 1

    I have found two ideas that came from Lisp that are invaluable.

    Minimize side effects in most functions. Any effort to reduce side effects will be repaid tenfold the next time you have to fix a bug or add a feature.

    Keep data objects immutable. This is the key to the easy life if you have to do concurrent programming (and who doesn't these days?).

  52. it's just another.... by SuperDre · · Score: 1

    It's just another framework we've had for ages..
    I see it with so many languages, all they do is add functions we already created in the past as standard options. It's really nothing new..
    A problem with a lot of newer frameworks, is that a developer doesn't have any idea anymore as how it actually works underneath, so if something doesn't work they can't figure out why as they don't have the understanding (doesn't mean you have to know all the ins and outs).
    Problem these days is, there are sooooo many frameworks, and everytime a new framework pops up it'll be a favorite for a while and then we all have to move over to the next new hip framework even if it doesn't actually add anything new to the previous one.

  53. Only 5 lines of code by Anonymous Coward · · Score: 1

    I love it how functional programming lovers show examples of a few lines of code and say "see i solved this difficult problem in just 5 lines of code". Then you ask what the other files are and they have written 10,000 lines of code for all the related functions.

    Yea abstracting is not something that only works in functional languages guys.

  54. In small doses by DrXym · · Score: 2
    Anonymous functions / closures / lambdas are fine for small snippets of code, e.g. iterating loops, firing timers, success / fail handlers etc. When you start nesting them or chaining them together with promises or similar constructs, then things can get really hairy.

    Try writing sets of asynchronous Jasmine tests that use promises, lodash iterators, success callbacks and other things of that nature arrays and madness swiftly follows.

  55. Re:My answer by Rockoon · · Score: 3, Interesting

    1 character names for types are not good

    Says who?

    All localized variables and types in my programs have 1-character names, and its for multiple good reasons including that because you can see that something is only 1 character at a glance, that therefore you know for sure that it doesnt have much if any outer scope with that very same glance.

    --
    "His name was James Damore."
  56. Re: My answer by Sique · · Score: 1

    The actual language is called farsi (new persian).

    --
    .sig: Sique *sigh*
  57. It's a fine enough paradigm, but... by bradley13 · · Score: 1

    Functional programming is a fine enough paradigm. It can be very educational to look at a problem from a different perspective? imperative, object-oriented, functional, logical, etc.. Hence, yes, functional programming is a very useful thing. I think every programmer should give functional programming a try.

    However: Mixing paradigms within a programming language makes code more difficult to understand, and generally leads to language bloat. It's worse, when the underlying language fundamentally cannot support the paradigm.

    Prime example: Java + Lambdas. Java does not support working with code the same way you work with data, which is what functional languages are all about. With reflection, Java allows limited inspection of functionality, but no manipulation. Java lambdas are a way of faking one aspect of functional programming: the ability to pass code as a parameter. However, you aren't actually passing code as a parameter. If you were, then you could alter the value of that parameter at runtime, like you can any other variable. Instead, you're just letting Java fill in some blanks at compile-time, because the interface you select has only one abstract method. This is syntactic sugar that kinda, sorta looks like functional programming, but actually isn't. As such, Java lambdas are a really stupid idea. Anyone who has used them thinks they've done functional programming, but they actually have not.

    --
    Enjoy life! This is not a dress rehearsal.
  58. Re:My answer by Hognoxious · · Score: 1

    being cleaver

    That's a cutting remark!

    --
    Confucius say, "Find worm in apple - bad. Find half a worm - worse."
  59. Functional Programming is a good thing. by Qbertino · · Score: 1

    So is knowing and understanding it.

    FP basically forces you to do multiple steps in one and trains your brain to think faster. Getting rid of state wherever possible is a neat thing too and enables more complex programms and routines that are less error-prone and more vertasile.

    As long as you can wrap your head around what your doing FP is great. I've made a habit of using it whenever I can. ... Although sometimes I'm just to lazy or tired and start wittling about with variables again.

    --
    We suffer more in our imagination than in reality. - Seneca
  60. I use it every day, but still use imperative too by RobinH · · Score: 1

    I maintain a large-ish enterprisey system, most of which is written in C#. I use the functional features of C# every day. However, I would caution you against lumping all functional features under a single heading of "functional programming" because you can look at each feature independently and decide whether you want to use it.

    For me, I definitely use immutability, both in combination with dependency injection for my service classes, but also in many of my data structures. For instance, I might have a module that pulls a bunch of state from the database and then organizes it into a projection, such as a forecast of material usage. That forecast is immutable. I then (optionally) have the ability to cache that either locally in the program, or cache it to the database, but when I bring it back it's still immutable, so that data with that ID never changes, and none of the consumers of that data need to worry about it changing. In some cases that means I can safely split the further processing of that data across multiple threads rather easily.

    Also, LINQ is really just a ripoff of Lisp's S-expressions, and I find it extremely useful. If I have a list of anything, and I need to manipulate it into another form, then LINQ allows me to do that without loops and with less complexity. I generally still use loops for modifying data.

    LINQ is really a combination of three features: 1) functions as first-class citizens, 2) lambda expressions/syntax, and 3) closures. These are very useful on their own. Being able to take a function as an argument is extremely powerful, and being able to define a function inline when you call that method, and have it capture values from outside that function in the form of a closure -- very powerful.

    That doesn't mean there isn't a use for imperative programming, but when I see a colleague filtering a list of objects with a foreach loop, I just cringe. Just use a .Where() clause! Don't be afraid of functional - use it as one more weapon in your arsenal.

    --
    "I have never let my schooling interfere with my education." - Mark Twain
  61. There is really no by silentcoder · · Score: 1

    fundamental difference between a map or an iterator in terms of how they execute.
    So the question becomes one of aesthetics - and that must, inevitably, have a subjective aspect to it. Those who love the functional approaches will find them more pleasing, those who prefer the OO approaches will prefer those instead.
    And some, like me, will mix and match them according to what looks better for the piece of code I'm currently writing - much as I choose between a for-loop or a list-compression based mostly on how long the list-compression is. Anything over about 60 characters and a for-loop is simply more readable and easier to debug.

    --
    Unicode killed the ASCII-art *
  62. Come on! We all know that... by MarcoPon · · Score: 1

    ... dysfunctional programming is way more used in the real world..

    --

    SeqBox
  63. I agree with Eric Lippert by billybiro · · Score: 1

    Eric Lippert, a former Microsoft employee and one of the main designers of the C# language and someone who understands and appreciates functional programming (having brought many functional paradigms to C# such as lambdas etc.) responded to the question "Why hasn't functional programming taken over yet?" on StackOverflow, which for me, sums up everything I feel about functional programming.

    I've quoted Eric's answer below, but the TL;DR is that I believe the future is neither purely functional, nor purely OO, but some hybrid of the two.

    Because all those advantages are also disadvantages.

    Stateless programs; No side effects
    Real-world programs are all about side effects and mutation. When the user presses a button it's because they want something to happen. When they type in something, they want that state to replace whatever state used to be there. When Jane Smith in accounting gets married and changes her name to Jane Jones, the database backing the business process that prints her paycheque had better be all about handling that sort of mutation. When you fire the machine gun at the alien, most people do not mentally model that as the construction of a new alien with fewer hit points; they model that as a mutation of an existing alien's properties.

    When the programming language concepts fundamentally work against the domain being modelled, it's hard to justify using that language.

    Concurrency; Plays extremely nice with the rising multi-core technology
    The problem is just pushed around. With immutable data structures you have cheap thread safety at the cost of possibly working with stale data. With mutable data structures you have the benefit of always working on fresh data at the cost of having to write complicated logic to keep the data consistent. It's not like one of those is obviously better than the other.

    Programs are usually shorter and in some cases easier to read
    Except in the cases where they are longer and harder to read. Learning how to read programs written in a functional style is a difficult skill; people seem to be much better at conceiving of programs as a series of steps to be followed, like a recipe, rather than as a series of calculations to be carried out.

    Productivity goes up (example: Erlang)
    Productivity has to go up a lot in order to justify the massive expense of hiring programmers who know how to program in a functional style.

    And remember, you don't want to throw away a working system; most programmers are not building new systems from scratch, but rather maintaining existing systems, most of which were built in non-functional languages. Imagine trying to justify that to shareholders. Why did you scrap your existing working payroll system to build a new one at the cost of millions of dollars? "Because functional programming is awesome" is unlikely to delight the shareholders.

    Imperative programming is a very old paradigm (as far as I know) and possibly not suitable for the 21th century
    Functional programming is very old too. I don't see how the age of the concept is relevant.

    Don't get me wrong. I love functional programming, I joined this team because I wanted to help bring concepts from functional programming into C#, and I think that programming in an immutable style is the way of the future. But there are enormous costs to programming in a functional style that can't simply be wished away. The shift towards a more functional style is going to happen slowly and gradually over a period of decades. And that's what it will be: a shift towards a more functional style, not a wholesale embracing of the purity and beauty of Haskell and the abandoning of C++.

    I build compilers for a living and we are definitely embracing a functional style for the next generation of compiler tools. That's because functional programming is fundamentally a good match for the sorts of problems we face. Our problems are all about taking in raw information -- string

  64. Re:I like functions... by vtcodger · · Score: 1

    I know squat about Functional Programming. But I'm told that Python's List (and generator) comprehensions are a functional programming concept. Input a list, perform an operation on all or part, and output an altered list. Not terribly readable IMO, but otherwise quite likeable. I find myself using them quite a lot.

    As for stuff like closures. The explanations I've read tend to be utterly opaque. Sort of like a color-blind individual trying to explain the color green. I'm not sure if the problem is me or the explainers. After a lot of reading, I think I sort of might understand how closures be done in Python. But it's sort of like reading about how to build a working mechanical arm out of toothpicks. Interesting, but I'll be damned if I can envision a situation where I might want to do that.

    --
    You can't see ANYTHING from a car, You've got to get out of the goddamned contraption and walk...Edward Abbey
  65. Poorly understood? by fyngyrz · · Score: 3, Interesting

    If you're using poor coders to maintain very old code then perhaps the choice of programming style is not your biggest problem.

    You may have misunderstood the previous poster's use of "poor coder."

    I read it as "unfortunate coder", not "incompetent coder."

    I could certainly be wrong. Perhaps clarification will be forthcoming.

    --
    I've fallen off your lawn, and I can't get up.
    1. Re:Poorly understood? by johannesg · · Score: 1

      The poor commenter shouldn't be blamed for his lack of understanding.

    2. Re:Poorly understood? by fyngyrz · · Score: 1

      Yes, said commenter clearly needs more money.

      --
      I've fallen off your lawn, and I can't get up.
  66. Fluid type manipulation with unions by fyngyrz · · Score: 2

    Would you consider unions in c a "means to circumvent the type system" as compared to a language with strong up-front typing?

    Unions are certainly a very powerful, useful, and concise tool for manipulating data across type boundaries. If you don't have them, in trying to accomplish similar tasks as those unions make easy, in many languages you're going to be a lot more verbose, and likely a lot less efficient, than if you do.

    I am assuming competence. Strong typing is a safety net. The need for such a thing varies with one's skill set. The fewer the participants, the more likely it is that the skill sets can be arranged to be similar. With larger teams, the need for safety nets almost always increases.

    --
    I've fallen off your lawn, and I can't get up.
    1. Re:Fluid type manipulation with unions by angel'o'sphere · · Score: 1

      Yeah,

      in Pascal and Modula 2 we had "case records", don't remember how they were named exactly.

      I used a union once or twice, but don't really remember why (I mean: for what purpose).

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    2. Re:Fluid type manipulation with unions by lgw · · Score: 1

      Skillful coding is writing code that's clear and easy to understand. Insufficient skill leaves one cheating, such as by using unions or "downcasting". From time to time I do such things, because I just can't find a simpler, more clear way without the cheating. But I always wish I could.

      Never be proud of writing obscure code.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    3. Re:Fluid type manipulation with unions by fyngyrz · · Score: 1

      Unions aren't the least bit obscure: they do very specific things, and just as you tell them to. It's a matter of skill. Not obscurity.

      For instance, in my 6809 emulation, with a register that is sometimes independent 8-bit and sometimes single 16-bit (the 8-bit A and B registers become the 16-bit D register, depending on the instruction in play), a union is just the thing. It does exactly what is needed, when needed, and not otherwise.

      --
      I've fallen off your lawn, and I can't get up.
    4. Re:Fluid type manipulation with unions by lgw · · Score: 1

      I'm afraid that "the 8-bit A and B registers become the 16-bit D register, depending on the instruction in play" is pretty much the essence of obscure legacy cruft. Granted, you're not making it worse in any way by representing it with a union.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    5. Re:Fluid type manipulation with unions by fyngyrz · · Score: 1

      Granted, you're not making it worse in any way by representing it with a union.

      More to the point, you can't make it better by avoiding using a union. Because it's optimum as is.

      The right tool for the right job.

      pretty much the essence of obscure legacy cruft.

      The job is the job. I have no problem using the right tool for the job.

      --
      I've fallen off your lawn, and I can't get up.
    6. Re:Fluid type manipulation with unions by lgw · · Score: 1

      Meh, I'd hope the optimizer was the right tool for the job. Any compiler worth a crap would know just what to do with
      uint8_t a = d >> 8;
      and that wouldn't rely on any undefined behavior (there's no standard way to directly manipulate registers in C, after all).

      --
      Socialism: a lie told by totalitarians and believed by fools.
    7. Re:Fluid type manipulation with unions by jeremyp · · Score: 1

      Yes, except that it is not portable. You'd need to arrange the 8 bit registers differently for big endian and little endian machines.

      This simple example illustrates why C style unions are a means to circumvent the type system and are dangerous to the unwary.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    8. Re:Fluid type manipulation with unions by jeremyp · · Score: 1

      He's emulating a 6809 which is pretty much a legacy processor by now. No amount t of you calling it cruft is going to stop the need for treating two eight bit registers as one 16 bit register because that is what the original hardware did. Same with the Z80 and the 8086.

      The problem with using a union to do it is the undefined behaviour.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
  67. function dictionaries in Python by fyngyrz · · Score: 1

    So, for example, by storing functions as values in a dict you can build complex structures of execution without using any conditional codes .

    This is the core mechanism of my text markup language. Once the specific built-in tokens are parsed out, they are immediately accessed via the language's function dictionary. This approach is quick, ultimately low-complexity, trivially extensible, and highly maintainable.

    --
    I've fallen off your lawn, and I can't get up.
    1. Re:function dictionaries in Python by silentcoder · · Score: 1

      Nice. I use the technique extensively in my code- it's elegant, easy to use, fast and powerful - I personally think it should be in every python coder's toolbox - but for implementing a lookup table for a markup language is one of the most elegant I've seen :) i will certainly be remembering this if I ever need to create a DSL again.

      --
      Unicode killed the ASCII-art *
  68. Unit testing FTW by fyngyrz · · Score: 1

    IMHO, unit testing is a far, far more important aspect of advancing programming in general than are lambdas. Just my 2c. :)

    --
    I've fallen off your lawn, and I can't get up.
  69. Hard stuff is, in fact, hard by fyngyrz · · Score: 5, Interesting

    I would add to this that reducing the complexity by turning everything into separate functions tends to also increase what I call "opacity by non-locality."

    Not only are some things hard, some things benefit from having the logic right there in front of your face; not in a header, not in some function elsewhere, not in a library.

    Benefits in both comprehension, and so ease of construction, but also in execution time and smaller executables depending on just how smart the language is in constructing its own executables.

    --
    I've fallen off your lawn, and I can't get up.
  70. structs and fundamental OO by fyngyrz · · Score: 3, Interesting

    Just having higher-order functions doesn't make a language a functional language any more than having structs makes C an object-oriented language.

    Structs do, however, make the critical aspects of an object oriented approach practical in c. They can carry data, function pointers, etc., and they can be passed around.

    I've been writing my c code like that since the 1980's. There are significant benefits.

    --
    I've fallen off your lawn, and I can't get up.
    1. Re:structs and fundamental OO by molarmass192 · · Score: 1

      Gotta agree with you here, structs are possibly the single most useful feature in C. Sure it's not "real" OO, but it's provides a nice way to encapsulate functionality and state, while providing "good enough" level of abstraction. I've even used anonymous structs to approximate inheritance a few times and polymorphism is the void ptrs cute looking cousin. The latter two I try to avoid because those are just begging to introduce hair pulling out types of bugs.

      --

      Good people do not need laws to tell them to act responsibly, while bad people will find a way around the laws-Plato
    2. Re:structs and fundamental OO by Tablizer · · Score: 1

      Structs do, however, make the critical aspects of an object oriented approach practical in c. They can carry data, function pointers, etc., and they can be passed around.

      You are just reinventing machine language where data, instructions, and address pointers can be mixed willy-nilly. Higher-level languages merely try to introduce discipline and consistency to such practices.

    3. Re:structs and fundamental OO by fyngyrz · · Score: 1

      You are just reinventing machine language where data, instructions, and address pointers can be mixed willy-nilly.

      Because machine language varies hugely, and c varies little or none, when working on one platform and then another, c is a convenient low-level way to get as many advantages of working close to the metal (obvious ones are speed and executable size) as possible.

      Higher-level languages merely try to introduce discipline and consistency to such practices.

      Yes, they do. And in the process, they often cause the resulting product to suffer in speed and/or execution size (and the source code in clarity.) When "mere" means "the product is less good", I translate it as "not mere."

      There are reasons to go one way or another. It's not as simple as "HLL's are always better." Sometimes even machine language is the best place to go, embedded controllers with limited storage and small tasks that must be accomplished efficiently, for instance.

      --
      I've fallen off your lawn, and I can't get up.
    4. Re:structs and fundamental OO by Tablizer · · Score: 1

      By "merely", I meant C (and HLL's) didn't originate the idea.

      I'm not sure what you mean by "less good". You seemed to agree there's a trade-off between optimizing for "machine" resources/time, and abstraction/discipline/consistency/clarity. "Good" would then be relative to needs, such as business requirements/goals.

  71. Sadly... by buddyglass · · Score: 1

    Where I work we only engage in dysfunctional programming.

  72. cars cons crap by fyngyrz · · Score: 2

    ((((((((((((I hate lisp too))))))))))

    --
    I've fallen off your lawn, and I can't get up.
  73. Isn't that the One with 20 Gazillion Brackets? by wisnoskij · · Score: 1

    I have never understood why the language is not considered a parody like the whitespace language. You cannot debug or change code when it is 90% brackets, and more than two to three ")))" brackets in a row and editing the nesting of something becomes really hard and error prone.
    A proper language tries to evenly distribute the character usage evenly over a wide array of characters, such that the code is easily readable.

    I have only seen a few examples in Scala, which replaced Java in my university the year after my class. But they were the least readable code snippets I have ever seen. It looked like they had replaced all the white space with brackets.

    --
    Troll is not a replacement for I disagree.
    1. Re:Isn't that the One with 20 Gazillion Brackets? by david_thornley · · Score: 1

      Writing Lisp without a parenthesis-aware editor is really painful. I tried that a few times. When you use an editor like Emacs (which I pretty much use only for Lisp), you don't keep track of the parentheses so much as the shape of the function you're writing or editing.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  74. For the most part, yes by zifn4b · · Score: 1

    I can write certain types of algorithms much faster specifically iterating arrays and associative arrays/dictionaries faster for the purposes of transforming data sets. Functional programming typically is more optimized than a do-it-yourself algorithm. No sense re-inventing the wheel if you don't have too.

    --
    We'll make great pets
  75. functional programming is ok by slashdice · · Score: 1

    what i don't like is functional programmers!

    --
    Copyright (c) 1990 - 2014 Dice. All rights reserved. Use of this comment is subject to certain Terms and Conditions.
  76. Re:Functional programming is trendy hipster garbag by zifn4b · · Score: 1

    Programming is about translating what you want a computer to do into a set of instructions that the computer understands that mean the same thing.

    That is half of what programming is, at most. The other half is, at least, making that set of instructions easily understandable by another human being. Your code will be read thousands more times than it is written, and readability is far more important than your statement suggests.

    Writing a website in assembly language is a very useful and pragmatic skill to have. In fact, I encourage those folks that can do it to put it on their resume and see how many job hits they get.

    --
    We'll make great pets
  77. Re:Lots of claims are being made about it's virtue by angel'o'sphere · · Score: 1

    Why so many out there seem to be unable to comprehend such a simple idea is something deserving of a study.

    Why are there so many people that can not comprehend that writers completely know the correct form of usage but STILL make simple TYPING MISTAKES!!
    And the damn typing mistake is not red underlined because it is a VALID WORD!

    And no: proof reading does not make me see such errors, as I'm a whole word or even "whole sentence" pattern match reader.

    (And in this text everything is red underlined because I can not make Windows 10 automatically detect the correct dictionary -- gosh this MS bullshit is so anoying ... my 20 year old Mac SE is better in EVERY regard than this windows nightmare)

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  78. Re:I like functions... by vtcodger · · Score: 1

    Here's a document that explains functional concepts in Python. Seems reasonable:to me.

    https://docs.python.org/2/howt...

    --
    You can't see ANYTHING from a car, You've got to get out of the goddamned contraption and walk...Edward Abbey
  79. It's All Soup by sycodon · · Score: 1

    I've seen many of these "paradigms" come and go.

    It's like someone coming up with a new way to make soup. New ingredients, new cooking methods, new ways to chop vegetables, new pots to put in in, blah blah blah.

    In the end, it takes about the same about of time, tastes pretty much the same, and only refrigerates so many times before you have to throw it out.

    --
    When Fascism comes to America, it will call itself Anti-Fascism, and tell you to give up your guns.
  80. Right time for functional programming by Dareth · · Score: 1

    Implementing functional programming needs to come at the right time for it to be effective. Until all of your programmers are following the internal style guide without exception, functional programming is not likely to take off. If people are still arguing over block style, forget getting them to agree on proper style for Lisp and the metric ton of braces.

    --

    I only look human.
    My mother is a halfling and my dad is an ogre, so that makes me an Ogreling
    1. Re:Right time for functional programming by jbolden · · Score: 1

      Mixed paradigm languages (like LISP) can be tough to have style guidelines. The purer functional languages enforce a functional style because bad code is a syntax error. You simply don't have syntax to break many of the rules. Haskell programmers often comment that getting a program with rich type definitions to compile is close to getting that program debugged.

      Also standardizing form is less important when the number of lines reduces drastically. Functional programming encourages a paradigm that if a program is long there is an abstraction missing and fix the problem that way.

    2. Re:Right time for functional programming by Dareth · · Score: 1

      "an abstraction missing and fix the problem that way"

      If you abstract a functional program enough, you can summarize it as:

      "MAGIC!"

      --

      I only look human.
      My mother is a halfling and my dad is an ogre, so that makes me an Ogreling
    3. Re:Right time for functional programming by jbolden · · Score: 1

      It can feel like magic. The abstractions are incredibly powerful and one line does a tremendous amount.

  81. Science not heresay by Mybrid · · Score: 1

    CS61A, or Introduction to Programming, is a flunk out/weed out class at UC Berkeley. It is taught in LISP and is functional programming. Why? Functional programming runs counter to the way the majority of people think. Science says that functional programming is demotivating for the general population. So, what do you do if you have way more students interested in Computer Science than you have slots available? Easy, just make them pass a functional programming course.

    CS61A is the only mandatory functional programming course at Berkeley. All other courses are in Java, C/C++, Python etc.

    The only question one needs to ask about a computer language is this: can the language exercise the full functionality of the target computer? If the answer is yes then all such languages are interchangeable and logically equivalent.

    Since scientifically speaking most people think in for/while loops and not function calls then procedural programming is the most common.

    What have we learned?

    1. A. If a language can exercise the full capability of the target computer than it is synonymous with any other such language in capability.
    2. B. Science has shown people are far more motivated by procedural programming than functional. For and while loops are more natural to how the mind works. Most people find functional programming an unnatural way to think and therefore do not like it.
  82. Javascript and Hacker News by Mybrid · · Score: 1

    Don't let Javascript and Hacker News fool you. Hacker News is predominantly a hang out for the functional programming crowd. This is a self selective audience. If you are not interested in functional programming then there is not a lot of content on Hacker News for developers.

    Javascript is a bloody mess, especially with the Nodejs. A bloody mess is not functional programming. For/while loops are for more prevalent in Javascript then functional programming. At issue is all the callbacks for async event handling. Javascript is very poorly designed software because unless your async code is wrapped in monitors it is not proper async code. Promises? Pick up any programming text book on async programming and it will always teach you to wrap your async code in monitors/semaphores/locks.

  83. FP not ready for prime time by hax4bux · · Score: 1

    I have a erlang team (over two years), and although it seems they work hard there is not much to show for it. Everything is written, then rewritten multiple times. Very ordinary things like web servers require extensive customization. Actually, lots of ordinary stuff requires custom implementation. The dogma and religious wars never end. It is difficult to staff qualified people. In short, many liabilities and it will be a long time before I sign up for another FP project.

  84. Re:I like functions... by swillden · · Score: 1

    Yes, it means your functions aren't allowed to have side effects (i.e., all parameters are passed by value and the only result is the value returned to the caller).

    It's quite a bit more than that, at least if you're talking about pure functional programming. You also have to get rid of most all of your old notions of flow control. Imperative programming is about defining sequences of steps, some of which are conditional. Functional programming is all done with nested transformations; there are no sequential steps, there are no branches, there is no iteration.

    If this sounds freakish and impossible to someone raised on imperative programming paradigms... yes, it is. Functional programming requires thinking in an entirely new way. It's a very powerful tool. I'm not sure it's the best tool for the systems I build (though I'm also not sure it isn't), but at a minimum it's a useful way to think about code construction. Every programmer should spend some time learning it.

    --
    Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  85. Too bad computers don't believe ifn FP. by thadtheman · · Score: 1

    At it's simplest. The first instruction of a function program executed, the PC register is changed and that's that. The state of the machine is changed. Claiming to be startelss is just a fictional abstraction. Moreover most programs are all about state ( eg. databases ). State is something that functional programmers have been trying hard to isolate for a long time, inventing such monstrosities as monads ( which BTW are easy to understand when you don't use category theory ). But I would really like to see something like a word processor written in a purely functional language with monads like Haskell. Then someone take the % of the code spent creating stateful monads ( such as IO or Option ) vs nonmonadic code or stateless monadic code ( like Lists ). I suspect that on averaage over all the programs in the world, 90% of the code ( via code, execution time, or any other size metric ) is spend into stateful monads and 10% in the rest of the code.

  86. I code in Haskell by xenog · · Score: 1

    I always want to get code that works, and better yet that works right after successfully compiling. Haskell with its functional style and rigid type system helps me catch the multiple errors that inevitable end up in my code as I write it. I have done multiple programs and libraries in Haskell and I’m pleased with the small chunks of expressive code that come out of these efforts. Sometimes I have to write verbose monstrosities that do very little in Java. I always dread going back to it. I write many more bugs in Java that I do in Haskell, and fewer get caught at compile time. A Java IDE is where both my productivity and fun go to die.

  87. Functional could be next - maybe by ripvlan · · Score: 1

    Functional programming is getting better. I use lambdas in C# all the time, sometimes in Python too (although I don't like the syntax), and I've tried them in Java. In C#/Java/et al they are fabulous ways to focus on the Functionality and not the Implementation (what the heck is this FOR loop doing?).

    Pure functional has problems that will be solved. Jet.com is based on F# (the whole website and backend - yes a bit of C# here and there). Now could be the time to jump in - while being aware that patterns and practice are an emerging area and there will be growing pains.

    I've been using F# and R for over a year now. F# caused me to suffer from a problem that early OOP/C++ programming had - methods/layers that hid too much and made debugging difficult because it wasn't clear where it went wrong. Plus the syntax of these languages can be confusing, and procedural languages (C#/++/Java) work the way we "think" "step1 - do this, step2 - do that" Functional focuses on the end product and not the steps in between. Beyond different syntax, we need to think differently.

    I've found myself passing too many arguments "down" to the layers (again - something early OOP suffered from). The promise of altering the lower implementation layers without affecting top-level code hasn't panned out. I've had a bit better luck with R but the problems I'm solving are different. F# has been a "real" program and R has been computation of stats (grab data and compute min/max/avg). OOP solved it through better patterns such as ambient properties and policy injection, possibly OCP (which is NOT a functional solution). I'm finding the readability of code to be difficult (esp this Javascript nested stuff -- seems like using the wrong tool for the job, as in, I want to program like this and let's' see what's in the web toolbox... Javascript it is).

    While I like F# my biggest mind-bender has been around function composition. The idea of magic params that the runtime simply solves causes a lot of "magic" to occur that isn't obvious to the coder. Yes - shorter code. However, the next person must spend time reading and understanding the code before being able to make changes that doesn't break the implementation. Again - the OOP problem. To read an F# function and wonder "where'd param 3 come from?" or "where *does* param 3 come from?" Quite possibly new patterns that must be learned.

    So I say - give it a try. Learn a new language.

    1. Re:Functional could be next - maybe by retchdog · · Score: 1

      "the next person must spend time reading and understanding the code before being able to make changes that doesn't break the implementation."

      yes, but does it have any disadvantages?

      --
      "They were pure niggers." – Noam Chomsky
    2. Re:Functional could be next - maybe by ripvlan · · Score: 1

      har har har..

      No - what I meant was... they need to develop an (overly) intimate understanding of what the code is trying to achieve.

      In most programming languages I can quickly understand the purpose and make a change. Maybe there's some concept like "functional density" which is "Low" in a language like C# and very "high" in F#. Therefore I can make non-functionality changes in C# that serve little purpose and unlikely to have side-affects because lots of code is crap to fill whitespace. But functional languages lack "white-space-code" :-)

      I will add that I've achieved a lot more functionality quickly using R & Python. My implementation of an internal utility was ~50 lines in Python vs the existing utility written in C# which was easily near ~500 lines. Granted I pulled in a lot of modules so the total size was larger -- but my effort was small to achieve the same goal. Same thing with my R programs.

      The only reason I can't say the same with F# is that I have a (relatively) lower number of hours in it.

  88. Not really by Kjella · · Score: 1

    I work far more with SQL than programming languages really, but I do work a lot with doing operations on large data sets so I definitively try to avoid looping through a million rows. I use in-memory or temp tables to chain operations without storing state. And that's all neat and well, but without a ton of state in between those set operations to say what's ready, what's running, what's done etc. I'd go nuts. The functional bits are the stretches between the state almost like barriers in computer shaders and other synchronization methods. A pure functional application well I couldn't really imagine it unless it read one file as input and spit out a result, it just flows through the whole application. Every time I try to understand state in FP my head hurts.

    --
    Live today, because you never know what tomorrow brings
  89. High-brow fails [Re:It depends on the use] by Tablizer · · Score: 1

    "High brow" programming has never proven itself in practice for multiple projects. There's never been a case where top-notch, highly-educated programmers are put into a single organization such that it consistently out-competes the "medium-brow" shops. They may be paid more than average, but in theory they'd be far more productive using high-brow techniques such that it overshadows their higher salaries.

    Some bring up Paul Graham and his e-stores company, but that was a one-shot deal. Once the company became established it abandoned Lisp. Quick-to-market entrepreneurial may benefit from it, but I'm talking rank and file projects.

    Related discussion:

    http://wiki.c2.com/?IfFooIsSoG...

    1. Re:High-brow fails [Re:It depends on the use] by Pseudonym · · Score: 1

      "High brow" programming has never proven itself in practice for multiple projects.

      Sure it has. Assembler proved itself against writing binary, high-level languages proved themselves against assembler, managed languages proved themselves against languages compiled to machine code, regular expressions proved themselves against writing custom parsers... most new technologies were "high brow" once.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    2. Re:High-brow fails [Re:It depends on the use] by Tablizer · · Score: 1

      That's true. But it's hard to know what will be "mainstream" in a decade or so. I'm not convinced FP will "trickle down" to mainstream (4-yr-degree staff), at least as a primary technique. It's been around for roughly 60 years (at least as Lisp). If it doesn't go mainstream within 60 years, it probably won't by 70 either.

      Thus, it may not match or be part of the evolution pattern you outlined.

      Even when GUI's first came out, I couldn't predict they'd go mainstream. While I thought it was "cool", I thought it may stay limited to graphical applications because for non-graphical applications they don't make one more productive than a well-designed command and/or character-based interface. (And still don't.) What I didn't count on was that most found they are easier to learn (pick up). I didn't know that issue would override others in users/manangers' minds.

    3. Re:High-brow fails [Re:It depends on the use] by Pseudonym · · Score: 1

      Thus, it may not match or be part of the evolution pattern you outlined.

      Of course. For every highbrow concept that became mainstream, there's three that only became niche and another 20 which died off.

      I think that functional programming (and I include the actor model) is more important now because of the trend towards more and more cores on the one machine. Purely functional design scales to lots of cores in a way that sequential code does not. Whether or not the industry realises this is a separate question.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    4. Re:High-brow fails [Re:It depends on the use] by Tablizer · · Score: 1

      is more important now because of the trend towards more and more cores

      But the bottleneck is not CPU itself for a good many applications. And specialized languages or sub-languages can handle much of the parallelism. If I ask a database to do a sort, it may use parallelism under the hood, but I don't have to micromanage that in most cases: I don't care if the sort algorithm uses FP or gerbils on treadmills. Similar with 3D rendering: the designer submits a 3D model with polygons and texture maps, and a rendering engine micromanages the parallelism under the hood. That "root engine" may indeed use FP, but the model maker doesn't have to know or care.

      And event-driven programming can hide that fact that parallelism is going on, or at least provide a non-FP interface. For example, in a game, a character may be programmed by how they respond to various events. There may be 10 events going on at once, but the app dev is only focusing on one at a time per character or character type. Granted, it may take better languages or API's to abstract parallelism well. The "root engines" may make heavy use of FP, such as the database, rendering, and event handling engines, but the 2nd level, typically called "application developers", probably won't need that any more than SQL query writers (usually) don't have to know how the database engine was written. But only time will tell...

    5. Re:High-brow fails [Re:It depends on the use] by Tablizer · · Score: 1

      Addendum and corrections:

      The "actor model" seems pretty close to event driven programming. I don't know the official or exact difference. But my key point is that the event handling programming and interface is procedural. The only non-procedural aspect may be that requests for further actions may need a priority value (rank) and to be submitted to a request queue. For example, a game character may request a "shoot arrow" event on their part as a follow-up. But the event handler writer doesn't have to concern themselves with the direct management of the event-request-queue.

      "Any more than...query writers...don't have to know..." should be "Any more than...query writers...have to know...". Remove "don't"

    6. Re:High-brow fails [Re:It depends on the use] by Pseudonym · · Score: 1

      But the bottleneck is not CPU itself for a good many applications.

      That's true, but it's also not relevant. For most "apps", the main issues are battery life and responsiveness. Multi-core is increasingly being seen as a tool to increase responsiveness rather than throughput, because the app looks like it hasn't fallen asleep even if it hasn't done the thing that the user asked yet.

      If I ask a database to do a sort, it may use parallelism under the hood, [...]

      Interesting example. I wrote the sort subsystem for a (non-SQL) DBMS in one of my previous jobs, so... I guess this illustrates that we come from different perspectives on this point. In case you are curious, it was single-threaded, although it was designed to work on a clustered database, so it was parallel in the sense that it did parallel sorting across multiple machines in a cluster (which is what we called it before we called it a "cloud").

      That "root engine" may indeed use FP, but the model maker doesn't have to know or care.

      Right, and that's the advantage: Pure functional programming ensures that the client doesn't have to care, because workers are guaranteed not to modify anything that they are not supposed to because they are pure functions.

      Map/reduce was all the rage a couple of years ago. I think the main advantage was not the map/reduce model, but the realisation that when you have "big data", you take the code to the data rather than taking the data to the code. But on top of that, forcing yourself into a pure functional style means that your code can run anywhere because it doesn't care about the context in which it runs.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    7. Re:High-brow fails [Re:It depends on the use] by Tablizer · · Score: 1

      forcing yourself into a pure functional style means that your code can run anywhere because it doesn't care about the context in which it runs.

      Most planners focus on the current needs, not future needs. Whether that's rational (good business planning) is another matter. It's generally cheaper to hire and get future maintenance on procedural code. If and when machine performance issues override that, the planners may THEN care.

      It depends on the project. If most of the processing for an app is happening on servers in cloud centers, then it's probably already parallelizing user sessions. Parallelizing at the app level thus won't really give you much more parallelism potential, especially if most of the data chomping is done on the database, which should already be using parallelism. Web servers and databases already take advantage of parallelism. It would thus be diminishing returns to parallelize the app level. If the code is looping on 10,000 items in app code itself, the coder is probably do something wrong.

  90. Re:My answer by DickBreath · · Score: 1

    No? So you're saying you prefer dysfunctional programming?

    --

    I'll see your senator, and I'll raise you two judges.
  91. It's the explanations. Start with examples by raymorris · · Score: 1

    > I'm not sure if the problem is me or the explainers.

    I'm fairly sure it's the explanations, which tend to mathematically define them, rather than showing what the heck they are are what they are good for.

    I noticed that the other day looking for good explanations of the normal forms in relational databases (sql). Most of the explanations I found were crap. Rigorously correct, and entirely useless to someone who doesn't already fully understand them.

    My kid is two. When I wanted her to know what a "horse" is, I didn't start with a rigourous, formal definition of "horse" as distinct from all other species. I showed her a horse, so she could see what it is, then I showed her someone riding a horse, so she can see how it's used. I wish more comp sci people had basic competence in explaining or teaching.

  92. Damn how I hated LISP by NotSoHeavyD3 · · Score: 1

    Mostly because when I was taking it in college 20 some odd years ago all the code they gave us as example basically tried to do everything in one line of code. I mean damn, maybe if your terminal gave you a 50,000 volt shock for hitting the enter key I could understand it but it made debugging anything a complete pain. (Well that and the fact you had to have the absolute perfect number of parenthesis. One too many or few and watch the app crash.)

    --
    Did you know 80 to 90% of the moderators on slashdot wouldn't recognize a troll even if one dragged them under a bridge.
  93. Can someone explain... by Zo0ok · · Score: 1

    I understand this is stupid but I would like to know... have a look at:

    http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers

    Look through the inititial text and get an idea. Then jump to the C code (not functional).

    Then look at functional implementations: C++11, Python, Closure, Haskell, PicoLisp, Python, Scheme, Swift.

    Look at Scala: 2 ways: functional (recommended) and procedural. Look at it.

    What do you see?
    What do you think?

  94. Apples and Oranges by tgrigsby · · Score: 1

    Object oriented design is here to stay. Functional programming has it's place, but as little more than one off event handlers, I wouldn't call it a programming paradigm. Like interfaces, it's useful, but it's more applicable in some situations than others.

    Put it this way, if someone told me OOP was dead, I'd fire them because it would indicate to me that they didn't understand OO and would likely be resistant to understanding it.

    --
    *** *** You're just jealous 'cause the voices talk to me... ***
  95. Re:No by jbolden · · Score: 1

    At about age 3 months the child learned "there" or "not there" for things. They could distinguish 0 from 1. Functional counting reduces to an even easier algorithmic skill learned even earlier

  96. Re:I like functions... by jbolden · · Score: 1

    In Python you would rarely want to do it. I'll give you some simple examples.

    items = [1, 2, 3, 4, 5]
    def sqr(x): return x ** 2;
    list(map(sqr, items))

    Now imagine this were legal:
    [1, 2, 3, 4, 5](map(**2,items))

    The **2 is a closure

  97. Love it in Ruby by Brian+Feldman · · Score: 1

    I love how it's done in Ruby. It's compact and yet readable, unlike certain other older languages known to include many paradigms, including OO and Functional.

    --
    Brian Fundakowski Feldman
  98. Re:I like functions... by mrchaotica · · Score: 1

    It's quite a bit more than that, at least if you're talking about pure functional programming. You also have to get rid of most all of your old notions of flow control. Imperative programming is about defining sequences of steps, some of which are conditional. Functional programming is all done with nested transformations; there are no sequential steps, there are no branches, there is no iteration.

    If you think about it, those are inevitable consequences of the constraints I mentioned. However, it's good that you highlighted them.

    If this sounds freakish and impossible to someone raised on imperative programming paradigms... yes, it is. Functional programming requires thinking in an entirely new way.

    Yep, both recursion and constructs like map/filter are incredibly useful (even in procedural/OO languages) once you get the hang of them.

    --

    "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

  99. Re:Moderate usage okay by lgw · · Score: 1

    Just guessing what AC means, but assuming he's talking about Java, enum's in Java can take arbitrary values (they're just instances of a class, and so can have as much state as you'd like, including lambdas). It lets you do the equivalent of creating an interface with one method, and a class that implements that one method specifically for each enum, without all that clutter and boilerplate. But it's a bit hacky, and best kept to small, self-evident lambdas. Java-style enums, aka "class enums", let you avoid a lot of switching in general, since often you were just getting some constant value associated with each enum value.

    --
    Socialism: a lie told by totalitarians and believed by fools.
  100. Project Euler by PJ6 · · Score: 1

    I see a ton of comments here from people that clearly don't understand what functional programming is, or they don't really get it. If you consider yourself a programmer, go to Project Euler and do the first 20 (or 50) problems. Use whatever language you like. You have to do them, because you need to solve them to see all the other solutions.

    Look at the solutions, in all the different languages, and compare. Not just for speed, but the design. Take a good look.

  101. Functional Programming IS GROOVY!!! by Foofoobar · · Score: 1

    For all the BS about Groovy not being functional, if you look at partial implementations, Groovy is just as functional as Scala. And better yet... it is 100% compatibale with Java; Take ANY Java class and change the extension to '.groovy' and it will compile!

    --
    This is my sig. There are many like it but this one is mine.
  102. Re:I like functions... by jbolden · · Score: 1

    ** is a function of two variables. The 2 is coming from a different context. **2, as a squaring function is a closure. No need to be complex about closures.

  103. Re:I like functions... by JesseMcDonald · · Score: 1

    ** is a function of two variables. The 2 is coming from a different context. **2, as a squaring function is a closure.

    (**2) is a Haskell-style "operator section" which would be shorthand for "lambda x: x**2" in Python. This lambda has no free variables and thus is not a closure. An example of a closure would be the second lambda in "lambda x: lambda y: x**y", which closes over the free variable "x". You can also do this without lambdas:

    def pow(x):
    ____def curried(y): return x**y
    ____return curried

    # returns closure of lambda y: x**y, capturing x=2
    f = pow(2)

    # returns 2**4
    f(4)

    (Pretend the underscores are spaces.) The important part is that the function you are capturing includes references to free variables inherited from its original context.

    --
    "The state is that great fiction by which everyone tries to live at the expense of everyone else." - Bastiat
  104. Re:I like functions... by jbolden · · Score: 1

    I was treating (**) as your second case, ignoring the (**2) as a specific function. Remember the idea originally was to show a simple example of the concept for Python.

  105. Why do I care, in practical terms? by nctritech · · Score: 1

    I have examined the concepts and languages involved in functional programming and I do not see their value. Most of my work is split between C and shell scripts with random PHP, SQL, etc. peppered in as necessary. My question is simple: what can functional programming do for me, in practical terms? Including a real-world example is mandatory to answer the question. I always see platitudes regarding either "elegance" or "you'll have to think differently" but neither is an actual benefit. I don't need a hammer that is hard to use and makes me think about the nature of hammers and their usage; I need something that is efficient and straightforward when I decide to forcefully attach two things using nails.

    As far as I can tell, functional programming is only useful as a thought exercise...which means that (compared to "uncool" but widespread languages like the C family) it's not useful when you actually want to get something done.

  106. Re:I like functions... by JesseMcDonald · · Score: 1

    So you were treating (**) as the free variable? That works, provided the operator actually appears as a function argument or local variable in an enclosing function context. References to global definitions do not create closures in Python. (The value of a global variable or function definition is looked up at each call, not captured as part of the lambda.) However, in that case you can't really refer to (**2) as "the squaring function" since (**) could do anything, not just exponentiation.

    --
    "The state is that great fiction by which everyone tries to live at the expense of everyone else." - Bastiat
  107. GUI Example [Re: It has its uses] by Tablizer · · Score: 1

    Of course in GUI development, Lambda can also be very convenient.

    Example? I've only seen examples that expose weaknesses in Java and/or its GUI libraries.

    For example, if the distinction between on object and class were blurred, then each GUI push-button could and should have an OnClick method. (Language could include an option to add or change the method away from object declaration.)

    Instead, one has to "register" the on-click code with a "listener" via a lambda. Why the fock should a typical coder have to care about a fricken GUI listener? That should be under-the-hood guts, or at least something you only care about (mostly just inspect) if there is a tricky bug. The coder mentally associates the on-click behavior with its button, and the GUI API should reflect that common sense. Java's doing it wrong; lambda's are merely a band-aid over bad design in that case.

    "We forgot to think this through so instead we randomly shoehorn behavior into the gui via lambda's"

    I've seen other "justifications" for lambda's that are usually a kludge over bad languages and/or libraries.

  108. Yes by leifbork · · Score: 1

    Yes

  109. Code by NewYork · · Score: 1

    Show me the code --Linus

  110. Re:FP becomes more popular than OOP? by Tablizer · · Score: 1

    The industry learned the hard way that OOP works well for some things but not others. For example, OOP has mostly failed in domain modeling (modeling real-world "nouns") but is pretty good at packaging API's for computing and networking services.

    The industry may also learn the hard way where FP does well and where it chokes. Some understandably don't want to be the guinea pigs.