News for hackers. Stuff that matters.
Re:C++ killed my grandpappy - Is C++ hard and where are the ... by ComputerGuru on Tuesday June 29, 2010 @06:20AM (#1470954)
I'm a C++ developer 18 hours of the day, and a .NET developer the other 6.

C++ is great. It's very powerful, it's very fast, and actually, very easy to use. Especially on Windows.

If you want quick and dirty access to system functions, if you want to be able to quickly open a pipe, write raw data to it, and be on your way. If you want low-level access to a buffer, to the memory, to a file. If you want to do basic string parsing. It's all there.

.NET is certainly a better platform but it's not as inherently powerful. On Linux, it's rather different because at this point you can do anything in Python or Java that you can in C++ (except drivers and kernel modules, etc.). On Windows, that's not exactly the case.

I love the control that C++ gives me. I can decide when a object is passed by reference and when it's by value. I can send a object as constant by reference explicitly and therefore make no mistake about it. I can use pointers to fly to pre-determined locations in a buffer. I can jump pointers to access hard-coded offsets in a struct. I choose not to use templates willy-nilly and to never do multiple inheritance. I don't use things that are hard to maintain, but I take pride in using quick and dirty innovative solutions where it's short on steps, but not short on self-explanatory functions (i.e. shortcuts in functionality, not in LoC).

C++ is as complicated as you make it. It gives you a lot of rope to hang yourself with. It gives you a lot of flexibility. It gives you a lot of power. When writing a filesystem monitor that parses hundreds to thousands of events per second, I use raw char* pointers and manual memory allocation (with a 3rd party allocator, no less). When doing userland apps, I use automatic memory management with smart pointers.

I have all the flexibility and automation of .NET and Java - but I also have the choice not to use it.

But stick a beginner in C++, and they'll fail to see that there are many options, some of them even easier than their managed counterparts. They'll get lost battling pointers and confusing their laws of inheritance, and they won't see the forest for the trees. They'll overuse templates when they're not necessary, and not use the well-syntaxed and to-the-point STL algorithms when they're available.

In .NET, I find myself longing for raw memory access at times. I find myself wishing that the .NET team bothered themselves to add wrappers to even more Win32 functions and that I don't have to have a class full of 50 to 100 P/Invokes in order to get access to what I consider for my needs to be essential Win32 calls.

But .NET makes working with a team easy. It makes it easy to set standards and stick to them. It makes it easy to keep track of objects. It makes it super easy to integrate GUI and code in a way that makes sense (MFC begone!). I can use .NET to write a terribly complicated app in a matter of an hour and have it deployed with minimal effort spent on error proofing the application. I don't have to worry about checking the return value of each and every call I make - a single catch() that's well written will take care of it all. I don't need to worry about finding headers that fit my coding style or bother myself with linker errors. A ton of libraries exist only a "using ...." away.

The worst thing about C++, without doubt, isn't the language or the syntax: it's the compilation problems. When you have multiple cyclic dependencies. When you have functions to export, and similar functions already imported from one of the dependencies you already have. DLL hell. Conflicting versions of the CRT. Having to search for the source code of a module you wrote years and years ago in order to re-compile it against the same C runtime that you're using in your current project. Having to keep a copy of both .h and .lib files for all your DLLs in order to use them again in a later project. Stuff like that is where I really appreciate the .NET way of doing things.

Re:C++ killed my grandpappy - Is C++ hard and where are the ... by dfox on Tuesday June 29, 2010 @11:17AM (#1471655)
I believe that compilation problems you describe are caused by Microsoft's development tools (and by some weird quirks of Windows as a platform) and not by C/C++ itself. Every time I build something for Windows I get this feeling that it's actually hostile to code reuse across projects and that is the case even in .NET. Getting right import libraries (what are they for, anyway?) and getting IDE to actually know that you intend to link something/use some assembly seems horribly complicated in contrast to unix's #include <foo.h> and ld ... -lfoo

Also, having five different almost-compatible ABIs for C is something that really helps C/C++ programmers, especially in environment where it is common to ship compiled binaries, that are often very hard to rebuild from scratch.

Re:C++ killed my grandpappy - Is C++ hard and where are the ... by xenthral on Tuesday June 29, 2010 @05:39PM (#1472941)
Have you looked into CMake to alleviate your compilation woes?

I recently started using it and its been very useful so far.