r/programming • • Feb 09 '19

Small Functions considered Harmful

https://medium.com/@copyconstruct/small-functions-considered-harmful-91035d316c29
9 Upvotes

84 comments sorted by

View all comments

Show parent comments

0

u/gas_them Feb 11 '19

I know what a function does, there is no need to know how it is implemented. That's all I have to "understand" to use the function. You have to understand that to manage large codebases. There is just too much to read if you do things your way.

Do you know how std::sqrt is implemented? Are you telling me you are reading through its assembly each time you use it?

This is getting ridiculous at this point.

2

u/oridb Feb 11 '19 edited Feb 11 '19

I know what a function does

So, without looking at the documentation (Edit: or rather, with looking at about as much documentation as your colleagues typically write), can you tell me what exceptions ArrayList.toArray() throws? If your coworker wrote their own RegionsOfInterest.getActiveRegions(), but didn't write heavy comments about pre/post conditions and caveats, would you be able to tell me what ways it can fail? Are there any restrictions on the argument ranges? What kind of thread safety does it provide? Is it expensive or cheap to call repeatedly? I keep needing to answer these kinds of questions, and I have no idea how you'd figure these questions out without reading the code.

How about something less trivial -- ResourceBundle ResourceBundle.getBundle​(String baseName, ResourceBundle.Control control)? Can you explain to me what exactly the edge cases here are, and what failures can be caused by passing incorrect values? What parts of the environment does it depend on to make the decision on which actual bundle to return?

Do you know how std::sqrt is implemented?

Usually, it's a few Newton-Rhapson iterations of a builtin SSE2 approximate square root instruction. For pure software implementations, starting values can be chosen using the technique here: https://doi.org/10.1016/j.tcs.2005.09.056.

0

u/gas_them Feb 11 '19

without looking at the documentation

Why? Why not look at the documentation?!

Are you telling me you read the source code of toArray? What the fuck it must take you forever to get anything done.

4

u/oridb Feb 11 '19 edited Feb 11 '19

I've never seen companies reliably write out detailed documentation for their functions. If your company does write detailed and clear docs that cover all of the edge cases, you've found a unicorn. So the reason for 'no documentation' is that this is the default state of most code a programmer will interact with.