News for hackers. Stuff that matters.
Re:C++ the Good Parts (2014) by pjmlp on Thursday October 01, 2020 @04:17AM (#24648654)
Only if the objects aren't heap allocated via new/delete, and you happen to forget to call delete on it.
Re:C++ the Good Parts (2014) by platinumrad on Thursday October 01, 2020 @06:38AM (#24649396)
`new` and `delete` have been banned outside of deep library code in every industrial C++ codebase I've ever worked on.
Re:C++ the Good Parts (2014) by todd8 on Friday October 02, 2020 @03:09AM (#24659846)
I don’t have first hand experience in the world of game programming, but I’ve heard that smart pointers aren’t used and old fashioned new and delete are standard practice. (Please correct me if I’m wrong, I’m curious if what I’ve heard about game development is really true.)
Re:C++ the Good Parts (2014) by pjmlp on Thursday October 01, 2020 @07:33AM (#24649707)
Re:C++ the Good Parts (2014) by darkmx0z on Thursday October 01, 2020 @09:11AM (#24650427)
did you check the header of that cpp? they are storing it in a shared_ptr: shared_ptr = referenced counted pointer = RAII

they should have used make_shared, but it is still safe

Re:C++ the Good Parts (2014) by pjmlp on Friday October 02, 2020 @01:56AM (#24659369)
Which isn't exception safe, as any good C++ developer would know.
Re:C++ the Good Parts (2014) by msla on Thursday October 01, 2020 @03:40PM (#24655337)
"Google Does Bad Thing" is not quite equivalent to "C++ Is Bad Language"
Re:C++ the Good Parts (2014) by pjmlp on Friday October 02, 2020 @01:59AM (#24659379)
Indeed, it is even one of my favourite languages, but contradicts the OP's point of every industry C++ codebase has banned new and delete.
Re:C++ the Good Parts (2014) by int_19h on Thursday October 01, 2020 @06:18PM (#24656752)
The Google C++ style guide alone is sufficient evidence to conclude that Google doesn't know how to do C++ properly.
Re:C++ the Good Parts (2014) by pjmlp on Friday October 02, 2020 @04:48AM (#24660517)
Yet they are one of the major contributors to ISO C++ and LLVM, what gives?
Re:C++ the Good Parts (2014) by int_19h on Friday October 02, 2020 @09:55PM (#24668862)
It just means that they still derive value from C++. But I, for one, am very glad that they're not a dominant force in the ISO standard committee.
Re:C++ the Good Parts (2014) by ncmncm on Saturday October 03, 2020 @02:21AM (#24670015)
In a word, not.
Re:C++ the Good Parts (2014) by secondcoming on Thursday October 01, 2020 @07:08AM (#24649569)
Well yes, C++'s destructor behaviour doesn't work if you don't use C++...
Re:C++ the Good Parts (2014) by cgrealy on Thursday October 01, 2020 @08:24AM (#24650072)
That's not really fair.

  Thing* thing = new Thing();
  thing->DoStuff();
  delete thing;
is perfectly valid C++ and has been since the invention of the language. It's not a good idea, but it is valid.

If, OTOH, you do

  Thing* thing=(Thing*)malloc(sizeof(Thing));
  free(thing);
the you fully deserve the inevitable world of pain that is coming your way
Re:C++ the Good Parts (2014) by jcelerier on Thursday October 01, 2020 @10:59AM (#24651609)
> is perfectly valid C++

we're in 2020.

    $ clang-tidy -checks='cppcoreguidelines-*' foo.cpp 
    /tmp/foo.cpp:10:3: warning: initializing non-owner 'Thing *' with a newly created 'gsl::owner<>' [cppcoreguidelines-owning-memory]
      Thing* thing = new Thing();
      ^
    /tmp/foo.cpp:12:3: warning: deleting a pointer through a type that is not marked 'gsl::owner<>'; consider using a smart pointer instead [cppcoreguidelines-owning-memory]
      delete thing;
      ^
    /tmp/foo.cpp:10:3: note: variable declared here
      Thing* thing = new Thing();
      ^
Re:C++ the Good Parts (2014) by cgrealy on Thursday October 01, 2020 @03:46PM (#24655416)
Does it compile? Does it run? Yes, therefore it's valid C++.

I'm not arguing it's good C++, but saying "C++'s destructor behaviour doesn't work if you don't use C++" in relation to using new and delete is clearly nonsense.

Re:C++ the Good Parts (2014) by umanwizard on Tuesday October 06, 2020 @08:40PM (#24704141)
The malloc/free version is perfectly valid C++ too, isn’t it?
Re:C++ the Good Parts (2014) by cgrealy on Tuesday October 13, 2020 @10:32PM (#24772550)
Eh... kind of?

I guess it depends on your definition of "valid".

Let's say we have:

  class Thing
  {
  public:
    Thing() { cout << "created" << endl; }
    ~Thing() { cout << "destroyed" << endl; }
  };
Assuming the happy path, the new/delete version will be functionally identical to a more correct/idiomatic

  {
    auto thing = make_unique<Thing>();
  }
The malloc/free version won't call the destructor, and therefore doesn't do what a "normal" object would do.

It's splitting hairs, I guess, but that's where I'd draw the line.

Re:C++ the Good Parts (2014) by pjmlp on Thursday October 01, 2020 @07:11AM (#24649584)
Which is what plenty of people do across the industry with C++ compilers, they code like C.
Re:C++ the Good Parts (2014) by secondcoming on Thursday October 01, 2020 @08:04AM (#24649926)
Well that's not C++'s fault. Those people are either stuck on a particular compiler version, are in a maintenance mode, or are just unwilling to improve themselves. Maybe there's job security in being able to write code in a deprecated style.
Re:C++ the Good Parts (2014) by badsectoracula on Thursday October 01, 2020 @01:29PM (#24653744)
> or are just unwilling to improve themselves

Or they may not see that stuff as an improvement in the first place (e.g. see Orthodox C++[0]).

[0] https://gist.github.com/bkaradzic/2e39896bc7d8c34e042b

Re:C++ the Good Parts (2014) by Jtsummers on Thursday October 01, 2020 @03:45PM (#24655403)
If I'm reading that right, they start off talking about a minimalist/reduced subset of C++, and then end up concluding: Use C++14 (now two standards ago) and we'll probably recommend C++17 in 2022 (5 year delay).

That seems like a rather weak conclusion given all the words that preceded it. You might as well just start and end with this:

New standards have issues, people don't know how to use them correctly, and compilers are slow to catch up. Wait 5 years to use a standard so all these things are worked out, and you don't have to worry about the details that don't stick.

Re:C++ the Good Parts (2014) by badsectoracula on Friday October 02, 2020 @07:35AM (#24661534)
The C++14 part seem to be added lately and indeed sounds contradictory to what was written previously. As a comment below writes though they use the original Orthodox C++ idea without the C++14 part (and TBH i think the whole "committee" part is a tongue-in-cheek joke).

In any case this is just an example, there are a couple of similar "subsets" with the same idea of keeping C++ use to its bare minimum, it is just that i remember this one because of the name :-P

Re:C++ the Good Parts (2014) by hyperpl on Thursday October 01, 2020 @03:18PM (#24655111)
Wow, I thought I was alone.
Re:C++ the Good Parts (2014) by ncmncm on Friday October 02, 2020 @05:53PM (#24667396)
It is always the right time to learn modern C++.

Discomfort is not a valid reason to avoid learning new things.

Re:C++ the Good Parts (2014) by unishark on Thursday October 01, 2020 @08:47AM (#24650237)
Historically there was a big performance hit for using the fancy added abstractions of C++. Don't know if it's still that bad. But in the past it cost a factor of two or so, whenever I tried to get fancy.
Re:C++ the Good Parts (2014) by jcelerier on Thursday October 01, 2020 @11:01AM (#24651649)
> Historically there was a big performance hit for using the fancy added abstractions of C++. Don't know if it's still that bad. But in the past it cost a factor of two or so, whenever I tried to get fancy.

I don't know how much back in the past it is, but pretty much every time in the last ten years I tried to beat a C++ abstraction, I almost never managed to substantially improve (and since gcc.godbolt.org exists it made it much easier to witness that most of the abstraction layers entirely disappear at -O2)

Re:C++ the Good Parts (2014) by ncmncm on Friday October 02, 2020 @08:33PM (#24668443)
Historically, meaning "in the '90s". It has been quite a long time since the '90s. Many readers here weren't even born yet when C++ abstraction overhead was last a thing.
Re:C++ the Good Parts (2014) by pjmlp on Thursday October 01, 2020 @08:27AM (#24650091)
Like Android NDK?
Re:C++ the Good Parts (2014) by secondcoming on Thursday October 01, 2020 @12:34PM (#24652974)
No idea, I've no experience with it.
Re:C++ the Good Parts (2014) by pjmlp on Friday October 02, 2020 @02:03AM (#24659405)
You should, then you will see how much C++ it actually uses.

It exposes everything as C APIs, even thought it is a mix of Java and C++ on the implementation side, leaving the C++ developers to write their own type safe abstractions from scratch.

Most just can't be bothered and write C in C++.

Then there is the whole issue how, following Google C++'s guidelines, the NDK is actually implemented.

Re:C++ the Good Parts (2014) by steerablesafe on Thursday October 01, 2020 @04:44AM (#24648801)
smart pointers exist
Re:C++ the Good Parts (2014) by pjmlp on Thursday October 01, 2020 @04:53AM (#24648870)
Just like value types and deterministic resource management in GC languages.