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

I disagree. Well written and abstracted code makes mathematical formulas easy to scan and proofread.

Your code should look like this:

    angle = acos( ( a . b ) /
                  (|a|*|b|) )
If it looks like this . . .

    angle2 = Math.acos((a.x*b.x + a.y*b.y + 
      a.z*b.z)/Math.sqrt(a.x*a.x + a.y*a.y + 
      a.z*a.z)*Math.sqrt(b.x*b.x + b.y*b.y + 
      b.z*b.z))
. . . you're likely to miss the error*

Bad code compiles. Good code works right. Great code is so obviously right you don't have to wonder.

*Those are the same formula, though the second one is missing some critical parentheses. I use the example because I have done exactly this and been bitten by exactly this, and now am fanatical about keeping my mathematical formulas clean and obvious.



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

Search: