O.k. item FOUR ... check everything and bail on bad. What do I mean by this? I mean every time you call a function, a library routine, or whatever ... check for errors! don't mask exceptions. Anticipate "that shouldn't happen" errors.
-
Show this thread
-
If there are invariants that should hold in your program, check those too! You can pretty much never check things too much. And if things don't add up .... bail! Be very very defensive in your programming.
1 reply 1 retweet 8 likesShow this thread -
This also relates to a simple programming tip. It can be easy to fall into a pattern of ... if (condition1 == good) { ... if (condition2 == good) { ... if (condition3 == good) { do_something(); but this is bad and becomes dangerous.
1 reply 2 retweets 10 likesShow this thread -
Instead do: if (condition1 != good) { bail(); } ... if (condition2 != good) { bail(); } if (condition3 != good) { bail(); } usually makes context much clearer, avoids nesting confusion, and builds in that pattern of bailing!
1 reply 1 retweet 48 likesShow this thread -
o.k. last piece of advice and it is ... don't write "what" comments, write "why" comments. If you have to comment on what your program is doing, then the code itself was not readable! Instead use comments to provide context.
1 reply 2 retweets 29 likesShow this thread -
Use readable variable names that are nouns and meaningful function names that are verbs. The code doesn't have to be poetry, but it can absolutely be easy to follow. Give your future self an easier time. Code is written to be read.
1 reply 3 retweets 18 likesShow this thread -
Very very rarely there is code that can't be easily read; if you're using bitwise operators as part of cryptography or compression or something, for example. Comment those with a "WTF is this doing" ... be very very verbose. But that's the only exception I've found!
1 reply 2 retweets 9 likesShow this thread -
Which brings me to the $1000 programming contest! 3 prizes: $500, $300, $200 for the most readable, easy to follow, tested, Apache Software License 2.0'd, implementation of
@lemire's nearly division-less RNG.https://lemire.me/blog/2019/06/06/nearly-divisionless-random-integer-generation-on-various-systems/ …4 replies 35 retweets 71 likesShow this thread -
I hope he doesn't mind because I didn't ask! I've chosen
@lemire's algorithm because it is awesome and ground breaking, very short, and intrinsically hard to follow if you're not into the math.4 replies 1 retweet 7 likesShow this thread -
Replying to @colmmacc
This sounds like fun. Can I blog about your contest?
1 reply 0 retweets 1 like
Absolutely!
your algorithm and this is my way of getting more people to see and appreciate it, and despite being so small and simple, it's in the space of "intrinsically challenging to make understandable".
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.