Why people think C++ is complicated?
easycppcodes.com
easycppcodes.com
I'd love to have the ability in C++ (and basically all other languages) to turn on/off language and standard library features right in the source code, it would do wonders for the maintainability of projects with many contributors and large code bases in general.
Instead of writing a style guide in the sense of "don't use new/delete, don't use raw pointers or arrays, don't use exceptions, don't use CRT functions, don't use stl containers, etc...", and hope that everyone follows the guide or catch violations in code reviews, the style guide would be part of the source code, and violating it would result in compilation errors.
If I could turn off a number of features, C++ would be great. I keep flashing back to blog posts [0][1] written by the ZeroMQ author trying to settle on C being the way to go.
Exceptions should be able to be turned off in the compiler, but destructors, move semantics, simple template type substitution, and lambdas should be zero overhead in modern C++11/14.
I think a lot of people think about C++ and think inheritance and exceptions, but after having done modern C++11 for two years, those are two of the features I've used the least.
Edit: the ZeroMQ point is that, if you have a constructor or a destructor, then it must not do anything that can fail because the mechanism for recovery is an exception and clean recovery from exceptions bubbling up through code is quite hard to achieve. This is basically the Go/Rust argument against exceptions and in favour of explicit error return.
What he said IIRC is that you can't manage errors in them without either using exceptions or using trivial constructors/destructors plus a state machine for the remainder of the lifecycle (initialisation etc). As he's mostly into writing libraries not applications, both approaches were, in his opinion, more hassle than they were worth.
Which is why EA created the EASTL: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n227...
Do note that some of the issues with STL as pointed out in the link above got improved upon as both implementations and compilers improved.
Compiler support hasn't always been there, especially on embedded systems with old or poorly supported compilers.
Strict control over memory allocation hasn't always been possible with STL, and it's still not very convenient if/when you need your own allocator, e.g., embedded systems, console games.
And this isn't true any more, but I still remember what the error messages used to look like more than 15 years ago. Sometimes a single error exceeded the maximum output length for error messages in whatever compiler I was using, probably Microsoft's, and you couldn't actually see what the problem was. That left me with impressions of STL that took a long time to recover from.
I don't think you can blame the C++ standards committee for vendors creating shitty implementations.
At the moment, unless you're exposing an object via a public API, I recommend using boost::string and boost::multi_index for hash tables. In public APIs expose a good old fashioned char*,size_t pair, or copy to a std::string.
It was down for me.
There is a huge amount of knowledge that you need to pick up over the years before you can consider yourself even an advanced c++ programmer let alone an expert.
In my experience it's way more complex than c, JavaScript, Python and any Lisp. However, you can use it in a c-like fashion and avoid some of the complexity but if you want to work with anyone else's code then you have little choice but to learn that complexity.
One think I loved when learning C++ (and which makes me feel it's not complicated) is that pretty much everything felt like a logical decision if you understood you're just one step above metal. Now I know I was mistaken back then in some ways (by e.g. believing that C memory model is exactly how things are done in hardware). I now believe that every language will feel logical and reasonable if you end up learning about the reasons why it looks like it does and its relationship with what your hardware does.
We need some frame of reference or objective standard, but I'd say: that is wrong.
For most languages I have the feeling I'm getting more proficient as I use them. Not so much with C++, especially if you get exposed to other people's code.
Same for JavaScript :)
Leonard Susskind
I'm afraid after a while, Rust will see the same problems, unless they let go of backward compatibility.
C++ is the oddity, in that it is trying to become a completely different language. Rust won't have that problem.
vs
http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/tut...
I know a lot of people would criticize the practices/styles used in ptypes - but I've yet to see another C++ library that is as easy to use, easy to read, AND most importantly cross platform. Hell even raw sockets in C is easier to use and understand than boost [1].
This is one of my favorite comments on reddit [2].
[1] http://www.thegeekstuff.com/2011/12/c-socket-programming/
[2] http://www.reddit.com/r/programming/comments/197dn1/introduc...
Dereference a pointer? That translates to a tiny fragment of machine code for "dereference pointer".
Create a lambda? That translates to a big blob of machine code for "set up this bunch of paperwork that will be used to painstakingly emulate a lambda".
Of course, it won't happen magically: someone has to go to the effort of defining the subset and building the compiler for it.
You can't expect the general-purpose compiler to automatically be as optimal as possible just because a program happens to use the subset. For example, the program might be being compiled into something like a java .class file meant for importing to a less conservative calling program. This would be incompatible with putting those bare metal optimizations in the .class file.
Interpreted languages such as Python or Ruby (or languages that run on a VM, like Java) go through an interpretation step _every time_ they are run that translates them down to machine language.
This gives compiled languages an inherent advantage in terms of runtime performance; programs written in these languages don't have the overhead of translating to machine code at runtime. This is typically why people advocate "next to bare metal" as having better performance.
In C and (sort of) C++ you can deal with actual bytes in actual memory locations. You can find the exact memory address of a data structure, and you can read or write directly to that location.
You can even prod the compiler to suggest that it uses real hardware registers for variables.
You can also control how memory is allocated and released.
In most languages an array is just an array. You usually don't care where it is in memory.
In functional languages you concentrate more on designing symbolic operations, and the fact that there's real memory under there somewhere is almost irrelevant.
But C/C++ are bare-metal-ish. In assembler you work directly with memory, but you can control program flow. You can jump/branch to any address in memory. Sometimes you can even overwrite your own code.
C/C++ won't let you do that.
As a former assembler guy, I find that C++ is the worst of both worlds. You get the cognitive overhead of dealing with memory management and pointer arithmetic and iterators, but the options for not working with them when you don't want to are limited - so it's hard to concentrate on the functional level, and you do a lot of the work the compiler/interpreter would usually do, but without the "do whatever you want" freedom of assembler.
With things like a JIT it can see it at runtime, but that's still overhead to handle the detection and the bail-out situations.
Edited: Correct my bad grammar.
But I would say it's because others are easy.
Yes others are hell lot easier.
(arguably C# is the "top C++" with its managed/unmanaged distinction)