Skip to content

Object-oriented: Add simpler examples, update quiz and exercises #249

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

Merged
merged 17 commits into from
Nov 15, 2024

Conversation

despadam
Copy link
Contributor

@despadam despadam commented Oct 22, 2024

As seen in #239, there were no bugs/errors reported for this notebook. So we proceed with just adding a few simpler exercises. More specifically, we add Examples 1,2,3,4 - one per each theoretical part, so that participants can practice while studying. Then, all exercises of greater difficulty have been moved to the end of the notebook.

@despadam despadam linked an issue Oct 22, 2024 that may be closed by this pull request
@despadam despadam marked this pull request as ready for review November 5, 2024 09:25
@despadam despadam self-assigned this Nov 5, 2024
@despadam despadam added the upcoming tutorial Stuff to work on/fix before the next tutorial label Nov 5, 2024
@despadam despadam changed the title Object-oriented: Add simpler exercises Object-oriented: Add simpler exercises Nov 5, 2024
@despadam despadam marked this pull request as draft November 5, 2024 13:38
@despadam
Copy link
Contributor Author

despadam commented Nov 8, 2024

Also added docstrings in every solution function.

@despadam despadam marked this pull request as ready for review November 8, 2024 09:27
Copy link
Collaborator

@Snowwpanda Snowwpanda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new examples are great. Much more intuitive. Only one change I would make to check the full_name method.

Then things you didn't actually change but it may make sense to rewrite the old exercises more similar to the new examples, e.g. also return the object for better testing and I didn't like the quiz too much, i thought the answers could have been clearer.

Copy link
Member

@edoardob90 edoardob90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from addressing Example 2's test, I have a comment about the quiz:

Q1: __str__ and __repr__

We should say that "__str__ can be used as __repr__" because they are technically independent.

Q1: Which statement best describes the relationship between __str__ and __repr__?
1. They are independent methods with no relationship to each other
2. __str__ is used as a fallback when __repr__ is missing
3. __repr__ is used as a fallback when __str__ is missing

And (3) is the correct one.

Q3: @property

I would change the correct one to "@property creates attributes that act like methods but can be accessed and assigned as regular attributes."

To be able to "set" property attributes, we must user the @attribute.setter decorator as well, otherwise Python raises an AttributeError.

Also: why using property restricts the dynamic behavior? We could define or change another attribute on-the-fly:

class Circle:
    def __init__(self, radius):
        self.radius = radius
    
    @property
    def area(self):
        self._area = 3.14 * self.radius * self.radius # dynamic, I would say
        return self._area

So perhaps rephrase "dynamic" and don't mention attribute setting because we don't talk about setters in this notebook.

@edoardob90
Copy link
Member

It seems there a lot to fix in this notebook, but it's just that's a tricky topic. Thanks for all the fixes, addition, changes @despadam!

@despadam despadam changed the title Object-oriented: Add simpler exercises Object-oriented: Add simpler examples, update quiz and exercises Nov 13, 2024
@despadam
Copy link
Contributor Author

Hey @Snowwpanda & @edoardob90 , thanks for your detailed reviews so far! I finished all changes I wanted to make, so I now ask you for another (hopefully final) review.

I deliberately left Exercise 4 as is and did not add validation in the testing, just because I consider it different than the other exercises. That is why it is the only one marked with a 🌶️ now. I would like to leave users free to interpret it / develop it as they wish, instead of thoroughly testing it - and hopefully let them have fun 😃

@despadam despadam dismissed stale reviews from edoardob90 and Snowwpanda November 15, 2024 10:48

Has been addressed.

edoardob90
edoardob90 previously approved these changes Nov 15, 2024
Copy link
Member

@edoardob90 edoardob90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, we're good to go! 🚀 👏🏻

Copy link
Member

@edoardob90 edoardob90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now is the right one! 💯 I let @despadam push the button 😉

@despadam despadam merged commit 9240a6d into main Nov 15, 2024
1 check passed
@despadam despadam deleted the 239-update/object-oriented branch November 15, 2024 17:14
edoardob90 added a commit that referenced this pull request Nov 20, 2024
* UI revamp WIP

* `Object-oriented`: Add simpler examples, update quiz and exercises (#249)

* add 2 new examples

* finish new examples

* finish new examples pt2

* update new examples with docstrings and improved tests

* add docstrings

* finish docstrings

* make sure that class methods are only using the class attributes to produce their results

* test that the return value is an instance of a custom class

* use closure to check for usage of class attributes

* update property section and quiz

* Expand docstring description of Exercise 4

* finish updating the exercises

* Minor changes

* Stupid metadata fix of the ipython notebook

* Fixing

* Replacing variable l: E741 Ambiguous variable name: `l`

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: edoardob90 <edoardob90@gmail.com>
Co-authored-by: Snowwpanda <pascal.su@empa.ch>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Revamp UI of AI widgets

* Resolve flake8 errors

* Fix more UI inconsistencies

* Fix test in Object-Oriented Example 4 (#262)

* Add __eq__ validation in Example 4
* Add a comment to explain the rationale behind __closure__ testing

---------
Co-authored-by: edoardob90 <edoardob90@gmail.com>

* Fix errors found in the `input_output` notebook (#258)

* Fixing some issues with the input_output notebook
and changing some exercies a bit.

* Added an exercise to input_output notebook

* Added Docstrings to exercises

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Changes for pre-commit

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Variable naming consistent in tests.

* Reformulation program execution

Co-authored-by: Despina Adamopoulou <16343312+despadam@users.noreply.github.com>

* Review from despina fixes

* Resetting inputfiles after exercises (after writing to file is explained)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* to_bytes function needs byteorder

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Despina Adamopoulou <16343312+despadam@users.noreply.github.com>

* Move quizzes to dedicated folder (#263)

* move quizes to folder
* Rename: quizes -> quiz
---------
Co-authored-by: edoardob90 <edoardob90@gmail.com>

---------

Co-authored-by: Despina Adamopoulou <16343312+despadam@users.noreply.github.com>
Co-authored-by: Snowwpanda <pascal.su@empa.ch>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upcoming tutorial Stuff to work on/fix before the next tutorial
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Errors found in the object-oriented notebook
3 participants