3 ms·
Isn't it possible to learn functional programming in C ? I often read people saying learning a functional language taught them good programming practices that
by jokoon 12y ago
Isn't it possible to learn functional programming in C ?
I often read people saying learning a functional language taught them good programming practices that they could apply to other language, so I conclude that functional programming is only made mandatory and very encouraged in functional language, but it doesn't mean it's not possible to use functional programming to a language like C.
I guess one way to learn functional programming simply would be to write as many pure functions as possible, and go from there. No need to learn a functional programming language. Honestly, haskell melt my brain several times and I did not see the point of learning it.
- adrusi 12y agoFunctional programming generally involves a lot of dynamic memory allocations (which are usually optimized in some way). Without some form of assisted memory management, this quickly becomes excruciating. C also lacks function closures, so important abstractions like function composition, partial application and higher order functions. It also lacks type parameterization and polymorphism. Not everyone will consider all of these to be fundamental to functional programming, but I'm certain most people would require at least one. C simply doesn't provide powerful enough mechanisms for abstraction to enable any interesting parts of functional programming. C++, Rust, D and Nim all do, however. If one ever felt the need to use them in a functional matter it would be possible, albeit unpleasant. Additional reading: https://news.ycombinator.com/item?id=8609775 https://news.ycombinator.com/item?id=8609775
- PolymorphicUser 12y ago>Functional programming generally involves a lot of dynamic memory allocations (which are usually optimized in some way) It's symptomatic of many functional languages, but it's not a prerequisite. > . C also lacks function closures, so important abstractions like function composition, partial application and higher order functions. That, on the other hand, is a core feature of functional languages (what does it mean to have functions as first class citizens if one cannot manipulate them in an algebraic way?). I actually think it's the only needed feature to qualify. > It also lacks type parameterization and polymorphism. These are strongly typed languages features, I wouldn't define a functional language by it (I don't think it's necessary), although it appears in many of them.
- mmf 12y agoIf I get the point of the article, the author would argue that cpp provides some form of closure (you can code a macro that generates a function that behaves somewhat like a closure if you want...)