-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Indentation
The whole idea behind indentation is to clearly define where a block of control starts and ends.
Especially when you've been looking at your screen for 20 straight hours, you'll find it a lot easier to see how the indentation works if you have large indentations.
Use tabs
to indent your code.
Tabs characters will be counted as 1
character by Betty
.
The preferred way to ease multiple indentation levels in a switch statement is to align the switch
and its subordinate case
labels in the same column instead of double-indenting
the case
labels.
E.g.:
int sample_func(char suffix)
{
int var;
var = 0;
switch (suffix)
{
case 'G':
case 'g':
var = 30;
break;
case 'M':
case 'm':
var = 20;
break;
case 'K':
case 'k':
var = 10;
default:
break;
}
return (var);
}
Don't put multiple statements on a single line:
if (condition) do_this;
do_something_everytime;
Don't put multiple assignments on a single line either.
Betty coding style is super simple.
Outside of comments and documentation, spaces are never used for indentation, and the above example is deliberately broken.
Get a decent editor and don't leave whitespace at the end of lines.
0.1 - Betty-style usage
0.2 - Betty-doc usage
0.3 - References
1.1 - Indentation
1.2 - Breaking long lines and strings
1.3 - Placing Braces
1.4 - Placing Spaces
1.5 - Naming
1.6 - Functions
1.7 - Commenting
1.8 - Macros and Enums
1.9 - Header files
2.1 - Functions
2.2 - Data structures
3.1 - Emacs
3.2 - Vim
3.3 - Atom