←back to thread

361 points mmphosis | 6 comments | | HN request time: 1.739s | source | bottom
Show context
leetrout ◴[] No.42165704[source]
> It's better to have some wonky parameterization than it is to have multiple implementations of nearly the same thing. Improving the parameters will be easier than to consolidate four different implementations if this situation comes up again.

Hard disagree. If you cant decompose to avoid "wonky parameters" then keep them separate. Big smell is boolean flags (avoid altogether when you can) and more than one enum parameter.

IME "heavy" function signatures are always making things harder to maintain.

replies(17): >>42165868 #>>42165902 #>>42166004 #>>42166217 #>>42166363 #>>42166370 #>>42166579 #>>42166774 #>>42167282 #>>42167534 #>>42167823 #>>42168263 #>>42168489 #>>42168888 #>>42169453 #>>42169755 #>>42171152 #
1. arccy ◴[] No.42166363[source]
+1, have 2 implementations that each have an independent branch point? if you combine them you have a function with 2 bool parameters, and 4 possible states to test, 2 of which you might never need
replies(4): >>42167501 #>>42168511 #>>42170578 #>>42187714 #
2. hinkley ◴[] No.42167501[source]
It’s difficult to convince people that once you consider the testing pyramid, it’s not just 2 + 2 + 2 < 2 x 2 x 2 but also 2 + 2 < 2 x 2
replies(1): >>42168010 #
3. silvestrov ◴[] No.42168010[source]
"The greatest shortcoming of the human race is our inability to understand the exponential function”.

https://en.wikipedia.org/wiki/Albert_Allen_Bartlett

4. Aeolun ◴[] No.42168511[source]
There’s ways to write this that still keep the entrypoint to a single function. Having different function names as your parameters doesn’t make them any less so.
5. cma ◴[] No.42170578[source]
A very common one is two booleans with one combination of them being an invalid state (e.g. never are both bools true in a valid state but all can be false or a mixture). Use an enum instead that represents only the three valid cases.
6. somethingsome ◴[] No.42187714[source]
Combinatorial explosion of states is a nightmare, IME it means that the abstraction behind is not the right one.

You really don't want to have a function that branches a lot inside. It's very difficult to test.

When you think of adding a flag, run in your head 2^n, this will give you the least number of tests needed. Do you really want to write all of them?