On Sun, 2014-11-23, Chicken Mcnuggets wrote:
...
> My big problem at the moment is writing C++ code as if it were C code so
> I have a tendency to use the C standard library more than the C++
> standard library. I guess this is just down to ignorance of the C++
> standard library and is considered poor practice for C++ code.
Depends on which part of the library you're talking about. The most
important parts of the C++ library don't exist in C: the containers
and algorithms.
> I certainly want to rewrite bits of my code to take full advantage of C++.
>
> On the other hand some "bad practices" in C++ I have read about such as
> using C style arrays and raw pointers rather than references seem to
> make some things a little lighter when a full on C++ solution might add
> extra overhead.
There's no performance penalty for references or std::array. For
other things ... one of the revelations I had when I started using C++
was when I realized that:
(a) A lot of the containers (string, vector, map ...) imply dynamic memory
allocation, when in C I would have used an array and hoped it
would be large enough.
(b) I could never or almost never see this cause any practical problems!
It's worth it.
> Is it really considered that bad to have these things in
> your code?
It depends ... they /do/ have their uses, but not where C++ has better
alternatives.
> The project I am working on is going to be open source, am I
> going to turn off C++ programmers if I have to much C style stuff in the
> code even if it is abstracted away behind classes?
Personally I can tolerate almost anything, if it's encapsulated in a
small class or function, and if that class or function as a whole
behaves normally (is exception-safe, has well-defined states, can be
copied if it makes sense, cannot be copied if it doesn't, and so on).
That's one of the main reasons classes exist.
Speaking of small classes: one of the common beginner's mistakes seems
to be to design a few big classes. IME you gain a lot more from
designing the many small, short-lived objects. Try to do that.