4 ms·
I was afraid this would be some sort of contorted framework to let you use C++ to write Lisp. Glad I was wrong. Carmack is spot-on here: "My pragmatic summary:
by kibwen 15y ago
I was afraid this would be some sort of contorted framework to let you use C++ to write Lisp. Glad I was wrong. Carmack is spot-on here:
"My pragmatic summary: A large fraction of the flaws in software development are due to programmers not fully understanding all the possible states their code may execute in. In a multithreaded environment, the lack of understanding and the resulting problems are greatly amplified, almost to the point of panic if you are paying attention. Programming in a functional style makes the state presented to your code explicit, which makes it much easier to reason about, and, in a completely pure system, makes thread race conditions impossible."
Too often I've seen functional proponents, when asked why we ought to use functional languages, rely on facile arguments such as "it makes your code more concise, therefore easier to hold in your head" or "it makes your code more mathematical, and therefore easier to reason about". Like Rich Hickey, Carmack gets it right.
- bithive123 15y agoTo me, "easier to hold in your head" is "easier to reason about". I can also imagine someone describing functional style (the thing Carmack says makes state presented to your code explicit) as "more mathematical".
- kibwen 15y agoI wasn't saying that the example arguments I gave were necessarily invalid, only that they are remarkably uncompelling. Is functional style the only way to achieve concise code? Is "mathematical" code really the standard to which we ought to aspire? These questions, among others, are left unanswered. Essentially, a bad argument for functional programming says, "here is what functional programming does well; here is why that helps you". A good argument for functional programming says, "here is a very real problem that you have encountered; here is the remarkably effective way in which functional programming addresses it". Note the inversion, especially the focus on solving problems rather than on justifying paradigms.
- dons 15y ago"hold in your head" == minimizing complexity by minimizing the state space. "Mathematical" == stateless, pure functions. If the states are fewer, the code is simpler. I can only hold simple things in my head :) I think everyone's basically saying the same thing.
- qznc 15y agoFunctional programming is not "minimizing" state. The point is that it makes state "explicit". The minimization is done by the programmer because she is lazy and longs for conciseness.
- dons 15y agoMaybe you write FP code differently to me, but I'm constantly trying to minimize the complexity of the code, so that it only contains the essential complexity. I gave a talk on how FP approaches force you to minimize accidental complexity recently, capturing this view, http://code.haskell.org/~dons/talks/padl-keynote-2012-01-24.pdf http://code.haskell.org/~dons/talks/padl-keynote-2012-01-24....
- jerf 15y agoFunctional programming has a lot of state minimization in it, at least in the stronger forms. A function in Haskell of Int -> Int can only be affected by the input Int. A function in C of int function(int) can be affected by arbitrary state from throughout the system; it may decrement or increment depending on global variables. It may write files. It may open connections to remote servers and read stuff off the internet. It has a vastly huger potential state space in theory and often vastly huger state spaces in practice. I go into this more explicitly in http://www.jerf.org/iri/post/2908 http://www.jerf.org/iri/post/2908 .
- batista 15y agoI find this statement outrageously offending. Why do you assume the programmer is a "she"? It might as well be a "he". Or it might as well not want to be associated with any gender (consider a transexual, asexual, or an alien from Mars). I think s/h/it is the correct pronoun to use to cover all those cases. (yes, it's /s. When I see "she" used to imply the author is oh, so progressive and non-sexist, I resort to sarcasm).
- nuje 15y agoWhy do people still associate FP with Lisp even though HN is supposed to be a lisper hangout :P
- VMG 15y agoI was under the impression that Lisp makes it easier to write functional code?
- cousin_it 15y agoYour impression is right. And nuje's question is also right. The goal of Lisp is to make it easier to write all kinds of code, including functional.
- fulafel 15y agoCommon Lisp is a a lot like other dynamic languages in that department. Some lispy languages have more FP support (eg. Scheme says implementations must perform tail call optimization so you can recurse without blowing your stack, which is useful when doing FP).
- pjmlp 15y agoThanks to lambdas in C++11, coupled with STL algorithms, there are a lot of possibilities to do functional programming in modern C++. One just has to take care to minimize mutability, as Carmack wrote on his blog entry.
- cageface 15y agoI wish the lamba stuff would finally land in Xcode. I think of all the features in C++11 that's going to change the way I write C++ code the most.
- deleted 15y ago[deleted]
- pjmlp 15y agoI am not a Mac OS X guy, but wouldn't installing a more up to date gcc or clang, do the trick?
- cageface 15y agoUnfortunately not. The clang that ships with Xcode is pretty tightly integrated into the IDE. I suppose it might work from the command line but I don't want to give up the IDE features.
- kruhft 15y agoI thought c++11's lambda's would be great until I tried to pass one into std::transform.