4 ms·
> You have to go look up three functions every time you read a block of code. When you write small, single-purpose functions, you can make them fairly self-doc
by JoshTriplett 10y ago
> You have to go look up three functions every time you read a block of code.
When you write small, single-purpose functions, you can make them fairly self-documenting with the name alone. If you have to look up a one-line function, it probably doesn't have a very clear function or name.
> Worse, people start writing the same functions over and over again.
That one I've definitely run into.
> There's probably a bigger picture problem and fix in that kind of situation, but it is something I think about.
Mechanisms to search functions by type ("find me a function that takes an X and returns a Y") help quite a bit.
- mrkgnao 10y agoConventions also help. For instance, the lazy readTVar, modifyTVar, etc. functions have strict analogs called readTVar' and so on. mapM, foldM, replicateM, and traverse return a monadic value, while mapM_, foldM_, replicateM_, traverse_ and friends discard the return value (giving an m () instead of an m a).
- Silhouette 10y agoWhen you write small, single-purpose functions, you can make them fairly self-documenting with the name alone. Sometimes, although with languages like Haskell there can be a related problem that accurate names for these small functions wind up being almost as long, or even longer, than their definitions.
- astrobe_ 10y agoPharo/Squeak (and probably other Smalltalk systems) have a utility that let you find a function given a set of input/output examples.
- krakensden 10y agoDo you have a name/link? That sounds fascinating.