Semantics discussion: Chapter 5 Challenge


#1

My buddy and I both solved the challenge independently, however, he used a solution highly specific to the question:

a + b = 90

Whereas I used a simple, but proper mathematical principle to solve the trig problem in the question:

180 - (a + b) = 90

In this case, both solutions return AngleC = 90. His solution is the shortest way to the answer to this specific question: angleA + angleB happens to equal to 90. I can see the value of the simplest solution, obviously you’d want your code to be lean and simple. However, I believe we should be using proper math and making our code versatile instead of just answering a single question. His reasoning for my coding being convoluted: the “180 -” is wrong because it adds an extra step to the code.

I’d like someone with extensive coding work experience to weigh in on this. Is there an industry standard that suggests we should be using the shortest possible solution?

If this is a subtle way the authors intended to teach us shortest solutions are the best or intended to lead to posts like these, it’s brilliant. Otherwise, the sum of the first two angles leading to 90 is somewhat ambiguous; it leaves room for an (admittedly interesting) discussion on semantics of the mathematical validity of the code we write.