Same as the `widthInPixels` example really, but my pet peeve is always around units of time. Don't comment that `timeout` variable, just rename it `timeoutMillis`, `timeoutSecs`, or whatever it is.
If possible in your language, I'd say that you should also replace name by types: using the name widthInPixels won't help you if you do widthInPixels = widthInMilimeter, but a strong type would prevent this.
A good point, but I'd like to add that the bigger the visibility scope of a variable, the more relevant this advice is. In method scope you will be perfectly fine with a primitive type and a descriptive name. In a bigger scope you might consider hiding the type as the implementation detail.
Even better if you are using something like F#, which has the concept of units built into the language, so you can't mistakenly add feet and centimeters together without converting first.
Same as the `widthInPixels` example really, but my pet peeve is always around units of time. Don't comment that `timeout` variable, just rename it `timeoutMillis`, `timeoutSecs`, or whatever it is.
返信削除And using the correct type. Why using an int for timeout if you could use a TimeSpan? It exposes the unit of time directly at the moment you use it.
削除If possible in your language, I'd say that you should also replace name by types:
返信削除using the name widthInPixels won't help you if you do widthInPixels = widthInMilimeter, but a strong type would prevent this.
A good point, but I'd like to add that the bigger the visibility scope of a variable, the more relevant this advice is. In method scope you will be perfectly fine with a primitive type and a descriptive name. In a bigger scope you might consider hiding the type as the implementation detail.
削除Amen, Jay. Timeouts should be described in their units and this should extend all the way to the user interface/command line.
返信削除All real-world physical quantities should be described or typed with their units.
Even better if you are using something like F#, which has the concept of units built into the language, so you can't mistakenly add feet and centimeters together without converting first.
削除Great advice! It's all about explaining the why, because code can often hide that.
返信削除Thanks for the excellent blog post.
Also, could you add the Code Health label to this? So it shows up with the other Code Health posts? Seriously loving this series.
Done! Thanks for the heads up!
返信削除i think the timeoutMillis`will be more perfect .
返信削除This is really helpful and awesome practice to comment only when it is really required.
返信削除