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

Operators exercise #439

Open
chavid opened this issue Mar 8, 2023 · 8 comments
Open

Operators exercise #439

chavid opened this issue Mar 8, 2023 · 8 comments
Labels

Comments

@chavid
Copy link
Contributor

chavid commented Mar 8, 2023

A very good support to discuss the design of a class... but obviously too hard for beginners who never wrote a single class. And I take each time 2 hours to complete it, which prevent from trying other exercices. I would make few suggestions:

  • split in two exercices:
    • in the first one, we just learn to create a class with constructors, private attributes, accessors, and externals functions such as multiply, add, compare, print.
    • in the second one, we replace with +, *, ==, and we add !=, =, +=, *=.
  • provide in the original code the normalize() function and std::gcd stuff. thatś not the purpose to loose time with this.
  • make them implement operators as external functions, relying on accessors, and do not discuss the option of implementing them as members, or friend functions. Beginners are not mature enough to understand this. better if they have time to play with tools and polymorphism, etc.
  • do not talk about chaining =, +=. do it only for <<, it is largely hard enough for beginners. again, better if they have time to play with tools and polymorphism, etc. Or clearly advertise it as a final advanced optional step.
@chavid
Copy link
Contributor Author

chavid commented Mar 8, 2023

I may work on a proposal later on, if you wish.

@bernhardmgruber
Copy link
Contributor

I would like to add, that we should prefill the class declaration with two data members for numerator and denominator, probably as int. I had a few students implementing the class with a float.

Furthermore, I think we could remove operator+ and operator+=, or move them to the back as bonus exercises.

@bernhardmgruber
Copy link
Contributor

My improvements are up here: #442

@bernhardmgruber
Copy link
Contributor

obviously too hard for beginners who never wrote a single class.

Right. I think we should therefore have an exercise before where the students design their own (simple) class, like you say below.

  • in the first one, we just learn to create a class with constructors, private attributes, accessors, and externals functions such as multiply, add, compare, print.

It does not need to be a Fraction class. It can be anything! We could also cover this as part of the polymorhism exercise, by asking the students to add a new class to the hierarchy.

  • provide in the original code the normalize() function and std::gcd stuff. thatś not the purpose to loose time with this.

Agreed, part of #442.

  • make them implement operators as external functions, relying on accessors, and do not discuss the option of implementing them as members, or friend functions. Beginners are not mature enough to understand this. better if they have time to play with tools and polymorphism, etc.

The exercise leaves it open how to implement the operators, by design. There is also no need to explain how hidden friends work. Students would only know if they looked at the solution, which they should not :)

  • do not talk about chaining =, +=. do it only for <<, it is largely hard enough for beginners. again, better if they have time to play with tools and polymorphism, etc. Or clearly advertise it as a final advanced optional step.

I removed the chaining of operator*= as well.

@chavid
Copy link
Contributor Author

chavid commented Mar 8, 2023

Starting with a Fraction class would have the benefit that when they move later on to operators exercise, they are already familiar with the use case. I would not put this in polymorphism, cause I prefer to keep inheritance away when they try their first class.

@chavid
Copy link
Contributor Author

chavid commented Mar 8, 2023

Yet their first class may be inspired by polymorphism. For example provide a Pentagon and ask them to write an Hexagon, with no base class and no inheritance at the beginning... Well, as you prefer. Both have different benefits.

@bernhardmgruber
Copy link
Contributor

An additional difficulty is that the operators exercise is also used in the advanced course. It has two audiences. We could try to make some "more difficult" parts optional, or add an extra second part that is only used in the advanced course.

Copy link

stale bot commented Mar 8, 2024

This issue or pull request has been automatically marked as stale because it has not had recent activity. Please manually close it, if it is no longer relevant, or ask for help or support to help getting it unstuck. Let me bring this to the attention of @klieret @wdconinc @michmx for now.

@stale stale bot added the stale label Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants