Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
What is the best style for code layout in C?
What is the best style for code layout in C?
✍: Guest
While providing the example most often copied, also supply a good excuse for disregarding it:
The position of braces is less important, although people hold passionate beliefs. We have chosen one of several popular styles. Pick a style that suits you, then use it consistently.
It is more important that the layout chosen be consistent (with itself, and with nearby or common code) than that it be ``perfect.'' If your coding environment (i.e. local custom or company policy) does not suggest a style, and you don't feel like inventing your own, just copy K&R.
Each of the various popular styles has its good and bad points. Putting the open brace on a line by itself wastes vertical space; combining it with the following line makes it hard to edit; combining it with the previous line prevents it from lining up with the close brace and may make it harder to see.
Indenting by eight columns per level is most common, but often gets you uncomfortably close to the right margin (which may be a hint that you should break up the function). If you indent by one tab but set tabstops at something other than eight columns, you're requiring other people to read your code with the same software setup that you used. .
The elusive quality of ``good style'' involves much more than mere code layout details; don't spend time on formatting to the exclusion of more substantive code quality issues.
2015-05-18, 1508👍, 0💬
Popular Posts:
What is the sequence of UML diagrams in project? First let me say some fact about this question, you...
What is a delegate ? Delegate is a class that can hold a reference to a method or a function. Delega...
What is a fish bone diagram ? Dr. Kaoru Ishikawa, invented the fishbone diagram. Therefore, it can b...
.NET INTERVIEW QUESTIONS - What are Daemon threads and how can a thread be created as Daemon? Daemon...
What is the version information in XML? “version” tag shows which version of XML is used.