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

Add cpp_demo #154

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add cpp_demo #154

wants to merge 3 commits into from

Conversation

JamesYang007
Copy link
Contributor

I'm going to go over this code in recitation. Yet another great example of classes with nontrivial constructors and destructor :D. It would be nice to get some feedback and have this merged soon so that students can refer back to it.

Copy link
Contributor

@j-hui j-hui left a comment

Choose a reason for hiding this comment

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

i think this demo is really great, but there are some aspects of it that can be streamlined, mostly for the sake of students reading this. Examples should be as minimal and instructive as possible – this is already very instructive, but could be pared down just a little so that there's less risk of confusion.

see my various inline comments; i'm neither approving nor requesting changes because while this is a fine demo, if it were up to me i would also make some changes to suit my own tastes, except it's not up to me, so i don't really get to assert own tastes, because it is in fact not my decision to be made about these tastes, therefore I am abstaining from either approving or requesting changes and taking the third option of simply making this comment, which i am currently writing, at this present moment in time, in text.

M-cpp/cpp_demo/matrix.cpp Outdated Show resolved Hide resolved
M-cpp/cpp_demo/matrix.hpp Show resolved Hide resolved
M-cpp/cpp_demo/test_tools.hpp Outdated Show resolved Hide resolved
M-cpp/cpp_demo/matrix.cpp Outdated Show resolved Hide resolved
M-cpp/cpp_demo/matrix.cpp Outdated Show resolved Hide resolved
M-cpp/cpp_demo/cpp_demo.cpp Outdated Show resolved Hide resolved
M-cpp/cpp_demo/README.md Show resolved Hide resolved
M-cpp/cpp_demo/cpp_demo.cpp Outdated Show resolved Hide resolved
M-cpp/cpp_demo/matrix.hpp Outdated Show resolved Hide resolved
M-cpp/cpp_demo/README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@lucieleblanc lucieleblanc left a comment

Choose a reason for hiding this comment

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

As a general comment, a lot of the helper functions here are beyond the scope of the class., and we don't want to black-box parts of the code. Sticking to a version with a specific set of features you want to review will be less confusing.

Keep in mind that many students who come to review sessions at this point in the semester do so because they're lost/confused, not because they want to learn extra material that will not be on the final. The existing recitation notes are a good reference for coverage.

@JamesYang007
Copy link
Contributor Author

JamesYang007 commented Nov 14, 2019

Thanks guys, after applying John's proposed changes, I think the only nontrivial functions that are maybe outside the scope are the print and operator+ in Matrix. I have no other way of showing students what the matrix looks like after doing these copy constructions, etc. without printing, so I really want to include print. I also want to include operator+ because it shows what you can do beyond basic-4 and also Jae's MyString does something similar. Any thoughts?

I have also changed the logic of my cpp_demo.cpp. I think this structure makes more sense logically.

Copy link
Contributor

@j-hui j-hui left a comment

Choose a reason for hiding this comment

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

nice changes, some nits but overall LGTM

M-cpp/cpp_demo/matrix.cpp Outdated Show resolved Hide resolved
M-cpp/cpp_demo/matrix.cpp Show resolved Hide resolved
M-cpp/cpp_demo/matrix.cpp Show resolved Hide resolved
M-cpp/cpp_demo/matrix.hpp Outdated Show resolved Hide resolved
M-cpp/cpp_demo/matrix.hpp Show resolved Hide resolved
class Matrix
{
public:
Matrix() =default; // tells compiler to generate default constructor.
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't you want to =delete this here? when would you want to declare Matrix M; on its own (and what dimensions would it have?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great question, in practice having containers or other data structures using matrix comes up. If these data structures are default constructed, it will invoke default constructor on matrix. A lot of times, you can't initialize the matrices at the time of construction of the container. As an example, think about a graph implementation using adjacency matrix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are other ways of achieving the similar thing like putting default values for nrows = 0 and ncols = 0 instead, but I just chose this cuz it highlights usage of =default.

Copy link
Contributor

Choose a reason for hiding this comment

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

imo that's kinda beyond the scope of these notes – will defer to judgement of other reviewers. @lucieleblanc @themost1 @al3623 what are your thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree this deeper reason for why I included it is way beyond the scope of class and actually totally subjective. For the students, I just want to say: I want a default constructor cuz I want it and here's a nice and simple way to let compiler generate it for you even if you defined your own constructor. The important thing is that you know how to do it.

Same thing with my decision to implement matrix with 1-dimensional array rather than like std::vector<std::vector>. I did that cuz it usually takes advantage of cache better, but all they need to know is I need something to hold the data and here's how you allocate/deallocate in ctor/dtor.

@j-hui
Copy link
Contributor

j-hui commented Nov 15, 2019

bruh why are there so many force pushes

@JamesYang007
Copy link
Contributor Author

Every time I had a small change to make, I thought that would be it and I always squash all my commits into one before pushing to master, so I kept squashing and force pushing and ended up doing it like 15 times xD big rip

Copy link
Contributor

@j-hui j-hui left a comment

Choose a reason for hiding this comment

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

bruh just squash upon merge

@JamesYang007
Copy link
Contributor Author

That's definitely the right thing to do, but I'm a rebel as you know.

@jaewoolee
Copy link

jaewoolee commented Nov 15, 2019 via email

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.

None yet

5 participants