Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Programming style
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Whitespace === A [[free-format language]] ignores [[whitespace character]]s: spaces, tabs and new lines so the programmer is free to style the code in different ways without affecting the meaning of the code. Generally, the programmer uses style that is considered to enhance [[readability]]. The two code snippets below are the same logically, but differ in whitespace. <syntaxhighlight lang="c"> int i; for(i=0;i<10;++i){ printf("%d",i*i+i); } </syntaxhighlight> versus <syntaxhighlight lang="c"> int i; for (i = 0; i < 10; ++i) { printf("%d", i * i + i); } </syntaxhighlight> The use of [[Tab key|tabs]] for whitespace is debatable. Alignment issues arise due to differing tab stops in different environments and mixed use of tabs and spaces. As an example, one programmer prefers [[tab stop]]s of four and has their toolset configured this way, and uses these to format their code. <syntaxhighlight lang="c"> int ix; // Index to scan array long sum; // Accumulator for sum </syntaxhighlight> Another programmer prefers tab stops of eight, and their toolset is configured this way. When someone else examines the original person's code, they may well find it difficult to read. <syntaxhighlight lang="c"> int ix; // Index to scan array long sum; // Accumulator for sum </syntaxhighlight> One widely used solution to this issue may involve forbidding the use of tabs for alignment or rules on how tab stops must be set. Note that tabs work fine provided they are used consistently, restricted to logical indentation, and not used for alignment: <syntaxhighlight lang="cpp"> class MyClass { int foobar( int qux, // first parameter int quux); // second parameter int foobar2( int qux, // first parameter int quux, // second parameter int quuux); // third parameter }; </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)