5 ms·
I've been paying attention to functional for the last 6 or so months and coming from a C background, its emphasis on immutability, data-oriented, readability, a
by bimbossible 9y ago
I've been paying attention to functional for the last 6 or so months and coming from a C background, its emphasis on immutability, data-oriented, readability, and safeness is really attractive if you're not worried about performance (which is allowed to take a back seat in most apps these days). I can't wait for software to be improved harboring the benefits of functional programming.
- sevensor 9y agoThere's no reason you can't realize some of these benefits in C. I wrote a program recently that produces a new struct every time the state changes (any function that changes the state is passed the current state struct by value and returns a new state struct.) While part of the state is a multi-gigabyte memory allocation, this is represented as a pointer, so copying it from state to state is very cheap. This means that all of the structs point to the same chunk of memory, so only one of them can be considered valid at a time. I found that this approach made it very easy to keep track of what state my program was in. It greatly simplified error handling because I could just discard a failed update rather than trying to unwind it.
- bimbossible 9y agoYou're correct. I've been writing C lately with functional concepts in mind and noticed an improvement in cleanliness with state and style. I'd definitely recommend trying it to other C developers.
- pmarreck 9y agoCarmack wrote about this years ago, and he's now a fan: https://www.gamasutra.com/view/news/169296/Indepth_Functional_programming_in_C.php https://www.gamasutra.com/view/news/169296/Indepth_Functiona...
- IMTDb 9y agoWhy should FP be slower ? The articles emphasises that one of the main arguments in favour of FP is that it's easy to see what part of the recipe can be done in parallel. Why can't the runtime automatically leverage multiple cores and speed up the process ?
- _pmf_ 9y ago> Why should FP be slower ? It's easier to move an object 1 cm to the left than it is to bootstrap a universe where the object happens to 1 cm to the left. > Why can't the runtime automatically leverage multiple cores and speed up the process ? That is more related to proper dataflow analysis than immutability, and this is much more mature in VM runtimes that are actually used (hundreds of man-centuries vs. the odd PhD thesis).
- whistlerbrk 9y ago> It's easier to move an object 1 cm to the left than it is to bootstrap a universe where the object happens to 1 cm to the left. structure sharing solves this, if my understanding of what you are implying is correct.
- rhinoceraptor 9y ago> It's easier to move an object 1 cm to the left than it is to bootstrap a universe That's like saying sorting can never be fast when the only algorithm you have is bubble sort.
- _greim_ 9y ago> Why can't the runtime automatically leverage multiple cores and speed up the process? Do any runtimes actually do this? (Honest question)
- thanatropism 9y agoMatlab.
- jackhack 9y agoErlang/elixir's runtime, OTP (open telecom platform) will do this. It can scale to multiple cores, or across multiple machines in a network, almost effortlessly. https://en.wikipedia.org/wiki/Erlang_(programming_language) https://en.wikipedia.org/wiki/Erlang_(programming_language)
- pjmlp 9y agoI always look at it from this point of view, Lisp was already running in mainframes during the 60's. http://www.softwarepreservation.org/projects/LISP/lisp15_family/ http://www.softwarepreservation.org/projects/LISP/lisp15_fam... In 1962, the IBM 704 was the first computer running Lisp. So given the hardware we have nowadays, unless we are doing some critical real time stuff, there is little reason for FP like programming not to be fast enough for 99% of most use cases.