Skip to content

Instantly share code, notes, and snippets.

@jfdm
Created September 21, 2018 14:25
Show Gist options
  • Select an option

  • Save jfdm/5af62bf15c3f5eafb317053bb7ce8538 to your computer and use it in GitHub Desktop.

Select an option

Save jfdm/5af62bf15c3f5eafb317053bb7ce8538 to your computer and use it in GitHub Desktop.
Summing up the good and the bad of dynamic typing and a programmer's mental model.
class Tree():
pass
class Node(Tree):
def __init__(self,l,r,value):
self.l = l
self.r = r
self.value = value
class Leaf(Tree):
def __init__(self):
pass
def toString(t):
if (isinstance(t,Node)):
return "({0},{2},{1})".format(toString(t.l),toString(t.r),str(t.value))
elif (isinstance(t,Leaf)):
return "()"
else:
return "Neither a Node or a Leaf"
myTree = Node(Leaf(),Leaf(),1)
print toString(myTree)
myTree = Node(Leaf(),"ss",1)
print toString(myTree)
myTree = Node("AAA",Leaf(),1)
print toString(myTree)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment