-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring Part 1 Updated #66
Refactoring Part 1 Updated #66
Conversation
Refactoring Part 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work, some suggestions on adding in guard clauses to ensure that a user gets a specific error message later on. 🎉
group = { | ||
"Jill": { | ||
"age": 26, | ||
"job": "biologist", | ||
"relations": { | ||
"Zalika": "friend", | ||
"John": "partner" | ||
} | ||
}, | ||
"Zalika": { | ||
"age": 28, | ||
"job": "artist", | ||
"relations": { | ||
"Jill": "friend", | ||
} | ||
}, | ||
"John": { | ||
"age": 27, | ||
"job": "writer", | ||
"relations": { | ||
" Jill": "partner" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Now the group won't be loaded if you imported the file which means you're not including uncessary variables in your module
@@ -16,7 +16,8 @@ def add_connection(self, person, relation): | |||
|
|||
def forget(self, person): | |||
"""Removes any connections to a person""" | |||
pass | |||
if person in self.connections: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that you've made sure that they exist, in our example we've thrown a specific exception here but this is also another sensible way to deal with it
@@ -32,17 +32,30 @@ def add_person(self, name, age, job): | |||
|
|||
def number_of_connections(self, name): | |||
"""Find the number of connections that a person in the group has""" | |||
pass | |||
return len(self.connections[name]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also add in a guard clause here so that we give a more specific error messge to the user
return len(self.connections[name]) | |
if not self.contains(name): | |
raise ValueError(f"I don't know about {name}.") | |
return len(self.connections[name]) |
|
||
def connect(self, name1, name2, relation, reciprocal=True): | ||
"""Connect two given people in a particular way. | ||
Optional reciprocal: If true, will add the relationship from name2 to name 1 as well | ||
""" | ||
pass | ||
if not name1 in self.connections: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also could have a guard clause here to check that we know about these people
if not name1 in self.connections: | |
if not self.contains(name1): | |
raise ValueError(f"I don't know who {name1} is.") | |
if not self.contains(name2): | |
raise ValueError(f"I don't know who {name2} is.") | |
if not name1 in self.connections: |
Answers UCL-COMP0233-2022-2023/RSE-Classwork#51