开发者

C++ as a high-level language? [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Closed 2 years ago. Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.

I learned C++ for the first time years ago by reading Stroustrup's "The C++ Programming Language" for two times and participating for a year in quite a big project (though the level of c++ team was quite low). The C++ from the Founder's book was really a huge extension of good old C. Powerfull and object-oriented and e开发者_JAVA技巧ven generic, but still - extension. And, yes, there was as STL somehow added to the language by standard, that was just there by some hidden reasons - whether you are going to use it or not. So, at that days I got not much of a good impression of C++: in addition to all these eternal C problems with memory, pointers and arrays' bounds there were a lot of new added: with classes and templates and complicated syntax and a lot of thinking to sort it out.

Now, after a years of keeping away from C++, I've started recently to refresh my knoweledge, but now I beagan with "Accelerated C++" by Andrew Koenig and Barbara E. Moo. And what I'm seeing there is absolutely "another C++"! Following this book, you can in fact use C++ almost without knowing its C-core: you can never use arrays, since you have vectors, you can forget about char*, since you have string, etc., etc. From this point of view, STL is really the heart of the language and the language itself appears to be a very "high level" one, but with performance and control over entities which neither Java, nor Python could ever afford.

So, what C++ do YOU use in you practice? Do you mix the styles, say, arrays and vectors? Are there any rules or best practices here?...

UPDATE:

I was told in comments that the thing I'm talking about is what's now called "Modern C++". Searching by this words brings out the following really interesting threads:

Is modern C++ becoming more prevalent?

What is Modern C++?

Examples of "modern C++" in action?


Congratulations, you have discovered what we call "Modern C++". I'd prefer it anyday over "C with classes" styles of programming. No more raw pointers, no more explicit deletes etc. Wonderful world!


So, what C++ do YOU use in you practice? Do you mix the styles, say, arrays and vectors? Are there any rules or best practices here?...

Modern C++, definitely. But in my opinion, that doesn't exactly rule out arrays. There are still cases where arrays are preferable to vectors. But when I do use arrays, I use them in an STL-kind of way. I use pointers as iterators, and I apply STL algorithms to the contents of the array, and so on.

By the way, Bjarne Stroustrup himself has been quoted for describing C++ in a very similar way to what described yourself:

Within C++, there is a much smaller and cleaner language struggling to get out

Of course, there are limitations. With modern C++, compile times tend to suffer. And it requires much more advanced compilers, which on some platforms makes it a no-go. And a lot of more conservative lead developers or project managers, or just ancient code bases sometimes mean that it is not an option either. And there is a certain learning curve, because all the pitfalls of C are still there, you just have to learn to step around them (for example, memory leaks don't just vanish, modern C++ just defines some very powerful patterns to avoid them).

But I think modern C++ can really be considered a beautiful language. And that's definitely not how you'd describe traditional "C-with-classes" style C++.

When I work in (other) high-level languages, I've found that there's nearly always something I miss from C++. Either the language misses the robust and type-safe containers or the expressive iterators/algorithms, or it lacks support for RAII, or it has no way to express generic algorithms, as you can with templates.

Those languages definitely have their advantages too, and there are indisputably areas where they are just plain better than C++. But I usually also find that they have clear shortcomings, where I just can't express my ideas as well as I can in C++. I have to jump through hoops, sacrifice type safety, rely on reflection or whatever else, just in order to do something that C++ would have supported "naturally".


Generic typing and template metaprogramming all the way. I don't use polymorphism that much since it's too much lock-in.

And by the way, the Boost libraries are a tremendous complement to STL.


Koenig and Moo's Accelerated C++ is a very good book, and one that I recommend.

I mix arrays and vectors as I see fit. For things that are not dynamically changed, I still use arrays, otherwise I would use vectors.

It is important that you understand both.


Definitely mixed-style. It seems silly to limit yourself unnecessarily, especially with so many options.


C++11 wins all your battles.. believe me..


As an alternate answer, I'm tempted to say the best practice for using C++ is don't.

If you are Windows only, and .Net isn't too large, then C# is an excellent choice. On Unix, Java is great.

Of course C++ has its place. It is just a smaller place than it used to be in my world.

Edit: I have over thirty years programming experience. 5 years Assembly, 17 years in C, 5 years in C++, 3 years in Java, and now 2 years in C#. I am very good at all of these. Assembler is is great. I am fast in programming with it. But I prefer C over Assembler. Similarly, I prefer C# over C++. I find it much easier to do most common applications in C# than in C++

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜