Tip 6 | Be Stylish |
[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 ... |
Get New Programmer's Survival Manual now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.