Readability
- john010117
-
john010117
- Member since: Feb. 26, 2007
- Offline.
-
- Forum Stats
- Member
- Level 36
- Blank Slate
Everyone has their own methods of making their code look "clean" and readable. What I do is put the curly brackets on a separate line and use tab after every opening curly brackets. But again, it's up to you.
- That-Is-Bull
-
That-Is-Bull
- Member since: Apr. 29, 2004
- Offline.
-
- Forum Stats
- Member
- Level 22
- Blank Slate
- DougyTheFreshmaker
-
DougyTheFreshmaker
- Member since: Jul. 30, 2007
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
Could someone introduced me to some widely implemented readability conventions? When parenthesis aren't necessary, what is the generally accepted use of them? Where do you place your curly braces, etc. I'm just looking to make my code as readable as possible.
You can check out this Wikipedia article dedicated to this stuff: http://en.wikipedia.org/wiki/Indent_styl e
Probably just useless trivia at best, though.
When I started wondering about stuff like this, I came across this and this. I use a different indentation style (Allman from the Wikipedia thing for the most part), but I follow the variable naming advice pretty closely (in particular the 2-word-length thing). Whatever floats your boat.
I'm not sure if it relates to what you're asking or not, but code should be self documenting. This link has a quick overview, though I don't necessarily support every word of it. In particular, pay attention to the part about naming functions and how it can help you split your code up. Functions which are too long, such as calculate_value_and_display_results(), should be split into smaller functions, such as calculate_value() and display_results(). This makes your code much more readable.
Really, being consistent with whatever style you choose to follow (or make up) is what is most important.
As far as when parentheses should and shouldn't be used... I'm not sure. I, personally, would say (keep in mind that I'm definitely no expert) that it's a judgment call on your part. If adding in a few parentheses makes it easier to read for *you*, then it'll probably make it easier for other people as well. Judiciously, though. *shrug*
We should take care not to make the intellect our god; it has, of course, powerful muscles, but no personality.
Freshmaking
Brainscrape


