Rules for Programmers.
Learn them. Love them. Live them.
Rule #1: Clarity Trumps Everything
Rule #2: Source Code is for Humans
Rule #3: Don’t Ignore Warnings
Rule #4: Comment As You Go
Rule #5: Always Use Parentheses
And…
Always Use Less-Than
The Thing About Constants (this should be a rule!)
Always Implement toString
The Synchronization Problem
Regular Expressions
See Also…
Four Principles for Programmers
The Universal Answer
Software Engineer
Computer Programming is Hard!
Getting to the Next Hill
HTML is not a Programming Language!
I confess to some confusion about what’s a Rule and what’s just really good advice you should follow. Sort of, more or less, the Rules apply to generally how you go about your business whereas the others (under “And…”) apply more to specific coding situations.
Sort of.
Whatever.
Stay tuned; more to come!
Trying a little experiment:
fib series: 0 1 1 2 3 5 8…
definition: fib(n) = fib(n-1) + fib(n-2)
exceptions: fib(0) = 0; fib(1) = 1
”’
def fib (n, lst=None):
if not lst:
return fib(n, [0, 1])
if len(lst) < 2:
lst.append(lst[0]+1)
ix = len(lst) – 1
c = lst[ix] + lst[ix–1]
lst.append(c)
if n <= len(lst):
return lst
return fib(n, lst)
ns = fib(42)[1:]
print(ns)
print()
My little home-baked Python-2-HTML function.
It also comes with line numbers:
001|
001| fib series: 0 1 1 2 3 5 8…
001|
001| definition: fib(n) = fib(n-1) + fib(n-2)
001| exceptions: fib(0) = 0; fib(1) = 1
001| ”’
002| def fib (n, lst=None):
003| if not lst:
004| return fib(n, [0, 1])
005| if len(lst) < 2:
006| lst.append(lst[0]+1)
007| ix = len(lst) – 1
008| c = lst[ix] + lst[ix–1]
009| lst.append(c)
010| if n <= len(lst):
011| return lst
012| return fib(n, lst)
013|
014| ns = fib(42)[1:]
015| print(ns)
016| print()
017|