O'Reilly logo

New Programmer's Survival Manual by Joshua D. Carter

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Tip 6Be Stylish
White Belt[​​White Belt] Writing code with good style helps well before the professional world.

These two functions do exactly the same thing:

Fibonacci.c
 
uint64_t
 
fibonacci(​unsigned​ ​int​ n)
 
{
 
if​ (n == 0 || n == 1) {
 
return​ n;
 
}
 
else​ {
 
uint64_t previous = 0;
 
uint64_t current = 1;
 
 
while​ (--n > 0) {
 
uint64_t sum = previous + current;
 
previous = current;
 
current = sum;
 
}
 
 
return​ current;
 
}
 
}
Fibonacci.c
 
unsigned​ ​long​ ​long​ fbncci(​unsigned​ ​int​ quux) { ​if
 
(quux == 0 || quux == 1) { ​return​ quux; } ​else​ {
 
unsigned​ ​long​ ​long​ foo = 0; ​unsigned​ ​long​ ​long​ bar
 
= 1; ​while​ (--quux ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required