News for hackers. Stuff that matters.
Re:I disagree with Linus Torvalds about C++ (2009) by stochastic_monk on Monday December 24, 2018 @09:04AM (#18752173)
I feel that I’m more skilled in C++ because I developed a large project in C first. Whether or not C is the language one ultimately chooses, it makes one aware of the tradeoffs and benefits of various coding styles.
Re:I disagree with Linus Torvalds about C++ (2009) by sytelus on Monday December 24, 2018 @09:21AM (#18752227)
Main advantage of C is that it forces you to understand what goes on under the hood. To many C++ programmers who didn't do much work in C, if you ask how the variable var1 bellow gets allocated, they will be scratching their heads. As a former C programmer, this is the first thing I try to understand - who is allocating what and who will be freeing it up and how. I don't like anything to be black box or performing magic for me. But many quick short and sweet courses on C++ completely skip this. There is in fact a book someone showed me which said that you don't need to worry about memory allocations in modern C++, just use smart pointers and everything will be taken care for them! Poor souls!!

  void f() {
    Vector<int> var1;
  }
Re:I disagree with Linus Torvalds about C++ (2009) by 0xcafecafe on Monday December 24, 2018 @09:25AM (#18752241)
Any C++ programmer worth their salt should know that a vector is implemented using begin and end pointers. I believe its do with the person than the language. The same person can miss nuances of C as well.
Re:I disagree with Linus Torvalds about C++ (2009) by e12e on Monday December 24, 2018 @09:33AM (#18752275)
I actually think this illustrates the success of c++ as a (also) high level language: a relative c++ novice can produce reasonably correct code, by sticking to a small, straightforward subset, and following best practices.

I think c a novice seem much more likely to rely on undefined behavior and have an accidentally working program that leaks memory, fails to check the return value of malloc, close files etc?

That is, one can be sort of productive and "correct" in naive c++ - in c that's not really possible (well, one can be "productive" but correct is less likely?).

Re:I disagree with Linus Torvalds about C++ (2009) by Koshkin on Monday December 24, 2018 @11:06AM (#18752707)
On the one hand, knowing an implementation detail is (or shouldn't be) very important; also, those can change. But on the other hand this is helpful in cases when you need to make a judgement as to the efficiency of certain constructs. For example, I find it is very instructive to learn about the actual implementation of the shared pointer.
Re:I disagree with Linus Torvalds about C++ (2009) by gpderetta on Monday December 24, 2018 @11:04AM (#18752697)
Ahem... I think that the tipical implementation is a triplet of base pointer, allocated size, initialized size.
Re:I disagree with Linus Torvalds about C++ (2009) by stochastic_monk on Monday December 24, 2018 @02:56PM (#18753938)
I expected it would be, and that’s how I’ve implemented my vector variants, but I checked the source code for libc++ and libstdc++. Both use two pointers.
Re:I disagree with Linus Torvalds about C++ (2009) by gpderetta on Thursday December 27, 2018 @07:56AM (#18769174)
Interesting. I do remember inspecting _M_begin and end in the debugger.

I can't be bothered to check the implementation now, but the allocated size must be stored somewhere. My first thought of inferring the capacity as the smallest power of two greater than the used size doesn't work as the vector size can shrink without affecting capacity.

Re:I disagree with Linus Torvalds about C++ (2009) by stochastic_monk on Monday December 31, 2018 @03:32PM (#18796796)
The used size is end - begin; the capacity is stored in addition. That’s why sizeof(std::vector<T>) is 24 on x86-64.
Re:I disagree with Linus Torvalds about C++ (2009) by hopler on Monday December 24, 2018 @09:33AM (#18752276)
Patent said allocated, not implemented.
Re:I disagree with Linus Torvalds about C++ (2009) by gpderetta on Monday December 24, 2018 @09:45AM (#18752327)
I like to ask candidates to implement (simple subset of) standard facilities as interview questions.
Re:I disagree with Linus Torvalds about C++ (2009) by Koshkin on Monday December 24, 2018 @11:00AM (#18752677)
I love C, but these days the thought of doing any serious programming in it is scary, like a nightmare where you would find yourself naked deep in the woods with only a stick in your hand.
Re:I disagree with Linus Torvalds about C++ (2009) by stochastic_monk on Monday December 24, 2018 @11:05AM (#18752700)
I respect great C developers, and a lot of great software is written in it. I can just write an equivalent or better program much more efficiently with less effort with C++ metaprogramming. I also think macros are a valuable tool for the language and wouldn’t choose for them to be removed because it allows for concise shorthand.
Re:I disagree with Linus Torvalds about C++ (2009) by gpderetta on Monday December 24, 2018 @09:54AM (#18752374)
I don't think you need to learn C to become a good C++ programmer. But knowing it (or the low level subset of C++) will make you a better programmer.