-
Notifications
You must be signed in to change notification settings - Fork 220
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
base: master
Are you sure you want to change the base?
Add cpp_demo #154
Conversation
There was a problem hiding this 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.
There was a problem hiding this 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.
Thanks guys, after applying John's proposed changes, I think the only nontrivial functions that are maybe outside the scope are the I have also changed the logic of my |
There was a problem hiding this 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
class Matrix | ||
{ | ||
public: | ||
Matrix() =default; // tells compiler to generate default constructor. |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
bruh why are there so many force pushes |
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 |
There was a problem hiding this 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
That's definitely the right thing to do, but I'm a rebel as you know. |
I just took a look at this. While this is a great example, I have some
concerns on the number of new C++ constructs that this example introduces
that either have yet to be covered or will never be covered. Remember that
review sessions are not supposed to teach new materials. Let's talk about
this in the meeting today.
- Jae
…On Fri, Nov 15, 2019 at 8:10 AM JamesYang007 ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In M-cpp/cpp_demo/matrix.hpp:
> @@ -0,0 +1,62 @@
+// pragma once is the C++ way of include guards.
+// This guarantees that header files will be included at most once.
+#pragma once
+
+// Matrix is a class that represents a matrix of integers.
+class Matrix
+{
+public:
+ Matrix() =default; // tells compiler to generate default constructor.
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.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#154?email_source=notifications&email_token=ABX2KHDTK3CNWCJXXNNVVZDQT2NV3A5CNFSM4JM7BZBKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCLXEXBQ#discussion_r346815726>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABX2KHAQH3FLDLGIJRGUBSTQT2NV3ANCNFSM4JM7BZBA>
.
|
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.