4 ms·
In terms of day to day programming, I've picked up the following habits: * Natural terseness. A lot of functional code is freakishly short. Because functiona
by newhouseb 16y ago
In terms of day to day programming, I've picked up the following habits:
* Natural terseness. A lot of functional code is freakishly short. Because functional code is similar to how we think of math, it's often times easier to simplify out over-computation and you end up with the bare minimum of what you actually need.
* Generic programming. Things like currying and first-order functions are great for separating (or combining) context from computation. When you understand where the difference lies, you can write your code such that it is adaptable in the most efficient way (read: generic).
* Lambda functions. Infinitely useful in a language that uses them, like Python. Lambda's are great for doing work over large collections of data without getting lost in for loops (i.e. map, reduce, sort, fold).
FWIW: I learned what I know from Haskell
- viraptor 16y agoExamples I completely agree with. I got used to short functions so much, than my normal function length in any other language went down a lot too. Now I'd probably refactor anything that doesn't fit on half of a screen (got fairly big monitors though). And that's a good thing - the effect is easier to read and the shorter the code is, the more self-documenting it becomes, because you have to name every sub-process correctly via the function name. Something that would otherwise be a 40 line function with inline comments: "First do this", "then do that", becomes a two-line: do_this(); do_that(); with ~20 lines in each of them. Much much better. On the other hand, once you get too used to lambdas, you start missing them in other languages. It just felt natural for me at some point to make a C macro (f, arr, type, len) which did something like map on an array of `type` using a function pointer `f`. That didn't go very well with other people who normally read that code...