Created
September 21, 2018 14:25
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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