I've noticed hackers/self taught prefer functional programming styles and CS degree holders prefer the more common style.
Functional Programming in C++ (2013)
11–20 of 64 posts
Re: Functional Programming in C++ (2013)
#12One difficulty with functional style c++ is just how verbose it is. Every time I tried to use std::transform (the equivalent of "map") I had to delete it and rewrite as a loop because it was just too hard to read. Functional style on a large scale is still possible.
The article is not about the functional C++ you mention. It is about using pure functions (functions that do not modify global context).
Re: Functional Programming in C++ (2013)
#13I've noticed hackers/self taught prefer functional programming styles and CS degree holders prefer the more common style.
Re: Functional Programming in C++ (2013)
#14This is from 2013, and the original title is "Functional Programming in C++". Moreover, Carmack never makes a statement that functional programming is the future anywhere in this article. The closest he says is "Formal systems and automated reasoning about software will be increasingly important in the future," which is a markedly different sentiment. That said, the problem of not understanding possible code states d…
https://news.ycombinator.com/newsguidelines.html
(Submitted title was 'John Carmack: Why functional programming is the future'.)
Re: Functional Programming in C++ (2013)
#15I just can't get behind all of this. Sure, its great to be able to reason clearly because you can see your whole state, but its exhausting always carrying your context around like a hobo with a huge backpack full of junk. Am I mistaken?
One of the tricks is the use of monads in Haskell. Monads are really just a small set of functions that operate in a certain way (that "satisfies the monadic laws") on a type.
What that gives you is (among many other things) a way to carry an implicit "world" around with you without needing to refer to it all the time.
One use for such a "world" would be a seed for a random number generator so different parts of your program can use their own, isolated streams of random numbers (nice for determinism, testing, debugging, etc), even if they execute asynchronously because Haskell is a "lazy" language where code doesn't necessarily get evaluated unless it really needs to.
Another use is for the "world" to actually represent the real world -- all of it -- so the I/O interactions happen in the right order. That's very important in a language where the evaluation order is so "loose" as it is in Haskell.
There are other tricks as well. One of them is to have lots of small transformation functions that don't need to understand all of the world, just their little bit of it. You create the big world transformations by composing the smaller transformations. The data structures you use are slightly different: you don't want to modify your data structures, you want to create new ones all the time, i.e. inserting an object into a tree shouldn't modify the tree but return a completely new tree with the new object in it WHILE KEEPING THE OLD TREE AROUND UNCHANGED. This doesn't have to be as expensive as it sounds, in fact, it can be quite cheap. Data structures where you can do this cheaply are called persistent data structures and they work really well with a functional programming style.
(They don't have to implemented purely functionally internally as long as they present a pure interface.)
https://en.wikipedia.org/wiki/Persistent_data_structure
Persistent data structures can also be confluent, which means that they use sharing internally if two versions of a data structure end up being logically the same. Tarjan and Sleator have some really nice papers on that -- well worth reading, even if you don't care one bit about functional programming.
Re: Functional Programming in C++ (2013)
#16I've noticed hackers/self taught prefer functional programming styles and CS degree holders prefer the more common style.
[1] At least the Haskell/ML kind.
Re: Functional Programming in C++ (2013)
#17I've noticed hackers/self taught prefer functional programming styles and CS degree holders prefer the more common style.
Hackers, and I'll assume all those vaguely tracing their lineage from MIT, have never been associated with FP. There has always been a fascination with Lisp, but that's the extent of it. In practice, most of their software legacy has been in firmly imperative and procedural languages, but with touches of a Lisp here and there.
It's precisely CS and academia where functional programming has been thriving. John Backus' research on function-level programming, Robin Milner on ML, David Turner on Miranda from which Haskell is almost a direct successor, etc.
So on the whole, I have the exact opposite impression that you do.
Re: Functional Programming in C++ (2013)
#18I've noticed hackers/self taught prefer functional programming styles and CS degree holders prefer the more common style.
i think people probably just prefer whatever paradigm they used first or currently are comfortable with. I have a cs degree and we were taught scala at my school and now I use it everyday.
I really like functional programming, especially in Standard ML and Haskell. I didn't learn ML until I'd been programming for about 15 years.
Edit: beadder grammer.
Re: Functional Programming in C++ (2013)
#19I've noticed hackers/self taught prefer functional programming styles and CS degree holders prefer the more common style.
I think this preference has more to do with the individual's past experiences and future goals than it does with his/her level of formal CS education.
[1] Although even this varies greatly from school to school, the school where I got my MS used OCaml in the undergrad algorithms course for awhile. My undergrad algorithms course used C, so again no OOP.
Re: Functional Programming in C++ (2013)
#20I've noticed hackers/self taught prefer functional programming styles and CS degree holders prefer the more common style.
If you learn type theory and semantics you also learn functional programming (and will probably like it, even if you don't use it much in practice).
If all the world is a Java VM to you, then... well, you might have a different view of the world.