r/programming • • Apr 01 '13

Ten C++11 Features Every C++ Developer Should Use

http://www.codeproject.com/Articles/570638/Ten-Cplusplus11-Features-Every-Cplusplus-Developer
469 Upvotes

283 comments sorted by

View all comments

Show parent comments

11

u/geaw Apr 01 '13

If the compiler knows, the IDE can know.

11

u/RagingIce Apr 02 '13

C++ is probably the language that this statement is the least true about.

5

u/mb86 Apr 02 '13

Depends on the compiler. Xcode and Visual Studio get along great with their compilers, but GCC tends to be a bit of a bad apple with IDEs.

7

u/danharibo Apr 02 '13

KDevelop for Linux users, easily on par with VS for code-introspection.

-3

u/josefx Apr 02 '13 edited Apr 02 '13

And that is why non-free obfuscated code is bad for the user./sarcasm

GCCs lack of integration was a long time feature to avoid missuse. It was developed to be impossible to integrate with proprietary tools and as a sideeffect was impossible to integrate with open source tools. Reason: Apparently RMS thought the GPL was not enough and being a hypocrite was ok.

Edit: Downvoters are welcome to point out what they disagree with.

3

u/[deleted] Apr 02 '13

Honestly, when I set up vim properly I felt like Linux itself became my IDE. Really deep git integration, session/project management, symbol navigation, code completion, argument completion, and of course code folding and syntax highlighting.

I think the same goes for most c/c++ developers who consider IDEs -- if they're spending enough time with the code to consider writing an IDE, they're probably spending enough time to realize learning how to make the most out of existing tools is quicker. Hence why no C/C++ IDE ever became the "Defacto standard" for a project as active as the linux kernel.

But Clang/llvm did a great fucking job and I hope GCC adopts all of its features.

3

u/josefx Apr 02 '13 edited Apr 02 '13

The reason there is no defacto c++ IDE for the linux Kernel is partly based on it not being a c++ project. The reason that writing a better c++ IDE for linux is too much work is caused by the fact that you had to implement half of the c++ compiler to get the features expected of a modrrn IDE. So again a big thank you to the gcc team for avoiding any form of stable modular design - by design.

VS is better than any IDE on linux, wait any run of the mill java IDE is better than what you get for c++ on linux and I hate that it is that way. Last but not least C/C++ is not a language, it is however a good way to sort out bad job applications - stop using it, C and C++ are mutually exclusive languages.

0

u/[deleted] Apr 03 '13

C and C++ are mutually exclusive languages

in what universe?

1

u/josefx Apr 03 '13

In any with an at least half decent c++ compiler and reasonable coding standards. Any C++ compiler will fail to compile most C code, even usting C headers in a C++ projekt wont work without using #ifdef __cplusplus ... #else ... #endif to constantly switch between both languages.

And if your code compiles in both languages the resulting binaries will differ in their runtime behavior.

Can you cite any non toy project that compiles as both C and C++?

1

u/[deleted] Apr 03 '13

Most C code will compile in C++, if you stick to standards. Of course, sticking to standards is impossible on MSVC, but that doesn't change the fact that for 99.9% of cases, C code can be recognized as valid C++.

And like I said, with vim I have code completion, symbol lookup, (really good) git integration, session managemnt, undo trees, syntax and error checking while coding (similar to XCode), neat refactoring tools, and the largest library of readable file formats. Sure, emacs has nicer gdb integration but I'm not about to learn another OS just to write C++.

So I don't get what features I'm missing? Most IDEs I've tried are lacking in one or two of these features. And their UI and editors are usually a locked-down, uncustomizable real-estate hog (except for Jetbrains Intellij platform -- really great programs).

1

u/josefx Apr 03 '13 edited Apr 03 '13

but that doesn't change the fact that for 99.9% of cases, C code can be recognized as valid C++.

I can believe that 99% percent of c code do not have variables/structs that collide with c++ keywords. However I find it unlikely that only 0.1% of C projects use malloc or other functions that cause implicit casts from void* (illegal in c++). Then there is the problem with all standard c headers being deprecated in favor of the c prefixed c++ versions e.g. cstdlib instead of stdlib.h which should move all methods into the c++ std namespace (only have cplusplus.com and cppreference.com as source).

Then there is the question which version of C and C++ we are talking about, the current C version is apparently 11, the current C++ version only includes parts of C99.

lastly getting a program to compile as c++ might get you unexpected behavior caused by suptle differences between the languages. (example sizeof('a') differs)

-1

u/mb86 Apr 02 '13

I do enjoy the irony in that this "feature" spurred the development of real competition in the free compiler arena with Clang.

2

u/adipisicing Apr 02 '13

I would imagine Perl or Ruby would have C++ beat.

1

u/[deleted] Apr 02 '13

Agreed. Rubymine does an awesome job with code introspection, but it still gets annoying seeing little "missing symbol" squigglies for methods and tests I know are defined. And if you make use of a lot of dynamically defined methods it just becomes a problem no IDE can even solve.

1

u/Houndie Apr 02 '13

What if we just use vim with a ton of plugins?

4

u/mhenr18 Apr 02 '13

Then you'll have to look at the headers and find their return type. auto's more for not needing to write massive templated types when it's obvious what a function's returning.

For example, if you declare a std::map<T1, T2> you know that you're getting a T2& back when you call map.at(), so why bother having to type T2 out when you can just type auto&? I'd rather not type something like std::tuple<int, std::set<MyType<...

...you get the idea.

0

u/[deleted] Apr 02 '13

[deleted]

2

u/elsporko Apr 02 '13

Kind of off topic, but I know several people working at large gaming companies and they've said that while they do use Visual Studio as a main IDE, any sort of 'Go to definition' functionality in completely useless since it can take up to a minute or so before it actually jumps to the definition. They have to disable the built-in intellisense stuff and use 3rd party libraries that do it almost instantly. Do you know anything about this? I'd thought VS would handle this type of thing pretty well, even for massive projects, so this puzzles me.

1

u/Jonny0Than Apr 02 '13 edited Apr 02 '13

Game programmer here, can confirm VS intellisense is crap in large projects. Visual Assist X works pretty well.

I'm not really sure what it is that intellisense has trouble with - it works well for my small hobby projects. Game studios tend to have LOTS of different build configs and platforms to target; that might be part of it.

Note: this comment is based on vs2010 and earlier. Vs2012 might be a lot better, can't say.