Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Confused about dating site scenario
In the dating site scenario Craig states that Heidi wants to meet someone with kids but does not want someone who smokes.
Therefore if someone is "not is_smoker" then wouldn't that suit her needs? However the code returns a False.
If you look at it like;
has_kids and is_smoker
Then the code would return True
However Heidi does not want to meet a smoker so it wouldn't be a match for her, and True wouldn't really be accurate.
Wouldn't this be more suitable;
non_smoker = True
has_kids = True
non_smoker and has_kids
not non_smoker and has_kids
Am I missing something here?
I think you're understanding everything pretty well, actually, but you're caught on the variable names, which is completely understandable. Naming things is one of the hardest parts of programming, and your confusion is a perfect example as to why.
If the hypothetical site Craig is referencing was ONLY for matching people with Heidi, then it might make sense to name everything around what Heidi prefers to keep things simple. Heidi prefers non_smokers, so on heididates.com it would make sense to name it non_smoker. That way when heidi fills out her preferences, she'd say non_smokers and has_kids, and the logic on her end would be really simple.
But for most every programming problem, solutions aren't for just one person or example. When making a site like exampledate.com that matches millions of different people on millions of different dates, it makes a lot more sense to name all the variables as Truthy by default. That way we don't have to think too much about "should this boolean variable be true or false by default, and what does that mean?". So, in the wild, you're much more likely to see "is_something" or "has_something" than "non_something" or "missing_something". In the grand scheme of things, it's easier to reason about.
So, in Craig's example, Joe would fill in True for is_smoker and True for has_kids in his dating profile, and Heidi would fill out not is_smoker and has_kids as her preferences. Naming things is hard, but generally it's best to name boolean values from the perspective of Truthy. I hope that helps, good question!
fahad lashari7,693 Points
the 'not is_smoker' basically means check and tell me if is_smoker = True, if is_smoker = True then return false.
In the real world the person filling out the application will answer true or false to whether they are a smoker and their answer will be assigned to the variable is_smoker.
So Heidi wants someone with kids and a non smoker so her application has:
has_kids = True is_smoker = False
and the other person has:
has_kids = True is_smoker = True
so when we do has_kids and not is_smoker, Heidi's profile requirements check the other person's profile and it will return True for has_kids and True for is_smoker but by saying 'not is_smoker' we want someone who's profile doesn't have is_smoker = true hence why it returns false. Hope that helps.
I know it can be confusing but after a few read time you read it, you'll start to grasp it. It took me a few read throughs. I I do agree that it should have been explained abit more in the video.