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 ... |
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.