|
The definitive guide to whitespace, part 1
|
|
Posted by: stak
Tags: code, whitespace
Posted on: 2009-03-10 23:17:14
Part 1: method invocations
The rules
- Arguments in favor or against any of the options must not be based on subjective viewpoints (e.g. "it looks prettier").
- Mention of languages that do not follow a C-style syntax is strictly prohibited (to avoid flame wars).
The options
optionA(foo, bar, func(baz));
optionB( foo, bar, func( baz ) );
optionC (foo, bar, func (baz));
The arguments
Option A is the shortest, requiring the least amount of typing, and fastest compilation time.
Options A and B have no whitespace before the opening parenthesis, therefore requiring a shorter search string when looking for instances of the method invocations (i.e. grep "optionA(" instead of grep "optionA (").
Option B is most convenient for manipulation via a tool (such as a naive code preprocessor), since useful tokens can be obtained by splitting the code on whitespace. Option A would return things like "optionA(foo," which are less useful than "optionB(" and "foo," separately.
The conclusion
To be determined once y'all weigh in with additional options and arguments.
|
|
(c) Kartikaya Gupta, 2004-2024. User comments owned by their respective posters. All rights reserved.
You are accessing this website via IPv4. Consider upgrading to IPv6!
|
Some will argue extra whitespace in OptionB makes for better readability. They are wrong. Again, when I read it quickly, it fails to semantically group arguments. The call to func just looks ridiculous.
So OptionA is the only one that makes any sense.
I am using my background in typography when I say "semantically". Unexpected whitespace is cognitively jarring. No one would write English like OptionB, and in OptionC, the space between the name of the function and the items in parentheses indicates a separation of ideas, which is what you don't want.
Isn't everyone taught OptionA anyway?