Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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)


I might be strange but the second seems far more readable than the third to me. The first is of course nonsense.


In 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.


Yeah, 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.


It'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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: