7 ms·
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
by stochastic_monk 8y ago
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.
- sytelus 8y agoMain 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; }
- 0xcafecafe 8y agoAny 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.
- Koshkin 8y agoOn 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.
- e12e 8y agoI 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?).
- hopler 8y agoPatent said allocated, not implemented.
- gpderetta 8y agoAhem... I think that the tipical implementation is a triplet of base pointer, allocated size, initialized size.
- stochastic_monk 8y agoI 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.
- gpderetta 8y agoInteresting. 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.
- stochastic_monk 8y agoThe used size is end - begin; the capacity is stored in addition. That’s why sizeof(std::vector<T>) is 24 on x86-64.
- gpderetta 8y agoI like to ask candidates to implement (simple subset of) standard facilities as interview questions.
- gpderetta 8y agoI 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.
- Koshkin 8y agoI 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.
- stochastic_monk 8y agoI 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.