ddhr.org | 2020 | 03 | 02 about | archives | comments | rss

Code quality and comments Mon, Mar 02, 2020
I think well-written, good quality code can forego the need for comments.  I'll admit most of the code I've written up to this point has neither been high quality nor well commented.  I'm trying to change that.  Here's something I wrote a few years ago to calculate the acceleration of gravity at a certain altitude: 

out.gr = 9.8066504*(6356766/(6356766+atmo.alt+pos(2)))^2;

There's a bunch of repeated numbers in there, and a whole bunch of parentheses.  It's hard to follow what's going on without writing it down.  Also, no comments.  I redid that code recently, and here's the same calculation, spaced out a little, and with a few minimalist comments: 

standard_gravity = 9.8066504; % [m/s^2]

earth_radius = 6356766; % [m]

local_gravity = standard_gravity*(earth_radius / (earth_radius+geometric_altitude))^2; % [m/s^2]

← older post 3054 of 3071 newer →