News for hackers. Stuff that matters.
Re:Is the C++ preprocessor still needed? by jjawssd on Tuesday May 09, 2017 @10:02PM (#14305405)
While perfectly fine, this comment unironically reinforces the GP's assertion of "how [C++] as a whole the language is basically a gigantic ball of special cases"
Re:Is the C++ preprocessor still needed? by kobeya on Tuesday May 09, 2017 @11:11PM (#14305650)
What specifically annoys me about C++ and is demonstrated by this example is that the simplest possible expression of an algorithm is almost certainly not the most efficient or desirable way to do what you are trying to accomplish.

In a language designed for humans, the simplest expression of a loop (e.g. `for (auto paths : m) {}`) would use references not value copying. You'd have to go out of your way to do the it the dumb way, which you would only do when you have a specific reason to do so.

C++, on the other hand, is only really an effective language in the hands of people who have either fully internalized the 1,000 page specification, or wasted a depressing number of synaptic connections on memorizing minute trivia about what constructs to use under what circumstances.

I say this as someone who works with C++ on a daily basis :(

Re:Is the C++ preprocessor still needed? by claudius on Wednesday May 10, 2017 @04:40AM (#14306779)
> In a language designed for humans, the simplest expression of a loop (e.g. `for (auto paths : m) {}`) would use references not value copying. You'd have to go out of your way to do the it the dumb way, which you would only do when you have a specific reason to do so.

But I would expect

    auto x = y;
to create a new variable by copying with type-deduction from y, not a reference (or even const reference) to y. If I want a reference anywhere in the language I always have to say so explicitly. As such, I find it perfectly normal that

    for(auto x : y)
create a copy of the elements of y while

    for(auto& x : y)
creates a reference to the elements of y. Reversing this just within for-loops would only add to the confusion. Defaulting to references over values just for auto where everywhere else values are the default and references need to be specified would also only add to the confusion.

Of course you may now say that one should have done it right from the start, but this is then an argument about the initial decisions in the late 80s, not about the use of auto in C++11.

Regarding the specification, I am incredibly happy that there is a specification I can trust and nowadays a series of different compilers which largely implement this specification instead of some "model-implementation" which implicitly defines the language and may look entirely different next week.

Re:Is the C++ preprocessor still needed? by kobeya on Wednesday May 10, 2017 @05:45AM (#14307024)
> But I would expect "auto x = y;" to create a new variable by copying

Why would you expect that? There are plenty of examples of other referentially transparent languages where "x = y" means x and y refer to the same thing, not different things (one newly created) initialized to the same value. Maybe you expect it to work the way it does because that more closely resembles how C++ has worked for you in the past, which is a bit of a circular argument.

> Of course you may now say that one should have done it right from the start, but this is then an argument about the initial decisions in the late 80s, not about the use of auto in C++11.

Yes, that's exactly the point I am making.

Re:Is the C++ preprocessor still needed? by exprA on Wednesday May 10, 2017 @08:27AM (#14307614)
Are you sure you're making a point – because I can't see one. Seems more about unnecessary bitching about C++ being different from [some-different-language].

If they could do anything more stupid as introducing a galling difference and a special case to variable initialisation with auto, it would be to do exactly that, but because “some other languages work more like that”.

Re:Is the C++ preprocessor still needed? by Retra on Wednesday May 10, 2017 @01:12AM (#14306049)
I used to despise C++... but now I work on it every day, and while I don't think it's great, it is not so bad. Turns out my hatred was entirely for the std library. At my work, we simply don't use it. And thus `auto` hardly saves anything, so we don't use that either, and I don't miss any of it.
Re:Is the C++ preprocessor still needed? by gpderetta on Wednesday May 10, 2017 @04:27AM (#14306726)
> In a language designed for humans, the simplest expression of a loop (e.g. `for (auto paths : m) {}`) would use references not value copying.

In C++ values are first class, making 'auto x' an implicit reference would be surprising for anybody with experience with the language model. It is also consistent[1] with the template deduction rules. I strongly believe that not not having first class values in a language with mutation is a design mistake [2].

[1] IIRC the ill designed initialization_list has special rules for auto. [2] C++ references are not first class which is also a mistake.

Re:Is the C++ preprocessor still needed? by llukas on Tuesday May 09, 2017 @11:27PM (#14305708)
> C++, on the other hand, is only really an effective language in the hands of people who have either fully internalized the 1,000 page specification, or wasted a depressing number of synaptic connections on memorizing minute trivia about what constructs to use under what circumstances.

No. You use profiling tools and optimize hotspots. Pareto principle applies here so you look at 20% of program tops.

Rest is irrelevant and can be executed as inefficiently as you please as long as you got your big O complexity right.

Re:Is the C++ preprocessor still needed? by kobeya on Tuesday May 09, 2017 @11:43PM (#14305774)
Or the language and compiler can just save you the trouble and get it right from the beginning.
Re:Is the C++ preprocessor still needed? by klipt on Wednesday May 10, 2017 @12:49AM (#14305974)
Isn't C++ still pretty much the fastest language out there, except Fortran for some numerical applications? I thought that's the main reason to use it over Python/Java/etc.
Re:Is the C++ preprocessor still needed? by kobeya on Wednesday May 10, 2017 @05:53AM (#14307065)
Who said anything about Python or Java? In any case Java and C++ are roughly similar. The next tier of languages such as Rust or Haskell are within a small constant factor in the usual benchmarks. But quoting such benchmarks is questionable because the C and C++ implementations require much more man-hours of hyper optimization to get into that top-tier position. The real important takeaway is that the first or second attempt in C++, by someone who is not a language lawyer, is nowhere near the maximum achievable speed. Whereas the first or second attempt by a similar layman in a reasonable language like Haskell is not only faster than the initial C++ version, but has fewer bugs as well.
Re:Is the C++ preprocessor still needed? by andrepd on Wednesday May 10, 2017 @11:03AM (#14308710)
C++ and Java are absolutely not similar in terms of performance. Java requires a virtual machine, C++ compiles to binary. Not in the same league.

And in regard to the first draft of a C++ program being slow until you spend lots of time optimizing it, when comparing to say Haskell, that is not at all my experience. I'm generally able to write clean and efficient programs in C++ on the first draft, and they are invariably more performant than if I had written it in a slower language, without a significantly greater amount of effort.

Re:Is the C++ preprocessor still needed? by pjmlp on Wednesday May 10, 2017 @02:51PM (#14310619)
Java doesn't require a VM per se, there are plenty of commercial JDKs that compile straight into native code.

In case you want to state that a VM is like a language runtime in that case, C++ also needs one for handling exceptions, RTTI, global constructors/destructors, floating point emulation,...

Re:Is the C++ preprocessor still needed? by burntsushi on Wednesday May 10, 2017 @07:25AM (#14307370)
Speaking as someone who has spent time optimizing programs in both languages, Rust is certainly not in the same tier as Haskell. It should be in the same tier as C or C++. If there's a program where it's not, then we consider it a bug. (And indeed, those exist. :-) But they are fixable!)
Re:Is the C++ preprocessor still needed? by annnnd on Wednesday May 10, 2017 @07:24AM (#14307367)
> Who said anything about Python or Java? In any case Java and C++ are roughly similar.

And with Python you use heavily optimized native libraries (Numpy & co.) where it matters.

Re:Is the C++ preprocessor still needed? by dima55 on Wednesday May 10, 2017 @01:42AM (#14306147)
C. Use C.
Re:Is the C++ preprocessor still needed? by jsolson on Wednesday May 10, 2017 @03:07AM (#14306396)
Having recently done some C development after a few years of exclusively C++, no, no thank you.

I'll take my RAII and destructors, thank you very much.

Re:Is the C++ preprocessor still needed? by pjmlp on Wednesday May 10, 2017 @05:22AM (#14306934)
Hence why already back in 1993, when faced with the option of Turbo C 2.0 vs Turbo C++ 1.0, I could not understand why bother with C at all, still don't.
Re:Is the C++ preprocessor still needed? by josefx on Wednesday May 10, 2017 @08:47AM (#14307735)
Those language creators and their names, "C","C++", "Objective-C","HolyC", "C#". I almost thought "C." was a new language.
Re:Is the C++ preprocessor still needed? by CyberDildonics on Wednesday May 10, 2017 @09:11AM (#14307851)
C doesn't have destructors or move semantics.
Re:Is the C++ preprocessor still needed? by llukas on Wednesday May 10, 2017 @12:11AM (#14305870)
What you see as trouble other people see as desired behavior.

Pick the right language.