7 ms·
Functional programming is the most important CS topic if you want to become a great (1.5+) engineer. No, you aren't going to be doing pure functional programmin
by michaelochurch 14y ago
Functional programming is the most important CS topic if you want to become a great (1.5+) engineer. No, you aren't going to be doing pure functional programming very often. In the real world, eliminating mutable state is neither possible nor desirable. It's extremely worthwhile to learn how to manage state, though. Hell, even the Unix philosophy (do one thing, do it well) was directly inspired by functional programming, though it couldn't be purely functional (infeasible at the time, plus semantic mutability).
TL;DR: If you don't know what "flatMap that shit" means, then it's worthwhile to learn it.
- jasallen 14y agoThis is very well said. I kind of think of it like learning calculus - if you aren't an engineer of very particular types you likely aren't using it directly, but the thinking patterns influence your analytical thinking tremendously.
- seanmcdirmid 14y agoYou should know it, but don't get all ideological and neglect your advanced object or imperative programming training. You might even want to look at gasp other paradigms like rule based coding to broaden your toolbox a bit. tl;dr scala is the best object-oriented imperative programming language I've ever used.
- spacemanaki 14y agoThis is something I think Martin Odersky did really well in this class... he spent a decent amount of time discussing tradeoffs between FP and OOP and how one might arrive at choosing the different features of Scala, even going so far as to cover the "expression problem" in Scala. I think it was a superbly tasteful presentation of Scala and FP.
- seanmcdirmid 14y agoI prefer the pure OO trait-based solution to the expression problem that isn't supposed to exist; pattern matching is not the only way to do it. Scala is just that good.
- edem 14y agoI think that Clojure might change your mind about that.
- papsosouid 14y agoAbout which? Caring about imperative/OO paradigms, or scala being a good imperative language?
- michaelochurch 14y agoClojure is, at least culturally based on what I've seen, much closer to purely functional than Scala. Both are great languages, IMO.
- seanmcdirmid 14y agoRight. Scala is functional like C# is; yes, the functional abstractions are more powerful than C#, but like C#, its not forced down your throat. I'm still waiting for people to discover how Scala is the best OO language we have so far, traits are incredibly powerful and case matching on top of that is just icing.
- Garoof 14y agoHeh. When I first checked out Scala, what I liked about it was that it dealt with a lot of the stuff that annoyed me when going from Smalltalk to Java :)
- kyllo 14y agoYes, Clojure is a Lisp, and looks like one. Scala can look like Java or it can look like ML, depending on the author's style. It's very multi-paradigm.
- kyllo 14y agoSure, being ideological and closed-minded is never a good thing. But one of the takeaways is that lambda expressions/anonymous functions, first-class functions, and function closures, are very powerful tools that should be provided in any modern, high-level programming language. The fact that they're working on adding these features to Java 1.8 is testament. Would be nice if they could also add polymorphic function/method declarations and Hindley–Milner type inference, but oh well, you have to start somewhere...
- chris_j 14y agoWhat does "1.5+" mean in the context of being a great engineer?
- lifeisstillgood 14y agomichaelochurch, like a few others, has his own meme on HN - he has a well received blog post describing it in detail, (http://michaelochurch.wordpress.com/2012/01/26/the-trajectory-of-a-software-engineer-and-where-it-all-goes-wrong/ http://michaelochurch.wordpress.com/2012/01/26/the-trajector...) Essentially he rates programmers on (IIRR) a 0-3 scale of impact - so a 1.0 developer neither adds nor subtracts to the overall quality of the code base, and a 3.0 invents C and Unix. This quote is something we should all measure ourselves against - honestly and painfully at times. 1.4 to 1.6: Solid adder: well above-average (top 10%) by software-industry standards, but average (at 5-10 years’ experience) in the context of the best companies (e.g. elite startups, Google, and research divisions of IBM). Can be trusted to independently solve most problems in an elegant and maintainable way. Engineer can make reasonable time estimates and communicate in both business and technical terms with management as well as other engineers. Can handle small levels of deadline/delivery responsibility and should be encouraged to participate in architectural decisions (“multiplier” concerns). Technical leadership non-urgent projects is a serious possibility. That's average base level in my book. And sometimes I mess up on those too. (Communication being a big bug bear for me)
- chris_j 14y agoThanks very much for the information; I had completely missed that particular meme until now.
- Kiro 14y agoI'm a PHP developer who often uses w3schools as reference. What score do I get?
- lifeisstillgood 14y agoI don't know. You are on HN so it's a good guess its productive. You know enough to know PhP and w3schools indicates there is more to learn and so I would guess you are on the right path As for everything else - I don't know till I read your code
- tel 14y agoAs a strong Haskell programmer I'm curious about the statement that "eliminating mutable state is neither possible nor desirable". My first response is to say that I find it both possible and desirable. My second is to note that "elimination of mutable state" isn't really the goal. The real goal is to give mutable state a very composable, repeatable, clear, and restricted semantics. This is what occurs in the State monad in Haskell, for instance. You retain mutability (observable w.r.t. the stored state over applications) but can slice up the mutation and the intermediate, immutable values and recompose them in various forms with impunity. That kind of state model is incredible to learn. Monads might be scary because they're unfamiliar, but in a functional context they can do some beautiful things.
- deleted 14y ago[deleted]
- tel 14y agoMonads are a way of reifying and manipulating context. If that context includes a background mutable state model, then yes. Monads are more useful than just for providing mutable state. That said, your example is just a constant function, not a monad at all. The point of monads wrt. mutable state is not that they hide it—indeed they uncover it and make it more explicit. I have to exactly specify where my code makes mutable or world-observable changes. Furthermore, through explicitness I can now manipulate, compose, adjust these abilities very flexibly.
- runT1ME 14y agoThe State Monad isn't really mutating state though, it's really a monad for composition of incremental operations upon immutable data structures. The ST monad is for 'hiding' mutable variables and ensuring their state doesn't violate referential transparency.
- tel 14y agoFrom inside the State monad though, it "looks just like" (has semantics of) mutability. It's simply interpreted in an immutable lambda calculus. The ST monad has the same game but a different interpreter.
- Dewie 14y ago> No, you aren't going to be doing pure functional programming very often. Some people claim that one is often able to make programs with a mostly functional core; in which case most of the code is purely functional. Do you not think that is the case?
- michaelochurch 14y agoSome people claim that one is often able to make programs with a mostly functional core; in which case most of the code is purely functional. Actually, I think that is the best way to do most things. Mutable state should be documented and sequestered. Perhaps what I consider "pure functional programming" (i.e. a project with all-functional code, except perhaps an I/O layer) is unreasonably purist.
- papsosouid 14y ago>No, you aren't going to be doing pure functional programming very often I do every single day. >In the real world, eliminating mutable state is neither possible nor desirable. Eliminating state is not what functional programming is about. >If you don't know what "flatMap that shit" means, then it's worthwhile to learn it. Scala is a pretty terrible language to be learning it though. Subtyping makes things far more complex and difficult to learn, just for the benefit of java compatibility (which doesn't matter if you are just learning for the sake of learning).
- michaelwww 14y agoI have a question if you care to answer. I was watching "Overview and Introduction to Lisp" (link below.) I was struck by the idea of a function taking a function as input and transforming it to another function as output. My only experience with something similar is JavaScript, but the idea of a function doing function transforms is new to me. Is this the fundamental thing to understand about Functional Programming? http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-001-structure-and-interpretation-of-computer-programs-spring-2005/video-lectures/1a-overview-and-introduction-to-lisp/ http://ocw.mit.edu/courses/electrical-engineering-and-comput...
- papsosouid 14y agoI don't know if I would say it is the fundamental thing, but it is certainly an important fundamental thing. I think if I had to pick a single most important fundamental thing I would say it is composability. That is the underlying reason behind things like monads and lenses for example.
- michaelwww 14y agoThanks. I'm liking what I'm hearing. I hear functional programmers say state is evil, but it seems like a necessary evil. What I agree with more -- and they say this a lot it seems -- is that complexity is evil. I like the focus on building something large from smaller, easily understood parts.
- stiff 14y agoWhat about things like data structures, general understanding of programming language semantics, basic problem decomposition for data hiding and abstraction, ... ?