3 ms·
Did you ever need to do involved mathematical manipulations using pen and paper? How would you judge the readability of the following expressions: zero_point
by cygx 4y ago
Did you ever need to do involved mathematical manipulations using pen and paper? How would you judge the readability of the following expressions:
zero_point equals negative prefactor divided_by two plus_or_minus square_root_of( square_of(prefactor divided_by two) minus absolute_term )
zero_point = -prefactor/2 ± √((prefactor/2)² - absolute_term)
x = -p/2 ± √((p/2)² - q)
- hutzlibu 4y agoYeah, when doing it with hand, I surely would shorten it. But when doing math on the computer with help of autocomplete, why not? But well, I do not really know if that in pure math shape exists, I am only doing Math in the context of programming. And for pedagogic purposes, I do would like more meaningful names at times.
- kortex 4y agoIt's definitely a lot harder to read and make sense of an equation that is sprawled out. In some domains, I would contend that using greek letters in code would increase readability, especially for those familiar with the underlying formula, and especially if the code is not edited frequently (e.g. implementing a scientific formula which won't change). A good compromise might be to put the equation in the comments in symbol-heavy form, and use the spelled out names in code.
- dan_mctree 4y agoI might be strange but the second seems far more readable than the third to me. The first is of course nonsense.
- cygx 4y agoIn my opinion, it puts too much emphasis on the variables compared to the operators and numbers and makes the expression as a whole harder to parse at a glance as I have to actually read the names.