3 ms·
Functions were invented by functional languages…but they originally were a lot more flexible than the way most procedural languages use them now. Let’s try rew
by hasmanean 5y ago
Functions were invented by functional languages…but they originally were a lot more flexible than the way most procedural languages use them now.
Let’s try rewriting your example this way
add = function(a,b) { + a b }
Why is this better?
Because + is a function, and add is an object, so you can then refactor the code to say this
add = +
Try doing that in C.
As I see it the code for some programs has a high degree of symmetry (ie repeated patterns), and the best language is a notation the let’s you capture that the best.
If you find yourself cutting, pasting and modifying things slightly each time, then your language is holding you back.
Test-script code is the best example of this…particularly hardware tests. You have the same code copied and pasted dozens of hundreds of times.
Thoreau once said that government is best that governs least. That language is best that makes you type the least.
- kaba0 5y ago> add = + > Try doing that in C. Function pointers. They are abused to no avail in C programs. It has the original callback hell, not JS. (And that is mainly because C has no proper way for abstractions)