3 ms·
I disagree that FP and OOP are the only abstraction methods. Arithmetic can be an excellent abstraction method. For me, it's a code smell to have a function ca
by BrandonM 12y ago
I disagree that FP and OOP are the only abstraction methods. Arithmetic can be an excellent abstraction method.
For me, it's a code smell to have a function called "updateScore4". It's often possible to come up with an algebraic statement that gives the same result as a bunch of logic (code paths).
I think userbinator's point is that better code is easier to test as a result of having fewer code paths. Of course there are some gotchas to be aware of (e.g., overflow), but overall I agree.
- nawitus 12y agoOn the other hand, you can "hide" the different code paths in a single algebraic statement, but even if your tests always execute that statement, you've lost information that you've actually tested the both "paths" of the algebraic statement. I guess it's easier to use a boolean logic example (in JavaScript): return myNormalObject || myDefaultObject(); Your code might always execute the myNormalObject half and return it, and even though your code coverage is 100% of the lines, your tests might miss myDefaultObject() code path. Perhaps some code coverage tools can take this into consideration, though, but then you're back to the original problem..
- BrandonM 12y agoThat's not arithmetic, though. That's logic represented as a one-liner... Not the sort of change I'm talking about.
- judk 12y agoMost real world problems need extra logic attached to each case of the conceptually simple arithmetic. All of coloring is just arithmetic, after all, but is rather complex
- Dewie 12y ago> I disagree that FP and OOP are the only abstraction methods. Arithmetic can be an excellent abstraction method. Arithmetic in programming is typically about functions taking in numbers and returning new numbers, ie. returning a new number instead of mutating one of the numbers in-place. That sounds like the spirit of FP, to me. (Though of course arithmetic on fixed-size numbers falls short of this ideal when it comes to overflow and such, and we often don't handle this possibility.) I don't doubt that there are other abstractions than FP and OOP. But arithmetic looks like FP, to me.
- BrandonM 12y ago> I don't doubt that there are other abstractions than FP and OOP. But arithmetic looks like FP, to me. When aikah said "FP", I took that to mean something like using a higher-level "updateScore" function that accepts a "calculateScore" function as an argument. I certainly may have been mistaken, though.