cpluspluscourse icon indicating copy to clipboard operation
cpluspluscourse copied to clipboard

Use std::vector in smartPointers and stl exercises ?

Open chavid opened this issue 3 years ago • 8 comments

It is my strong feeling that the use of raw C arrays makes the syntax uselessly complex, and divert the learners from what we want to demonstrate. It would rather use std::vector, provided it has been previously presented in the morning lessons.

chavid avatar Mar 17 '22 15:03 chavid

We have std::vector in the STL chapter, which comes before smart pointers, so we can use it for the exercises.

bernhardmgruber avatar Mar 18 '22 09:03 bernhardmgruber

Do we also have std::array ?

chavid avatar Mar 18 '22 09:03 chavid

We have a slide that lists all STL containers, including std::array. I told the students that std::array is similar to a C array but with a std::vector like interface. So in principle, they should not be too surprised seeing it.

However, if we now put STL algorithms and std::vector/std::array all in one or two exercises, that might be a bit too much.

bernhardmgruber avatar Mar 18 '22 09:03 bernhardmgruber

I rather think that using the type double[] in the exercises, with the unusual way to use make_unique/shared, and the use of array addresse together with "address+size", instead of begin() and end(), is doing a great disservice to beginners. They should use std::array from the beginning, never more C arrays.

chavid avatar Mar 18 '22 11:03 chavid

With vector, there is no need to put it on the heap. I would generally say that people should use vector, but you see that it defies the point of the exercise.

I'm very happy though if you want to replace the array with a std::array on the heap! Thoughts?

hageboeck avatar Mar 18 '22 14:03 hageboeck

... the same for the array in LargeObject, problem2.

hageboeck avatar Mar 18 '22 14:03 hageboeck

I generally use valarray in such a case, as a replacement for the stillborn gsl::dyn_array... but I understand that some developers dislike std::valarray.

chavid avatar Mar 18 '22 14:03 chavid

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[bot] avatar Jul 19 '22 18:07 stale[bot]