Skip to content

grade-school: Force const on roster() and grade() - #287

Merged
arcuru merged 2 commits into
exercism:masterfrom
siebenschlaefer:grade-school-const-correctness
Sep 14, 2019
Merged

arcuru merged 2 commits into
exercism:masterfrom
siebenschlaefer:grade-school-const-correctness

Conversation

@siebenschlaefer

Copy link
Copy Markdown
Contributor

Currently school::roster() and school::grade() can be implemented as
non-const methods. Logically it makes sense to be able to call those two
methods on a const instance because they should not modify that
instance.

Currently school::roster() and school::grade() can be implemented as
non-const methods. Logically it makes sense to be able to call those two
methods on a const instance because they should not modify that
instance.
@siebenschlaefer

Copy link
Copy Markdown
Contributor Author

I accidentally deleted my previous (identical) PR.

@arcuru

arcuru commented Jun 2, 2019

Copy link
Copy Markdown
Contributor

The CI is failing because of this. We test against Clang 3.8 since last I checked it was still the default in something (probably an Ubuntu LTS build, 16.XX?). For now we should support that until we update the compilers, so you'd need to add a default constructor to the example.

I would suggest actually adding a brief comment to the added constructor to explain why there is otherwise unnecessary code.

This is a good change though :)

@siebenschlaefer

Copy link
Copy Markdown
Contributor Author

Good catch!
I could add a defaulted default constructor (as you suggested) or I could could use value initialization for those three const grade_school::school instances (see https://godbolt.org/z/Mrx2uh).
Which do you prefer?

@arcuru

arcuru commented Jun 2, 2019

Copy link
Copy Markdown
Contributor

Wow that's...interesting. Let's do value initialization as you suggested so we don't force the students to deal with that.

@arcuru arcuru mentioned this pull request Jun 22, 2019
@arcuru
arcuru merged commit 30bcd97 into exercism:master Sep 14, 2019
@siebenschlaefer
siebenschlaefer deleted the grade-school-const-correctness branch January 31, 2020 11:31
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