News for hackers. Stuff that matters.
Re:Does C++ still deserve a bad rap? by beyondCritics on Friday October 16, 2020 @09:23PM (#24806718)
This story about the committees fixing Stroustrup's "mistakes" is completely made up from you and is not even remotely true. Also Stroustrup does _not_ take pride in how big the language is, the exact opposite is true. E.g. you will never ever hear Stroustrup speaking about template meta programming or similar weird stuff. He always tries to teach the practical side of C++. His C++ book is not big because the language is complex, but because it is a genral introduction into programming with C++. In fact, if you want to learn the esoteric features of C++, you have to buy other books. Implicit type conversions are inherited from C, the language you called "awesome". Many arcane features of C are nowadays considered as anachronisms and no modern designed language would repeat them.
Re:Does C++ still deserve a bad rap? by flowerlad on Friday October 16, 2020 @09:59PM (#24806884)
> Implicit type conversions are inherited from C, the language you called "awesome".

It is true that C language has some very limited implicit type conversions. For example you can say:

   long n = 3;
And the integer 3 is converted to long. This is extremely limited, and does not make the program hard to understand, which is completely different from the craziness you see in C++.
Re:Does C++ still deserve a bad rap? by beyondCritics on Friday October 16, 2020 @10:54PM (#24807105)
C does destructive conversions automatically, if you ask for it. E.g.

  unsigned n;
  n = 2.99;      // n = 2
  n = -1;        // n = 2^M-1;
  n = 1.0E33;    // undefined but not catched
Both C and C++ follow the same philosopy: "Trust the programmer". The programmer is expected to use his expressive freedom, to solve performance problems and stay away from problematic constructs without being told to so. C is a systems programming language from the 70's, designed to solve performance problems and C++ inherits from that. It is true, that in C++, you can overload assignment, addition and throw exceptions everywhere, thus making even simple expressions like

  auto n = a + b;
completely unpredictable. But the coder simply has abused the freedom C++ gave him. T some extent, the same is possible in C, look here https://www.ioccc.org/
Re:Does C++ still deserve a bad rap? by beyondCritics on Friday October 16, 2020 @11:16PM (#24807191)
Either you love C++ or you hate it. To tell the truth, i am also of the opinion that C++ is fucking crazy complicated. There are youtube videos from leading experts, explaining the usage of simple language elements at length, something like that is unheard of in modern languages. E.g. you are not expected to grasp overload resolution to the fullest extent: https://en.cppreference.com/w/cpp/language/overload_resoluti... Mastery takes likely years of experience.
Re:Does C++ still deserve a bad rap? by pooya13 on Saturday October 17, 2020 @04:32AM (#24808443)
> Both C and C++ follow the same philosopy: "Trust the programmer"

I disagree. I think ever since it’s inception from C, C++ has tried to increase type safety and continuously move more of the work to the compiler (latest example is concepts). It does empower the programmer to do what they want: OOP, FP, GP...

The philosophy of the language is mostly about abstractions. Abstracting objects, types, resource management etc And using modern C++ features and a recent compiler makes it harder to make mistakes. Using some generally accepted guidelines and static analysis tools helps even further.

Though the syntax is at times ugly due to the age of the language and it has a lot of inertia that makes it hard to get rid of some bad design decisions like some of the defaults, unless someone recreates c++ with the same flexibility and power, and the same powerful compilers/tools but with better syntax and defaults I don’t see the language going anywhere. And I am not holding my breath for another language to quickly be able to reproduce the C++ echo system that have taken decades to develop.

Re:Does C++ still deserve a bad rap? by srg0 on Saturday October 17, 2020 @02:13PM (#24811929)
The philosophy of C++ is about _zero cost_ abstractions.
Re:Does C++ still deserve a bad rap? by fbkr on Saturday October 17, 2020 @03:14AM (#24808062)
> C language has some very limited implicit type conversions

What? C will happily compile this:

    void g() {
        float f = 3.14;
        int* ip = &f;
    }
C++ has no such _craziness_. Your strawman actually has pretty good uses:

    complex c = 3i;
    ... = c + 4;
Would you rather have the last line not compile because 4 is not a complex number? Because one _could_ argue that 4 is a complex number, and C++ can represent this with an implicit constructor.

The issue with C++ is that implicit is the default, not that it exists.

Re:Does C++ still deserve a bad rap? by 59nadir on Saturday October 17, 2020 @08:17AM (#24809418)
One of the main gripes I have with C++ is exactly what you said, that the defaults usually are the wrong for the usual cases and for general sanity.

With that said, C programmers also seem to love their implicit behavior so it's pretty clear where this kind of thinking comes from.

Re:Does C++ still deserve a bad rap? by cygx on Saturday October 17, 2020 @08:51AM (#24809583)
C will happily compile this

Only if you ignore your compiler output: Even TinyCC will warn about that one on default settings. With the flags I use, the code would in fact fail to compile.

Re:Does C++ still deserve a bad rap? by moonchild on Saturday October 17, 2020 @05:24AM (#24808742)
The second case is easily solved by having an overload operator+(complex lhs, int rhs). No need to convert anything.
Re:Does C++ still deserve a bad rap? by fbkr on Saturday October 17, 2020 @04:28PM (#24813023)
This fails when you want `4 + c` or `c + 4.f` etc. So you either have a gross number of overloads doing the same thing, or you just put an implicit constructor to `complex`.

Also, I agree that implicit conversions in general should be avoided, but this complex number example feels like the perfect use case.

Re:Does C++ still deserve a bad rap? by brianush1 on Saturday October 17, 2020 @07:58AM (#24809343)

    complex c = 4;
Would you rather have this line not compile because 4 is not a complex number? Because one _could_ argue that 4 is a complex number, and C++ can represent this with an implicit constructor.

The issue with C++ is that implicit is the default, not that it exists.

Re:Does C++ still deserve a bad rap? by eru on Saturday October 17, 2020 @09:34AM (#24809861)
Haskell solves this reasonably well.

If your data type implements the Num typeclass, you can use literals like 4. (A typeclass in Haskell is similar to what they call an interface in Java.)

There's no automatic conversion happening at all. It's done via overloading literals at compile time. (You can do the same for strings.)

Re:Does C++ still deserve a bad rap? by srg0 on Saturday October 17, 2020 @02:35PM (#24812103)
C++20 introduced concepts, and now it's possible to specify type constraints, like integral, in a way similar to Haskell typeclasses.

What it doesn't solve that by default the compiler tries to find an appropriate implicit conversion. Sometimes it's convenient, sometimes it's harder to see what the code actually does.

Re:Does C++ still deserve a bad rap? by eru on Sunday October 18, 2020 @06:38AM (#24816844)
Yes, concepts help a bit, but I'm not sure whether they would be necessary here.

Yes, the implicit conversion for all values is part of the problem. The Haskell approach only gives you magic for literals.