News for hackers. Stuff that matters.
Re:Why C++ is back by marris on Sunday December 02, 2012 @05:16PM (#4862773)
I think not.

The language is too big [it's always odd to see some people say things like "the language is still too big", as if some recent effort has succeeded in making the language somewhat smaller, but not small enough... every recent effort has actually made the language bigger]

There are too many ways to write bad code and too few ways to navigate bad code. It's hard enough to pick up a big C# program and figure out what it does ... C++ is not easier.

I'm not sure why there's all this excitement over bit twiddling... every language lets you twiddle bits. I can only assume the cool feature here is mislabeled, and the authors are really excited about memory twiddling. Fair enough. It's fun to write code that touches data structures at a byte level. But it's not fun to read/fix someone's buggy byte manipulation code. If you're not writing a device driver, or your own compression library, then you should not do this.

Now, I am a big fan of people learning low-level system details, provided they do it with some small C program, or by doing a project for their OS or compilers class, or by maybe working on some open source project.

But anyone who chooses C++ when he doesn't need it reminds me of the kid who, rather than painting on paper, decides to paint on the carpet. You could do it. It's also probably a lot of fun. There's even the remote possibility that you'll improve the carpet. But you probably won't. You'll probably just make a mess. And it won't be fun to clean it up.

Re:Why C++ is back by jandrewrogers on Sunday December 02, 2012 @05:58PM (#4862944)
In practice, C++ is considerably smaller than the theoretical extent of the language. Every C++ code base I ever worked on restricted itself to a subset of the possible feature space. With C++11, you can have a restricted subset of C++ that is actually pretty decent as a programming language and relatively easy to maintain.

With respect to bit-twiddling, the advantages of C/C++ are not intrinsic; many other languages have broken implementations for this purpose. For example, a glaring deficiency in Java is the lack of large unsigned integers which are useful for many types of algorithms. You can always implement these algorithms with signed integers but they may be much slower as a consequence.

For most people though, memory control and optimization is the primary reason to use C/C++. While I can see why it is difficult code for people uncomfortable with it, I think you overestimate the complexity for people that have done it for years. Like LISP, you have to become used to it. It is similar to the reason why, despite some arguments, there are many huge C/C++ code bases that rarely leak memory despite very active development. Proper idioms and use are a discipline like anything else.

C++ is never coming back for front-end applications. It is unnecessary and inefficient for that purpose. However, on the server side (where I do development), C/C++ is expanding very rapidly. Five years ago almost all of the server engines I worked on were written in Java. These days, all new development is in C++. The reasoning is pragmatic: C++ offers much better performance and latency characteristics for server engines, primarily due to its excellent memory behavior and efficiency. The latency and throughput differences are often integer factor relative to other languages for server workloads, so it is not a small difference and people are very sensitive to operational costs and footprint these days.

I pretty much hated C++ for years but with C++11 it is not great but it is adequate. Too much junk glued onto the language too many times. But until something remotely as capable becomes widely used, C++ will be with us for a long time, particularly as power efficiency becomes more important.

Re:Why C++ is back by millstone on Sunday December 02, 2012 @06:53PM (#4863162)
I don't agree that C++ is not coming back for front-end applications. There's some currents against managed code (i.e. WinRT), but more importantly, it never left.

I assume you are using IE, Firefox, or a WebKit browser to read this; that means you are using a majority-C++ front-end app right now!

In web browsers, text editors, video editing, IDEs, games, etc, there's hardly anything that can compete with C-derivative languages. Exceptions do exist (Eclipse, Minecraft) but are universally slow.

Re:Why C++ is back by politician on Sunday December 02, 2012 @08:31PM (#4863459)
"IE, Firefox, or a WebKit" are shims which allow UIs written in high-level languages to run on a variety of hardware. Their existence and popularity is evidence that argues against your claim.
Re:Why C++ is back by millstone on Monday December 03, 2012 @12:05AM (#4864045)
A shim is a thin and small piece of wood used to fill in small gaps. They make a very poor analogy to web browsers, which are tremendously sophisticated user-facing apps in their own right, and that dwarf the high level "UIs" they support in complexity.
Re:Why C++ is back by politician on Monday December 03, 2012 @09:34AM (#4865503)
Both Mozilla and Google consider their browsers to be shims for the underlying OS. Firefox OS and Chrome OS betray that assessment. Accordingly, IE has been historically crippled by Microsoft because they realize that browsers obsolete operating systems in many important ways for end-users.

Consider that operating systems are tremendously sophisticated user-facing applications in their own right, and that dwarf the high level "web browsers" they support in complexity. ;)

Re:Why C++ is back by pcwalton on Sunday December 02, 2012 @07:30PM (#4863295)
Alternatives to C++ are not universally slow for browser engines. I have first-hand experience here :)
Re:Why C++ is back by motti on Sunday December 02, 2012 @07:00PM (#4863187)
Not to mention Qt
Re:Why C++ is back by corysama on Sunday December 02, 2012 @07:27PM (#4863282)
Both mobile and server-side software are kind of a big deal at the moment --to understate drastically. And both can benefit greatly from C++ for the simple reason that computation (and especially memory traffic) requires power and power comes at a cost --either in the form of data center electricity bills or in the form of bigger, clunkier batteries in your device. "Servers are cheaper than engineers" is certainly true in small-to-mid-scale development. But, I expect Facebook is shifting from PHP->HipHop->C++ to save money. Meanwhile on mobile, you can't just tell the user to buy multiple phones. Your only alternative to more efficient software is to sit and wait for faster chips to start using less power. Unfortunately, it looks like there is a power-wall coming up there pretty soon... http://darksilicon.org/
Re:Why C++ is back by furyofantares on Sunday December 02, 2012 @05:37PM (#4862860)
> If you're not writing a device driver, or your own compression library, then you should not do this

Or a cutting edge game, or a high frequency trading system, or a high performance server, or an operating system, or implementing a language, or a database, or a numerical library, or a crypto library, or a VM...

Re:Why C++ is back by marris on Sunday December 02, 2012 @10:57PM (#4863872)
Game... maybe HFT... maybe High performance server... sure OS... most are not (C++ != C, C++ != assembly) Implementing a language... maybe Database... sure Numerical library... most are not Crypto library... most are not VM... maybe Browser... maybe the rendering engine

Again, you need to wrap your mind around:

(1) Some things will be written in C++

(2) C++ is not a synonym for "low-level." Many of your examples are really referring to C and assembly. Why would you prefer a C++ implementation of a crypto library to a C one?

(3) The vast majority of computer code written today is not for any of these systems. Lots of code uses these systems, but most people are happy with language bindings for a crypto API. Or to a numerical processing library. Or running on a VM running on an OS.

Does anyone have empirical data that the C++ fraction of software written today is increasing? If so, then you have a case. I'm going to guess that that fraction has been falling for quite some time, and will continue to fall.

Re:Why C++ is back by AnthonyMouse on Monday December 03, 2012 @02:24AM (#4864345)
>Why would you prefer a C++ implementation of a crypto library to a C one?

Here's an example from the EVP_Digest* man page from OpenSSL, with some comments added:

EVP_MD_CTX *mdctx;

// forget this part and get undefined behavior (but maybe it seems to work, sometimes)

mdctx = EVP_MD_CTX_create();

// forget this part? more and different runtime errors

EVP_DigestInit_ex(mdctx, md, NULL);

EVP_DigestUpdate(mdctx, mess1, strlen(mess1));

EVP_DigestUpdate(mdctx, mess2, strlen(mess2));

// md_value allocated with malloc()? don't forget to free()

EVP_DigestFinal_ex(mdctx, md_value, &md_len);

// forget this part, or remember it but miss an "if(err) return -1" statement somewhere? memory leak

EVP_MD_CTX_destroy(mdctx);

Comparable C++ implementation:

// RAII, compile error if you don't provide constructor argument instead of runtime error if you don't call init function

EVP_Digest_CTX ctx(md);

ctx.update(msg1, msg1_size);

ctx.update(msg2, msg2_size);

// return simple object: typed dynamic byte array + size with its own destructor, both digest and ctx destructors get called when function returns from anywhere

EVP_Digest digest = ctx.final_result();

And it's 4 lines of code instead of 7.

Can you explain why I would want the C version?

Re:Why C++ is back by furyofantares on Sunday December 02, 2012 @11:25PM (#4863941)
I was responding to your statement that you shouldn't be doing byte-level manipulation unless you're writing a device driver or compression library. The fact that C and assembly are used for some of my examples does not take away from them.

I agree that there is a ton of code being written where byte-level manipulation is not needed and is not appropriate. But there is still a ton of code where it is needed or appropriate, and you misrepresent that when you say you shouldn't be doing it unless you're writing a device driver or compression library.

Re:Why C++ is back by pjmlp on Monday December 03, 2012 @02:55AM (#4864407)
Symbian, BeOS(Haiku), z/OS, MacOS X device drivers, Windows COM infrastructure and user space drivers are all written in C++.

Additionally Microsoft is now replacing parts of the Windows C codebase to C++, as mentioned at the latest Build 2012 conference.

Re:Why C++ is back by xyzzy123 on Sunday December 02, 2012 @05:58PM (#4862943)
Or a web browser....
Re:Why C++ is back by dmcg on Sunday December 02, 2012 @06:35PM (#4863094)
We've added 3 rounds of features to the language and it's still too complex.