3 ms·
In my old age I use comments to write my code before I write the code. The comments explain in pseudo code what Im trying to accomplish. # check to see if the
by achenatx 7y ago
In my old age I use comments to write my code before I write the code. The comments explain in pseudo code what Im trying to accomplish.
# check to see if the user has a cart. The default state for
# users is to not have a cart. The original implementation
#created a cart for every visitor which resulted in 10s of
#thousands of unused carts.
# if the cart does not exist only create a new one because
# they are adding an item. You can never assume the user has
# a cart.
as I read code that isnt mine and figure out what it does, I write comments like the above about why I think it works that way. I will sometimes date the comments. You can do that with your own code as you make modifications or additions. It adds minimal overhead and is tremendous for when you go back later.
For a check like if i > 5 then do something I have seen comments like "check for i>5" which is obvious. I would want something like
# Im hardcoding a 5 here because <bad reason> so that when
#<whatever I represents is > 5 then we do <some stuff>