Skip to content
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

Closed

Conversation

anda-raluca
Copy link

@anda-raluca
Copy link
Author

Refactoring Part 2
Answers UCL-COMP0233-2022-2023/RSE-Classwork#52

Copy link

@stefpiatek stefpiatek left a 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. 🎉

Comment on lines +23 to +44
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"
}

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:

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])

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

Suggested change
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:

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

Suggested change
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:

@stefpiatek stefpiatek closed this Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants