Slashdot Mirror


Bjarne Stroustrup Announces the C++ Core Guidelines

alphabetsoup writes: At CppCon this year, Bjarne Stroustrup announced the C++ Core Guidelines. The guidelines are designed to help programmers write safe-by-default C++ with no run-time overhead. Compilers will statically check the code to ensure no violations. A library is available now, with a static checking tool to follow in October.

Here is the video of the talk, and here are the slides.The guidelines themselves are here.

262 comments

  1. No runtime overhead? by Anonymous Coward · · Score: 0

    Praise the computer gods!

  2. Wait what? by Virtucon · · Score: 4, Funny

    If you take all the fun out of finding memory leaks and stack overflows what fun is there to C/C++? I mean I just love using AutoPtr everywhere, it's perfect!

    --
    Harrison's Postulate - "For every action there is an equal and opposite criticism"
    1. Re:Wait what? by Anonymous Coward · · Score: 0

      std::auto_ptr is deprecated. You should be using std::unique_ptr, or std::shared_ptr which address the issue of pointer ownership.

    2. Re:Wait what? by tepples · · Score: 2

      If you take the drudgery out of finding stack overflows, then perhaps you'll have more time to d%%% around on //||] stackoverflow.com.

    3. Re:Wait what? by Anonymous Coward · · Score: 0

      This appears to be an argument for keeping the drudgery where we found it.

    4. Re:Wait what? by Anonymous Coward · · Score: 1

      We apologize for the newly discovered and intentional faults of std::safe::extrasafe_ptr and it has been sacked and no responsibility has been accepted. Please use std::reallysafe::extrasafewontleak_ptr in the meantime. Including the majestik møøse A Møøse once bit my sister...

    5. Re:Wait what? by Pseudonymous+Powers · · Score: 5, Funny

      Everything in C++ is now deprecated except the word "safe". So you should really be using safesafe::safe_safe_safe in such situations. And in all other situations. When in doubt, just keep typing "safe" until it's safe.

    6. Re:Wait what? by Virtucon · · Score: 1

      which address the issue of pointer ownership.

      I own the pointers, they're all mine!

      --
      Harrison's Postulate - "For every action there is an equal and opposite criticism"
    7. Re:Wait what? by Anonymous Coward · · Score: 1

      std::auto_ptr is deprecated. You should be using std::unique_ptr, or std::shared_ptr which address the issue of pointer ownership.

      You perfectly highlight one of the reasons why programming is not a fun hobby for me anymore.

    8. Re:Wait what? by Anonymous Coward · · Score: 0

      There is rarely in any need for a hobbyist to use bleeding edge stuff unless they are particularly interested in that aspect of a project. If anything, they are more likely to pick up new stuff just because tutorials will use newer stuff. That said, shared_ptr has been the better option for over 15 years.

    9. Re:Wait what? by Anonymous Coward · · Score: 0

      This is c++, not php.

    10. Re:Wait what? by Anonymous Coward · · Score: 0

      The boost shared_ptr template was just a way to add reference counting to objects that sadly didn't plan for it. AddRef / Release concepts have been around much longer. When your reference count reaches zero, either self destruct or return yourself to your owner for recycling.

    11. Re:Wait what? by Anonymous Coward · · Score: 0

      You perfectly highlight one of the reasons why programming is not a fun hobby for me anymore.

      I'm sorry writing stable C++ programs isn't fun. You can still be a web developer if you want.

    12. Re: Wait what? by Anonymous Coward · · Score: 0

      I'll have the safe, safe, safe, safe, safe, baked beans, safe, safe, safe and safe. But with out the baked beans.

      You mean you want safe, safe, safe, safe, safe, safe, safe, safe, safe and safe? ugh!

    13. Re:Wait what? by david_thornley · · Score: 1

      Languages are either dead or they change over time. Even COBOL and Fortran get periodic updates. If you program in Visual Basic 6 or Snobol or something like that, you can ignore this.

      If you're programming as a hobby, you can generally ignore the changes and program in the language version you're comfortable with. If you're maintaining a professional codebase, then you should keep up with the language changes. I get paid to help keep a big C++ codebase in good shape, so I keep up with things.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    14. Re:Wait what? by luis_a_espinal · · Score: 1

      std::auto_ptr is deprecated. You should be using std::unique_ptr, or std::shared_ptr which address the issue of pointer ownership.

      I think he meant it with a flair of irony. I dunno, just guessing.

    15. Re:Wait what? by Anonymous Coward · · Score: 1

      They are just chicken-shit scared of Swift, Rust and Sappeur. Languages which prove you do not need the insecure crapola from the C age to create secure, efficient and real-time capable software.

      C and C++ are enablers of cyber warfare and a mortal enemy of the IT industry.

      It was much better during the days of memory-safe Algol, but then came along the "free" stuff from Bell Labs. Free as in "free trojan horse".

    16. Re:Wait what? by Darinbob · · Score: 1

      C++ is great. Where else can you reinvent bad garbage collection techniques every day? Modern languages like Java come with bad garbage collection built in!

    17. Re:Wait what? by Darinbob · · Score: 2

      And reference counting has been known to be a terrible garbage collection technique for four decades. Yes, it's problematic to add good garbage collection to a language compiled to bare machine code, especially with smaller CPUs or less memory, and so it the reference counting technique keeps getting used even in modern times.

      It is actually easy to manage the memory yourself (though less efficient than incremental generational scavaging techniques) but there has been a generation of programmers trained to believe that manual memory management is evil. There also seems to be this sort of mystic vision that if only we could solve the memory management problem that programming will finally become pain free and we will no longer need to learn to be disciplined. The whole goal, probably driven by management, is to allow poorly trained engineers to write software.

    18. Re:Wait what? by Darinbob · · Score: 4, Insightful

      If you're using a professional code base, then you're better off NOT using all the latest features just because they're new! Sure, learn about the new language features, but that doesn't mean you should embrace them. Let other people be the guinea pigs.

    19. Re:Wait what? by w_dragon · · Score: 1

      Most of the stuff in C++11 isn't really new, a lot of it has been in Boost for a very long time. A lot of it is also stuff for safety that doesn't affect the binary - like the override keyword. Avoiding it because it's new is really just saying you're not willing to learn.

    20. Re:Wait what? by angel'o'sphere · · Score: 1

      Reference counting is not a GC technique but a memory management technique.

      And it is very valid in cases where you upfront know that it will work fine.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    21. Re:Wait what? by Pseudonym · · Score: 2

      They are just chicken-shit scared of Swift, Rust and Sappeur.

      The language that everyone hates is not scared of the languages that nobody uses.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    22. Re:Wait what? by Pseudonym · · Score: 1

      And reference counting has been known to be a terrible garbage collection technique for four decades.

      More accurately, it was a terrible garbage collection technique four decades ago, in an era when the disparity between RAM and cache wasn't as large as it is today, when multicore wasn't common, and when compilers weren't as clever as they are now. Today, it's a surprisingly competitive technique.

      Modern compilers can go to a lot of trouble to avoid manipulating reference counts when it's not needed, and can use static type information to prove that some data structures are acyclic. Of course, in C++, that last point isn't even an issue, since the programmer gets to control when reference counts get manipulated.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    23. Re:Wait what? by Darinbob · · Score: 1

      True, it's not really a GC technique. But... I have seen garbage collectors in some popular interpreters still doing this. Reference counting is good for things with a low reference count - like number of users of a file or window.

      However sometimes reference counting can pass the buck on responsibility. Ie, if I "know up front" that I can alloc memory, call a sequence of functions, then free the memory then this should be adequate. If some in a called function retains a reference to the memory then that's an error that needs to be fixed. But because shared_ptr is so easy to use I have seen people use that technique to mask the error, as if it was better to leak the memory than to locate and fix the bug.

    24. Re:Wait what? by Darinbob · · Score: 1

      Ya, but Boost is a bit strange in my view. It's heavy heavy templated code nearly impossible to debug. It violates the "keep it simple" technique I like to use. Maybe there are parts of Boost that are decent though.

    25. Re:Wait what? by Darinbob · · Score: 1

      Reference counts can lead to loops which then results in memory that is not reclaimed. Its also wasteful of memory compared to just having two or three bits. Then what if you overflow your reference count? A "real" garbage collector can make good use of modern CPUs (like dirty bits on pages, etc) and are faster than reference counting and malloc/free. They actually move stuff around in memory which also improves locality of reference as well.

      But they don't fit in well with most languages that have pointers, and especially in C++. Garbage collection is best in languages that don't have allocation or freeing of memory. The best C++ has is a best-effort approach that claims to find "most" garbage and it doesn't attempt to move memory around.

      Multicore should make garbage collection easier, because GC is something that runs on the side of the program. No need to interleave GC steps into your program when it can run as a separate task. But language implementers seem have forgotten how to do this stuff, or never learned in the first place. The computing world today is designed around the idea that you can always throw more memory at a problem.

    26. Re: Wait what? by Anonymous Coward · · Score: 0

      That's double-plus deep!

    27. Re:Wait what? by Tranzistors · · Score: 1

      My impression is that the features that are in external libraries are more difficult to debug than those that are in the language itself (or standard libraries). So just because boost is more obscure doesn't mean that the same thing in std is.

    28. Re:Wait what? by Xtifr · · Score: 1

      Huh. It's not the templates that bother me; it's the bazillions of obscure macros you're expected to use to make sure that your code works on dozens of broken compilers I don't care about, and which come with 37 different definitions that all depend on the exact release of compiler you're using and it's almost impossible to figure out which one is actually in use, and half the time, if you're using a decent, up-to-date compiler, you can't even tell if you've got all the macros you need in the right places, because your compiler is too smart to even need those macros, so your code doesn't actually work right with other compilers that are supposedly supported by the libraries you're using.

      The template stuff is relatively easy if you have a decent modern compiler.

    29. Re:Wait what? by Kiaser+Zohsay · · Score: 1

      which address the issue of pointer ownership.

      I own the pointers, they're all mine!

      ALL YOUR POINTERS ARE BELONG TO US!

      --
      I am not your blowing wind, I am the lightning.
    30. Re:Wait what? by Darinbob · · Score: 1

      Yes all that stuff too. I was the C++ "expert" at one company, meaning the one who translated the obscure gcc error messages, and who kept the runtime working. And Boost was difficult to maintain at times.

    31. Re:Wait what? by david_thornley · · Score: 1

      You are better off using some of the latest features because they're better than what the language had previously. If you don't find them useful, don't use them. The C++ Standards Committee has generally been pretty good about not incorporating features unless people had introduced them as compiler extensions, so by using the latest standard features you're not generally on the bleeding edge.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  3. What's the name of the Library? by the_skywise · · Score: 1

    CPPCoreGhost?

    1. Re:What's the name of the Library? by Godai · · Score: 1

      It's the GSL -- Guideline Support Library. It's header-only, nothing to link against, and it's being kept small to make it easy for it to be cleared for use.

      --
      Wood Shavings!
      - Godai
    2. Re:What's the name of the Library? by Anonymous Coward · · Score: 0

      Another boilerplate that I have to add to my projects.

    3. Re:What's the name of the Library? by Anonymous Coward · · Score: 0

      And at this point it doesn't follow its own guidelines.

  4. Re: And Yogi Says Dejavu all over again! by Anonymous Coward · · Score: 0

    He really didn't say all the things he said.

  5. As always with C++, the truth is more nuanced by beelsebob · · Score: 4, Interesting

    For example, one of the guidelines here is to always prefer make_shared over std::shared_ptr(new ...). That's good advice for a couple of reasons
    1) it allocates your memory for the shared_ptr control block and the object contiguously
    2) it means you can't separate the allocation from the creation of the shared ptr and end up with an owner who's not looking at the shared ptr in-between.

    However, it also means that if you have any weak_ptrs pointing at the end of that shared_ptr, the object itself won't go away until all the weak_ptrs do too (because the control structure won't go away until they do, and they're contiguously allocated).

    1. Re:As always with C++, the truth is more nuanced by serviscope_minor · · Score: 1

      Huh?

      Are you complaining that a set of coding guidelines isn't a new language standard?

      --
      SJW n. One who posts facts.
    2. Re:As always with C++, the truth is more nuanced by rippeltippel · · Score: 1

      However, it also means that if you have any weak_ptrs pointing at the end of that shared_ptr, the object itself won't go away until all the weak_ptrs do too (because the control structure won't go away until they do, and they're contiguously allocated).

      Shouldn't you lock the weak_ptr before using it?

    3. Re:As always with C++, the truth is more nuanced by Anonymous Coward · · Score: 0

      So if your implementation was shoddy to start with, maybe you should fix that first...

    4. Re:As always with C++, the truth is more nuanced by bluefoxlucid · · Score: 0, Flamebait

      I'm complaining that Bjarne Stroustrup is a little girl.

    5. Re:As always with C++, the truth is more nuanced by Anonymous Coward · · Score: 0

      Shouldn't you lock the weak_ptr before using it?

      Doesn't matter. While the usable lifetime of the object itself is controlled by the number of owning pointers, the lifetime of the structure that stores reference counts is normally determined by both owning and weak pointers. (The control block not disappearing until all the weak pointers go away is important, because when you lock a weak pointer whose underlying object disappeared, you need to have a valid bit of data around which says "nope, this object is no longer valid - don't use it")

      The upshot of this is that if you allocate the object and control block in a single "malloc" (or equivalent) call, you can't return that block of memory to the allocator until all the users of it are done, i.e. until the control block also reaches the end of it's life. So unless you're doing something fancy with memory allocation in make_shared and the corresponding deletes, in practice the chunk of memory doesn't get returned to the allocator until all the pointers - both weak and shared - disappear.

    6. Re:As always with C++, the truth is more nuanced by Anonymous Coward · · Score: 0

      Good point, but note that the destructor of the object does get called as soon as all the shared_ptrs die. This means that it is only the object itself that is not freed, everything it owns is freed normally. In practice, this means that in practice this does not quickly get problematic.

    7. Re:As always with C++, the truth is more nuanced by david_thornley · · Score: 1

      It also helps exception safety. A call like Foo(new Bar, new Bar) can allocate one Bar and throw on the next, creating a leak. Putting them into shared pointers in the call doesn't work, since shared_ptr(new Bar) is not a function, and so the compiler is justified in doing both allocates and then putting each pointer into a shared_ptr. make_shared() is a function, and must be executed as a unit, so that enforces the order of allocate, make_shared, allocate, make_shared. No memory leaks there.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    8. Re: As always with C++, the truth is more nuanced by slack_justyb · · Score: 2

      Agreed, however some of us inherit the problems and do our best to convince the uppers to allocate time to clean things up. Let's not forget that there are a whole slew of Lennart Poettering wannabes out there that have everything to prove using some of the most horrible coding styles that could ever exist.

    9. Re:As always with C++, the truth is more nuanced by Anonymous Coward · · Score: 0

      While you were tracking all of your structure pointers, I wrote up a prototype web service in Java (or C#, take your pick), integrated it with Mongo and deployed it in an HA configuration on AWS.

      </tongue-in-cheek>

    10. Re:As always with C++, the truth is more nuanced by D.McG. · · Score: 1

      There's a much easier way to accomplish this: use reference counted objects, rather than smart pointer templates around dumb objects.

      Define IRefCount to include AddRef (or Retain) and Release methods. Make all interfaces extend IRefCount. Define CRefCount to include a FinalRelease method; which by default calls "delete this", and will be invoked when the reference count reaches zero. This method can be overridden to return objects to pools, be handled by some other deallocator, etc.

      This removes the need to create two objects, and ensures all shared objects can be passed around like candy. If you really still want a smart pointer template, it's easy enough to create one that simply calls AddRef and Release on the IRefCount object on your behalf as appropriate. An important difference is that the ref count is part of the object, not the smart pointer.

    11. Re: As always with C++, the truth is more nuanced by Anonymous Coward · · Score: 0

      Make sure to throw it all in a docker container. I hear it's the future.

    12. Re:As always with C++, the truth is more nuanced by Anonymous Coward · · Score: 0

      There once was a student who approached his master and said "Master, I have discovered the perfect garbage collection scheme! Every object in the system will have a reference count that is incremented when it is referenced by another object and decremented when the reference goes away and when the reference count reaches zero it can be freed!"

      The Master replied: "There once was a student who approached his master and said..."

    13. Re:As always with C++, the truth is more nuanced by david_thornley · · Score: 1

      We're still going to need two objects, one a base object and one a pointer object. If we use raw pointers, the reference count will not be incremented and decremented properly, and we need the reference count to reliably be equal to the number of pointers extant. Therefore, the pointer needs to have its own copy constructor, copy assignment operator, and destructor, which will call the appropriate increment and decrement methods (the decrement method to include the deletion as a special case). If we keep the reference count with the object instead of with the pointer, we can keep the pointer size down without indirection.

      We need to document heavily that IRefCount (or something more according to C++ naming) is to be inherited virtually, as otherwise we could have more than one reference count if we add it to multiple levels of a class hierarchy. (C++ multiple inheritance can be tricky to get right.)

      So, we've got the pointer object, which will contain the pointer and have some attached functionality, and the reference count mixin. This works as long as we can easily modify the class structure, but it does require a fairly sophistication serialization/deserialization system to keep the modified and unmodified objects in sync. In addition, since it changes the memory layout of a class, it can lead to slow compiles.

      With this, we also don't get weak_ptr functionality. A shared_ptr object has a shared pointer count and a weak pointer count. This makes it possible, for example, to have a circular list that can be destructed: have one link be a weak_ptr and everything else a shared_ptr. The object itself is destructed when the shared pointer count goes to zero, and the shared_ptr object when both go to zero. (A weak_ptr does nothing on its own, but can be converted to a shared_ptr if the target object is still there.)

      I don't see this as being easier than shared_ptr, although it is superior for some purposes.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    14. Re:As always with C++, the truth is more nuanced by D.McG. · · Score: 1

      I only brought this up as an alternative to yet-another redefinition of shared_ptr. We don't need new libraries to have shared objects.

      If you're looking for the lazy approach, then yes, the smart pointer object can be used to call AddRef / Release for you. Or you could just call these methods yourself and call it a day, like we did in Objective-C for years until ARC came around. The smart pointer object in this design is optional.

      I think you missed the point with the pointer object. There is no reference count mix-in regarding the pointer object. The ref count is store and managed by the base class (CRefCount) of all derived classes that implement IRefCount. The C++ multiple inheritance here is not that tricky. If one cannot handle the diamond pattern, one should not be coding in C++.

      A weak reference to an IRefCount object can also be converted to a strong reference by simply calling AddRef.

      Deserialization in other languages like Objective-C was done by calling retain in the same way. If it should be weak, it's not retained when deserialized.

      My last project used this C++ design for all classes, and it did not impact compile times (the build of 9 dylibs and the app took 90 seconds total on an I7).

    15. Re:As always with C++, the truth is more nuanced by Anonymous Coward · · Score: 0

      It is very much close to perfect. Massive systems like CATIA rely on this for the best part of their memory allocation needs. They model entire airplanes on CATIA. Like the A380 or the B787.

      But of course sometimes one will need other schemes like allocating on stack and allocating on a contiguous array.

    16. Re:As always with C++, the truth is more nuanced by Anonymous Coward · · Score: 0

      I worked on CATIA source code and I invented a language which is essentially a memory safe C++ variant, Sappeur.

      Yes, reference counting goes a long way, but surely there are corner cases where you have to use different mechanisms.

      Apple seems to think along the same lines with Objective C and Swift. CATIA is the market leader in CAD and Apple is the market leader in phones and high end computers, arguably. Apple and Dassault Systemes are some of the most valuable corporations both financially and in other ways.

      If you want cheap dreck, there are garbage-collected languages out there...

    17. Re:As always with C++, the truth is more nuanced by spitzak · · Score: 2

      We're still going to need two objects, one a base object and one a pointer object. If we use raw pointers, the reference count will not be incremented and decremented properly, and we need the reference count to reliably be equal to the number of pointers extant. Therefore, the pointer needs to have its own copy constructor, copy assignment operator, and destructor, which will call the appropriate increment and decrement methods (the decrement method to include the deletion as a special case). If we keep the reference count with the object instead of with the pointer, we can keep the pointer size down without indirection.

      This is no more complicated than what has to be done with shared_ptr. And you are confused, you can use raw pointers all you want, as long as you know there is a shared_ptr pointing at the object. This happens in many cases.

      We need to document heavily that IRefCount (or something more according to C++ naming) is to be inherited virtually, as otherwise we could have more than one reference count if we add it to multiple levels of a class hierarchy. (C++ multiple inheritance can be tricky to get right.)

      So, we've got the pointer object, which will contain the pointer and have some attached functionality, and the reference count mixin. This works as long as we can easily modify the class structure, but it does require a fairly sophistication serialization/deserialization system to keep the modified and unmodified objects in sync. In addition, since it changes the memory layout of a class, it can lead to slow compiles.

      It's not a "mixin". It is a base class. This avoids your supposed problems.

      With this, we also don't get weak_ptr functionality. A shared_ptr object has a shared pointer count and a weak pointer count. This makes it possible, for example, to have a circular list that can be destructed: have one link be a weak_ptr and everything else a shared_ptr. The object itself is destructed when the shared pointer count goes to zero, and the shared_ptr object when both go to zero. (A weak_ptr does nothing on its own, but can be converted to a shared_ptr if the target object is still there.)

      You can implement weak_ptr in EXACTLY the same way make_shared does it. The object is destroyed but the memory is not freed until the weak_ptr count goes to zero. In fact it is fairly easy to have "an object that supports weak_ptr" be a different base class than the plain refcounted object, thus you don't pay for the weak_ptr overhead on every pointer (though you can't make a weak_ptr unless the object is derived from the correct base class).

      I don't see this as being easier than shared_ptr, although it is superior for some purposes.

      It is enormously easier when you have to do the equivalent of make_shared_from_this (or whatever they called it), and to avoid constructor shenanigans so that the user has to call make_shared and not construct raw objects. The implementation is about the same as shared_ptr.

      Boost called this an "intrusive pointer" but they did not support weak pointers. That could be done with a few extra calls. It was a bit ugly as they tried to not define the base class (instead it called functions that the class defined to inc/dec the ref count), I think insisting that everything be based on a refcounted base class would work just fine.

    18. Re: As always with C++, the truth is more nuanced by Darinbob · · Score: 1

      And I wrote my own OS in C while you were busy doing that.

    19. Re:As always with C++, the truth is more nuanced by david_thornley · · Score: 1

      One difficulty with raw pointers in this case is that you have to know what's an owning raw pointer and what's a non-owning raw pointer. As far as not using an object and maintaining the reference count by hand, you're going to screw up sometime, and that's going to be a difficult error to find. In C++, I know that a unique_ptr reflects ownership, a shared_ptr reflects shared ownership, it's a good convention to say raw pointers do not own, and that shared_ptr won't mess the reference count up.

      I don't know what you mean by "base class" vs. "mixin". You seem to be visualizing IRefCount like a Java or C# interface, and the best approximation to that in C++ is a mixin-type class. In C++, there really is no difference between a base class and a mixin, although a mixin is more likely to use virtual inheritance. If you're insisting that this be baked into the class, you're losing some flexibility. I can take anything and wrap it in a shared_ptr without having to either have foreseen that sometime I might want to use shared ownership or recompiling everything.

      How do you intend to implement weak_ptr here? What are the alternatives? When the shared count goes to zero, you can neither delete the object nor not delete the object. You seem to be suggesting allocating the memory, using placement new, and then deleting the object when the shared count goes to zero and releasing the memory when both counts are zero. This involves accessing a member of the object after the object is destructed, which is undefined behavior since the object no longer exists. If you want to reference the counts after the object has been destructed, the counts have to be in another object, at which point you can just use shared_ptr. There's also the issue that, if the object would normally be allocated with placement new (some programs maintain a pool for a frequently allocated class, for example), you've screwed that up, so you may need to rewrite the function that handles destruction from use to use (there's no reason why one part of the program couldn't use standard allocation while another used a memory pool with placement new).

      I still fail to see that this is easier than shared_ptr, particularly since shared_ptr is already part of the standard library.

      This can be superior to shared_ptr in the case where you can put the reference count into the object and use a intrusive_shared_ptr pointer object. The intrusive_shared_ptr contains only an ordinary pointer (unless you put it in an inheritance hierarchy, in which you'll get a vtable pointer, but there's no point in doing that), and there's only one object to allocate and deallocate.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    20. Re:As always with C++, the truth is more nuanced by Anonymous Coward · · Score: 0

      Just to clarify, the object will be destructed (destructor called) once all remaining shared_ptrs are destroyed. Any remaining weak pointers after that will not help the object from being destructed.

      But the underlying raw memory (which is not an object) will be retained until the control block is deleted, assuming the object was allocated contiguous with the control block (eg via std::make_shared).

    21. Re:As always with C++, the truth is more nuanced by w_dragon · · Score: 1

      The other downside to make_shared is that I don't think there's an equivalent to std::nothrow, so you must have exceptions enabled to use it and handle out-of-memory conditions.

    22. Re: As always with C++, the truth is more nuanced by D.McG. · · Score: 1

      Interfaces in C++ are simply structs that contain only pure virtual methods. No one uses the non-technical term "mix-in".

    23. Re:As always with C++, the truth is more nuanced by angel'o'sphere · · Score: 1

      Sorry, but this: In C++, there really is no difference between a base class and a mixin,
      is complete nonsense.

      A mixin in C++ is e.g. a template class that inherits from its template parameter(s).

      A interface is a class where all methods are defined pure virtual.

      There is no direct connection between both concepts.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    24. Re:As always with C++, the truth is more nuanced by Pseudonym · · Score: 2

      Yet still no modules.

      One of these days, Stroustrup will realise (like Stepanov did) that Simula's object model was a mistake.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    25. Re:As always with C++, the truth is more nuanced by serviscope_minor · · Score: 1

      Oh yes? A "mistake".

      And what would you replace it with, then?

      --
      SJW n. One who posts facts.
    26. Re:As always with C++, the truth is more nuanced by bluefoxlucid · · Score: 1

      Candycanes and unicorns.

    27. Re:As always with C++, the truth is more nuanced by Pseudonym · · Score: 1

      A module system, and a mathematically sound object system (like O'Caml, Haskell, etc).

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    28. Re:As always with C++, the truth is more nuanced by beelsebob · · Score: 1

      Yes, but with the million dollars you spent on hardware to run your inefficient code, I hired 5 coders for a year, and got way further down the road with a well designed, architected and thought out system rather than a hack on top of a hack.

    29. Re: As always with C++, the truth is more nuanced by david_thornley · · Score: 1

      People who spent time using Lisp use that term. Then again, I appear to be one of the three people in the world who really likes both C++ and Common Lisp.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    30. Re:As always with C++, the truth is more nuanced by Zero__Kelvin · · Score: 1

      "There's a much easier way to accomplish this: use reference counted objects, rather than smart pointer templates around dumb objects. "

      You should contact Bjarne and explain this incredible discovery! I have no doubt he has never heard of it, will be amazed at your brilliance, and abandon his approach immediately!

      --
      Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
  6. News at eleven by Anonymous Coward · · Score: 3, Informative

    Imperative programmers reinvent functional programming concepts, but in a shitty way. More at eleven.

    1. Re:News at eleven by BlackHawk-666 · · Score: 1, Troll

      When functional languages can do real world high speed low latency application development that rivals c++ for performance, then I'll consider giving up c++. Until then, we'll re-invent your shitty programming concepts in a way that is performant.

      --
      All those moments will be lost in time, like tears in rain.
    2. Re:News at eleven by Anonymous Coward · · Score: 0

      Rather, more at 10 on Greenspun TV Network.

    3. Re:News at eleven by Anonymous Coward · · Score: 0, Informative

      Haskell is faster for HTTP. (I would go so far as to say that functional programming has solved the issue of extremely fast HTTP serving.)

      Haskell is 4x faster than extremely optimized C++ code for parsing subversion log files. (Although admittedly this is a rather specific application.)

      The claim that functional programming sacrifices performance and/or latency (which I don't think you are making, but many people are) is false. Yes, development is needed, but there are plenty of missed opportunities.

    4. Re:News at eleven by Anonymous Coward · · Score: 0

      Also, wake us up when you recover from Garbage Collection.

      Some people want high-quality GUIs and other realtime code and cannot stand any interruption because something really bad will happen if they cannot react in 10ms or less.

    5. Re:News at eleven by Anonymous Coward · · Score: 0

      I'd like to subscribe to your newsletter.

      Next time I need a script language that runs like shit and isn't available on any platforms, that is.

    6. Re:News at eleven by Anonymous Coward · · Score: 0

      People who know anything about history would say it's the other way around.

      If you mean C++ or Java when you say "imperative" then say C++ or Java.

    7. Re:News at eleven by Anonymous Coward · · Score: 0

      The parent is only a troll if the grand parent is also. Moderators, show your might!

  7. Effort will help by Anonymous Coward · · Score: 0

    As a hiring management and C++ expert, I can tell you that most C++ programmers are bad because they are not well informed. C++ demands the use of best practice and the avoidance of pitfalls. If you call yourself a C++ professional you should be thoroughly familiar with the work of Meyers, Sutter, Lakos, Stroustoup... This effort can only help.

    1. Re:Effort will help by Anonymous Coward · · Score: 0

      "Stroustroup. This effort can only help."

      Hmmmm....

    2. Re:Effort will help by Anonymous Coward · · Score: 0, Funny

      Sounds like you're a nincompoop with an MBA who cares more about name dropping and buzzword bingo than you do about code. Pro tip: nobody takes an anonymous coward seriously when they claim to be an "expert". Trust me. I am an expert at detecting no-nothing management boneheads.

    3. Re:Effort will help by umghhh · · Score: 1

      You did not hear this sound? It was like whizzzz or whoooooosh or alike.

    4. Re:Effort will help by Anonymous Coward · · Score: 0

      Yes, from your comment we all gather you are a "C++ expert". If you are indeed a hiring manager then I feel sorry for the company you work for, because all good programming professionals I know including myself would detect the smell of your bullshit miles away from your office and would never work for your company.
      One of the first things to look for when accepting a new job is the profile of the hiring manager. If the hiring manager is incompetent with little practical skills then there is a high chance most of the dev employees are incompetent as well.

    5. Re:Effort will help by Anonymous Coward · · Score: 0

      Piss off Troll!!!

    6. Re:Effort will help by Anonymous Coward · · Score: 0

      What fun would that be?

    7. Re:Effort will help by david_thornley · · Score: 1

      FWIW, Lakos' book (he wrote only one, but it's a good one) was published in 1996 with a possibly new edition in 1997. Since some of the recommendations appear quite specific, I don't know how applicable it is in 2015.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  8. Re:Frist! by Anonymous Coward · · Score: 3, Funny

    "print" is deprecated. You must now use the safe_print_n function and get a safe pointer back using the SafetyFirst() method of the SafeLiteral class.

    Because safe by default, amirite?

  9. Re:Frist! by lisaparratt · · Score: 1

    Safer than you could possibly imagine.

  10. Bjarne should not be writing that by Carewolf · · Score: 3, Insightful

    He has a connecting to all the features he put into C++ and any coding guidelines should include thing that should not be used. First among those are exceptions, unfortunately Bjarne has never wanted to admit C++ exceptions were a mistake.

    1. Re:Bjarne should not be writing that by Anonymous Coward · · Score: 0

      There is nothing wrong with C++ exceptions. There are many features in C++ that can make your code difficult to reason about, but this doesn't mean that these features are mistakes. It just means that you don't know the language well enough to safely and readably employ such features.

      I can hear your objections now. "But Google bans the use of exceptions in their C++ codebases! Surely they must be a mistake!" This is the same company that brewed up its own language because one of their senior developers basically came out and said that Google's younger developers are too stupid to be trusted with C++.

      He's probably right.

      Face it. Most "C++ developers" don't actually know C++. They know bits and pieces of C++, and are mystified and spooked by the parts that they don't know, be it templates, exceptions, whatever.

      For those of us that have actually bothered to learn the entire language and keep up to date on its development, "mistakes" like exceptions mean that I can write less code with less bugs in less time.

    2. Re:Bjarne should not be writing that by Anonymous Coward · · Score: 0

      "But Google bans the use of exceptions in their C++ codebases! Surely they must be a mistake!"

      Google doesn't make a judgement about exceptions in general. Google's current codebase isn't designed for exceptions and they didn't want to introduce exception handling this late in the development.

    3. Re:Bjarne should not be writing that by luis_a_espinal · · Score: 1

      He has a connecting to all the features he put into C++ and any coding guidelines should include thing that should not be used. First among those are exceptions, unfortunately Bjarne has never wanted to admit C++ exceptions were a mistake.

      That's a hard call. Exceptions have their place. The thing I cannot stomach is the catch(...) construct. I understand the technical reasons for having it. I still think that was a bad design decision that outweighs the pros. It is almost always impossible to quickly pinpoint the origin of the error (specially if you do not have a core dumb to at least analyze.)

    4. Re:Bjarne should not be writing that by Carewolf · · Score: 2

      It is not just Google that bans them, it is industry best practise not to use them. While you can make exception-safe code by containing all state information in classes that can properly unwrap them, it is extremly tedious and very error-prone to do. Basically the only safe thing to do after catching an exception is quiting, which means you might as well exit, crash or catch a signal.

    5. Re:Bjarne should not be writing that by david_thornley · · Score: 1

      If your code isn't exception-safe, it's probably bad in several other ways. It's not that difficult to get it right, if you have a clue, and will avoid other problems. If you think industry best practice is C++ that isn't exception-safe, I don't want to work where you do.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    6. Re:Bjarne should not be writing that by angel'o'sphere · · Score: 1

      I don't realy get why people write this nonsense.

      You are at an ATM, you insert your card, the card can not be read: DamagedCardException.

      The card can be read and you are asked to enter the code, code is wrong: InvalidCodeException

      You enter the code three times wrong: CardSwallowedException

      You enter the code correctly and want to withdraw $1000, but the bank does not acknowledge: TransactionNotPossibleException.

      NONE of the above exceptions will terminate the ATM software but will return with a hopefully meaningful message to the main menu.

      (*Facepalm*)
      For the application it should be absolutely no difference if you handle errors with error codes or with exceptions. The user should not see any difference, the program should behave exactly the same.
      However: working with exceptions is 100 times easier for developers than working with error codes.
      If that is not true for you then for funk sake: you should definitely not be a programmer!!!!

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    7. Re:Bjarne should not be writing that by goose-incarnated · · Score: 2

      I don't realy get why people write this nonsense.

      You are at an ATM, you insert your card, the card can not be read: DamagedCardException.

      The card can be read and you are asked to enter the code, code is wrong: InvalidCodeException

      You enter the code three times wrong: CardSwallowedException

      You enter the code correctly and want to withdraw $1000, but the bank does not acknowledge: TransactionNotPossibleException.

      NONE of the above exceptions will terminate the ATM software but will return with a hopefully meaningful message to the main menu.

      I wouldn't consider any of those to be exceptions; return DamagedCard, InvalidCode, CardSwallowed or TransactionNotPossible (+ TransactionSuccessful). This allows the caller to be a state machine that changes to different states simply by switching on the return value of the function:

      while (1) {
      state = readCard ();
      switch (state) {
      case DamagedCard: //...
      case InvalidCode: //...
      case CardSwallowed: //...
      case TransactionNotPossible: //...
      case TransactionSuccessful: //...
      }

      is a great deal cleaner than

      try {
      readCard();
      // Handle successful return
      } catch (DamagedCardException e ) {
      // Handle exception
      } catch (InvalidCodeException e ) {
      // Handle exception
      } catch (CardSwallowedException e ) {
      // Handle exception
      } catch (TransactionNotPossibleException e ) {
      // Handle exception
      }

      By classifying non-exceptional conditions as an exceptional out of the ordinary condition you tend to handle it in an ad-hoc way, treating it as an error. All of those conditions above are *not* errors, they are part of the logic for the ATM. Running out of money in an ATM is also not an error. These things should be handled in the state-machine for the main logic so that at least formal methods can be used to verify that the logic has a well-defined flow for every state. Moving logic out of the normal program flow is asking for errors when someone changes something and it is then not apparent by checking the program logic.

      I wrote ATM software for a long long time. Nothing was considered an exception - everything (including errors) was simply a signal to move to some other state which would handle the signal properly. Exceptions are most-used and well-loved by non-CS programmers, because it lets you place undocumented local jumps that bypass the documented logic-flow. Exceptions are hated by CS programmers for the same reason.

      --
      I'm a minority race. Save your vitriol for white people.
    8. Re:Bjarne should not be writing that by angel'o'sphere · · Score: 1

      No, it is not cleaner.
      Especially as all the catches you make are at the wrong place.
      You only have to do one catch at one place each.

      However my example was perhaps to simple, as putting it into a state machine makes sense, too.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    9. Re:Bjarne should not be writing that by goose-incarnated · · Score: 1

      No, it is not cleaner. Especially as all the catches you make are at the wrong place. You only have to do one catch at one place each.

      Okay, maybe you can rewrite that try/catch structure in a way that looks cleaner to you, and show me how? I put it the way that I did because I assumed that each response/exception would be handled differently (in actual ATMs every response is handled explicitly and there are very few, usually none at all, catchall for responses/exceptions).

      However my example was perhaps to simple, as putting it into a state machine makes sense, too.

      In my usual line of work, predictability and consistency is more important than execution speed or development time, hence usage of a state-machine is pretty popular as it allows a formal proof of the logic independent of the actual code review. Having all the logic paths laid out in a state-machine makes using formal proof a great deal easier.

      (Code reviews also get easier when no stack unwinding can ever be performed in the middle of a function and no composite datatype implicitly destroys itself and its fields... but that's a different argument :-))

      --
      I'm a minority race. Save your vitriol for white people.
    10. Re:Bjarne should not be writing that by angel'o'sphere · · Score: 1

      You catch exceptions only at a place where you can do something about them.

      E.g. when your ATM is idle and gets "activated" by inserting the Card, the only exception you need to catch and handle there is "CardUnreadableException" (or however we named it before).

      Same for the wrong code, only when codes are entered you have to handle that.

      Bottom line a single if that would handle a single error code, transforms into a single catch. The advantage is: the if has to come directly after the call (and its result is available) ... the catch can be elsewhere.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    11. Re:Bjarne should not be writing that by Carewolf · · Score: 2

      If your code isn't exception-safe, it's probably bad in several other ways. It's not that difficult to get it right, if you have a clue, and will avoid other problems. If you think industry best practice is C++ that isn't exception-safe, I don't want to work where you do.

      If you think it is easy, you are doing it wrong. It is as difficulty as coding thread-safe code without using mutexes and semaphores. Execution might be cut at any point in time and the state has to be consistent at that time. If you set a pointer to an array and then the length to it, you are not doing it thread-safe because an exception might come inbetween, which means something as simple as setting data needs to be controlled by state-classes that can rollback half completed state changes in case of an exception.

      The easiest way to get around it, is just to use functional programming style where you have little or no state, but that also implies reducing the multiparadigme langauge of C++ to just one paradigme

    12. Re:Bjarne should not be writing that by Carewolf · · Score: 1

      I don't realy get why people write this nonsense.

      You are at an ATM, you insert your card, the card can not be read: DamagedCardException.

      The card can be read and you are asked to enter the code, code is wrong: InvalidCodeException

      You enter the code three times wrong: CardSwallowedException

      You enter the code correctly and want to withdraw $1000, but the bank does not acknowledge: TransactionNotPossibleException.

      NONE of the above exceptions will terminate the ATM software but will return with a hopefully meaningful message to the main menu.

      (*Facepalm*)
      For the application it should be absolutely no difference if you handle errors with error codes or with exceptions. The user should not see any difference, the program should behave exactly the same.
      However: working with exceptions is 100 times easier for developers than working with error codes.
      If that is not true for you then for funk sake: you should definitely not be a programmer!!!!

      I don't think you should be a programmer. None of those cases are exceptions, they are errors, errors needs to be handled through normal code path. if you haven't figured out how to handle the potential errors you need to think your design over again, instead of throwing an exception in a half-done transaction and hoping it get magically unwrapped to something that isn't completely fucked.

    13. Re:Bjarne should not be writing that by angel'o'sphere · · Score: 1

      I don't think you should be a programmer.
      Same for you.
      None of those cases are exceptions, they are errors,
      Exceptions and errors are the same thing, only the way you handle them in your code is different. If the language supports exceptions, the preferred way is using Exceptions for errors.
      If your language does not support exceptions, the only way is using error codes.
      Bottom line: it is a programming idiom. No idea where you got the idea that exceptions and errors are something different. (And how would all the languages that don't support exceptions handle "exceptions" then?)

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    14. Re:Bjarne should not be writing that by david_thornley · · Score: 1

      That's one reason you don't use C-style arrays, but rather std::vector or other standard containers. Also, if you must use a C-style array, at least put it in a std::unique_ptr or std::shared_ptr so it gets cleaned up. That said, after the assignment to the pointer, what's going to throw?

      You do need to keep exception safety in mind, you need to avoid some pitfalls, and you need to know at least a few constructs that will not throw exceptions. Assignment of primitives will not throw, and you do need to keep your swap functions from throwing. After that, it isn't that difficult. (One tip: if you ever write "delete" outside a destructor, you are probably doing it wrong.)

      Things become hairier with threads, but they always do. If you get in the habit of watching what will have to be destructed, it's not that hard.

      I'm not saying it's trivial, but it's not that hard to get right.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  11. Instrumenting c++ to behave like Rust by Anonymous Coward · · Score: 0

    What I take from the talk is that ownership matters.
    I found Rust very interesting on its pragmatic solution to pointers. If c++ can borrow that and implement it, even better.

    1. Re:Instrumenting c++ to behave like Rust by Tailhook · · Score: 4, Informative

      I found Rust

      I've found it best not to talk about Rust around here. The language has already accumulated a legion of haters at Slashdot. Rational discussion about Rust sans the office punklets happens at Hacker News.

      It was anticipated that Rust would motivate some progress in C++ memory safety. Some have argued that if that is all that Rust accomplishes it is worthwhile. Too bad an entire language has to be invented to get some folks off the dime.

      The uptake of Rust is so large though I don't think it's going to go away just because C++ adopts some degree of compile time memory safety. The language is great on it's own merits, there is none of that half century of baggage to slog through and the entire stack and all native Rust third part modules provide the same memory safety guarantees, barring 'unsafe.'

      These things, combined with the never ending stream of opportunities the segfaults and overflows that C/C++ cannot avoid providing will ensure a chunk of mind-share, haters be damned.

      --
      Maw! Fire up the karma burner!
    2. Re:Instrumenting c++ to behave like Rust by Grant_Watson · · Score: 2

      Half century? Are you counting from Algol?

      That said, the cruftiness of C++ is one of the things that keeps me from bothering to properly learn it, however much I respect its newer developments. Another is that its place on the scale of abstraction isn't often a place that I need to go personally: C or Python usually makes more sense for me.

      Where on that scale would you say Rust lies? Is its target use software that lies on the boundry between systems software and applications, e.g., web servers?

    3. Re:Instrumenting c++ to behave like Rust by Anonymous Coward · · Score: 0

      So we gloss over the Cyber War Domain created by you and your fellow C and C++ advocates ?

      "because it is soooo fast" ?

      Quick way into hell ?

      And we "do C++ because we can hire sooo many developers who will quickly knock up one more vulnerable system" ?

      Yeah, more quickly built pestilence is what mankind needs. NOT.

    4. Re:Instrumenting c++ to behave like Rust by Pinky's+Brain · · Score: 3, Insightful

      Seasoned professionals have given us decades worth of mostly unnecessary buffer overflows.

  12. Cost of safety by fragMasterFlash · · Score: 2

    Its nice to see efforts to drive the complexity out of the design/implementation of safe code but this won't due much to improve the already error prone task of debugging optimized code. You don't always have the luxury of running a debug build, especially when analyzing a crash dump from a customer and templated/STL C++ constructs are often too complex for debuggers to parse properly. Hopefully these efforts reduce the number of crashes enough to justify the added complexity of debugging the crashes that still occur.

    1. Re:Cost of safety by Anonymous Coward · · Score: 0

      Send a debug version of the crashing module to the customer, although this sounds like a compiler problem ultimately.

    2. Re:Cost of safety by mrprogrammerman · · Score: 1

      There's better support for this scenario in the latest Visual Studio. Unfortunately it greatly increases the size of your pdbs.

  13. Re:Frist! by Blaskowicz · · Score: 1

    Safe but you have to pay a lot of attention to not make it accidentally unsafe, thus.. sort of safe?

  14. Ada had this in 1995 by david.emery · · Score: 3, Informative

    Ada95 added OO features including clear mechanisms (enforced by the compiler) on how to get OO design benefits without runtime performance costs or risks for dispatching.

    Much of what I've seen in C++ is a response to problems in the original language design, particularly gaps or errors of omission.

    Computer Science in the 21st Century seems to be full of stuff we knew about in the '80s and '90s, but forgot.

    1. Re:Ada had this in 1995 by Virtucon · · Score: 1

      Yo mama!

      --
      Harrison's Postulate - "For every action there is an equal and opposite criticism"
    2. Re:Ada had this in 1995 by david_thornley · · Score: 2

      What part of C++ OO imposes runtime performance costs? Virtual functions are one indirect access of a table that's likely to be in cache already. What are the risks in dispatching?

      Modern C++ is a successful attempt to make C++ into a much better language. You could call that a response to earlier problems, but it's not just a bunch of patches.

      Computer programming in the 21st Century seems to have problems with stuff we knew about in the 70s. Java's "finally"? Who thought that was a good idea?

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    3. Re:Ada had this in 1995 by UnknownSoldier · · Score: 2

      > What part of C++ OO imposes runtime performance costs?

      Uh, the fact that it is designed for the uncommon single case instead of the common multi case. You want to optimize for the throughput, not latency.

      OOP (Object Orientated Programming) has terrible performance scalability since it has terrible D$ (Data Cache) usage. For high performance OOP is completely ditched in favor of DOD (Data Orientated Design). DOD is used heavily in modern game development, and HFT (High Frequency Trading.)

      I would recommend starting here:

      * Pitfalls of Object Oriented Programming

      Even Bjarne Stroustrup was ignorant of D$ usage and how it effects performance:

      * Why you should avoid Linked Lists, where someone subtitled it: Stroustrup learns how L1 Cache usage is critical for performance sensitive code.

      I would also read Mike Acton's presentation:

      * Typical C++ Bullshit

    4. Re:Ada had this in 1995 by Anonymous Coward · · Score: 0

      Ada was a piece of shit. No one forgot that!

    5. Re:Ada had this in 1995 by Grant_Watson · · Score: 2

      C++ grew somewhat organically out of C. C is (IMHO) an excellent language, but its goals often differ from C++'s goals.

      I won't argue with your conclusion; it's true. But a lot of what was achieved in the research and design of the '80s and '90s was achieved by burning down the software stack and starting over. (Take Smalltalk for example.) People are rediscovering those things in a context where the existing stack matters and tackling the hard work of reconciling those developments with what we already have in a coherent way.

    6. Re:Ada had this in 1995 by david.emery · · Score: 4, Informative

      That "piece of shit" is in most modern commercial aircraft these days, as well as the ground ATC systems. Guess maybe you shouldn't fly, then, if that's your opinion, Mr Coward.

      There are legitimate criticisms that can be levied against any programming language, as well as against the Ada program. But this comment addresses none of them.

    7. Re:Ada had this in 1995 by phantomfive · · Score: 4, Interesting
      It reminds me of this quote:

      "It's quite apparent that the evolution of the C family of languages (C, C++, Java, C#) is converging on a language very like Ada, except unfortunately as a kludgepile rather than a clean design."

      --
      "First they came for the slanderers and i said nothing."
    8. Re:Ada had this in 1995 by david.emery · · Score: 2

      And that's what makes Ada95 (and subsequent versions) so interesting from a language design perspective. Ada95 built on the Ada83 language (which itself built on Pascal, as well as CLU and other research languages), adding OOP (including supporting concurrent objects in a way that I haven't seen in other "modern" programming languages in this era of multi-core processors). There are design trade-offs, and these are well-documented. If you're interested in such things, the published design team rationale documents (for both Ada83 and Ada95) should be required reading. Ada83: http://www.adahome.com/Resourc... Ada95: http://www.adahome.com/Resourc...

      What Ada95 accomplished was to graft a full OO design mechanism (i.e. inheritance) , while preserving type-safety (for scalar types, as well as "objects" or classes), keeping the safety properties (e.g. impossible without unchecked conversion to dereference a null pointer), and providing nearly 100% backwards-compatibility with Ada83. (There were a few inconsistencies, but these were at the edges of the language.)

      Oh, and Ada2005 adds support for pre-conditions and post-conditions that matches what Eiffel now provides for defining and enforcing contracts. And it does so while providing the SPARK subset that supports theorem-proving for proof-of-correctness (including concurrent programs), starting with "cannot generate runtime error". See https://en.wikipedia.org/wiki/... A lot of this grew out of David Luckham's work at Stanford on annotation languages such as ANNA and TSL, see http://www.springer.com/us/boo...

    9. Re:Ada had this in 1995 by phantomfive · · Score: 1

      Serious question......
      Game programmers often use C++ (for various reasons). Since you are a game programmer who doesn't like C++,
      What do you typically use to write programs?

      --
      "First they came for the slanderers and i said nothing."
    10. Re:Ada had this in 1995 by Anonymous Coward · · Score: 0

      I would also read Mike Acton's presentation:

      * Typical C++ Bullshit

      I have a hard time convincing myself to take best-practices advice from someone who thinks information is best conveyed by a slide presentation of photographs of hand-written notes on post-its stuck to a printout of code.

    11. Re:Ada had this in 1995 by UnknownSoldier · · Score: 2

      > Game programmers often use C++ (for various reasons).

      Performance is the #1 of reason, but yeah, C++ gets the right balance of power, compactness, performance, and multi-paradigm design which builds upon C's foundation.

      > What do you typically use to write programs?

      Just because I'm vocal, and passionate, doesn't mean I toss the baby out with the bath water.

      I would be stupid to ignore the wisdom of Bjarne Stroustrup:

      There are only two kinds of languages:

      * the ones people complain about and
      * the ones nobody uses.

      To answer your question:

      Pragmatic C++. (With some Javascript, since WebGL is my (current) day job)

      Which is the balance of the middle ground between basic C and the modern over-engineered clusterfuck of C++. Why do you think there was an "Embedded C++" movement years ago which removed all the Templates, Exception Handling, and RTTI junk? Gee, look, Ubisoft C++ usage does the exact same thing.

      To clarify, I use _only_ templates when it makes sense. Most of the time it doesn't. I use #define macro's where it makes sense. Most of the time it doesn't. I don't use Boost because it is over engineered 99% of the time. I uses classes where it makes sense. I use 3rd party libraries only when necessary. I use design patterns only when the model fits - instead of trying to shoehorn the code+data into a broken model.

      I've shipped enough games where a full build was 45+ minutes. This is insanity.

      Minimal C++ is the mantra. Use the expressive complexity and power of the language when it matters. Most of the time it doesn't.

      I just want the insanity of C++ to stop and address the common core issues instead of adding yet-another-flavor-of-the-month concept. Retarded ideas like 2D Graphics Rendering API proposal is the epitome of everything wrong with the committee. Completely out-of-touch with reality and solutions in search of a problem.

      When you _even_ have a C++ committee member admitting he writes in a sub-set of C++ himself you know the language has gotten too big. /Oblg. Murphy Computer Law: Inside every large programming language is a smaller one struggling to get out.

      *ALL* programming languages suck. Most suck even more.

      Want to know someone else who hates C++? Andrei Alexandrescu. *Every* C++ programmer should read until they grok Modern C++ Design: Generic Programming and Design Patterns Applied Guess where he works on now? D (All Things D (programming language) - A Conversation with Andrei Alexandrescu.)

      When you even have Scott Meyers at a D Conference (DConf 2014: The Last Thing D Needs (Scott Meyers), you know the language has potential. D has its own problems but I would keep my eye on it. :-)

      As bad as C++ is, for my needs it is better then the alternatives.

    12. Re:Ada had this in 1995 by Anonymous Coward · · Score: 0

      I guess he works for Redmond Propaganda the odd days, given the level of intelligence displayed.

    13. Re:Ada had this in 1995 by david_thornley · · Score: 1

      Having gotten through about half of that Pitfalls slide show by now, I'm not impressed. Much of the discussion is about the "is_dirty" flag which has as much to do with OO programming as my cat's last hairball. It's worth commenting on, sure, but mixing that with the alleged evils of OO programming makes the presentation hard to follow.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    14. Re:Ada had this in 1995 by phantomfive · · Score: 1

      That's a nice comment.

      --
      "First they came for the slanderers and i said nothing."
    15. Re:Ada had this in 1995 by UnknownSoldier · · Score: 1

      If you "Ignore the messenger because you don't like the message" you'll miss out on a lot of great wisdom. You'll find the following links to be a lot more palatable.

      Mike Acton reviewed Ogre 1.9's OrgreNode.cpp pointing out its horrible design and performance.

      As a result Orge 2.x game up with a gameplan -- they put together a PDF of how OOP screwed their performance over.

      Turns out, Mike Acton was right. They ended up with a 5x performance increase by ditching OOP and using DOD.

  15. Fox guarding the hen house by Anonymous Coward · · Score: 0

    Just say no.

    I mean, that's like asking your drug dealer how to smoke crack safely. Because he has the most experience. And must be a specialist in drug safety because he is still alive. Until he isn't.

    I mean, we are talking C++ here. The language where one solves the dining philosophers problem by turning the forks into generalized tables and then taking a dump on the plates.

  16. What instead of an exception? by tepples · · Score: 2

    Bjarne has never wanted to admit C++ exceptions were a mistake.

    What should a method that fails do instead of returning an exception? Should it instead be set up to explicitly return two different types of return value, namely the object that it's supposed to return if it exceeds or an object describing the failure if it fails?

    1. Re:What instead of an exception? by Anonymous Coward · · Score: 0

      It should crash hard to teach the developer a lesson.

    2. Re:What instead of an exception? by Yosho · · Score: 2

      I can't speak for the original poster, but as for myself, I think that conceptually exceptions are great, but the C++ implementation of them is full of holes and prone to abuse. As much as the Slashdot base loves to hate Java, I think Java got exceptions right.

      Notable differences:
      1) There's a distinction between checked (compile-time) and unchecked (runtime) exceptions. All C++ exceptions are unchecked.
      2) A method that can throw checked exceptions must declare every checked exception it can throw, and a method that calls another method that can throw checked exceptions must explicitly catch or re-throw them. These can be verified at compile time.
      3) Every object that can be thrown/caught must implement the Throwable interface, so it has a predictable interface and can be properly manipulated in an object-oriented manner.
      4) try/catch blocks also have a "finally" clause that is guaranteed to be run after the try/catch blocks complete, regardless of whether either one of them runs to completion or throws an exception out of the method. This is crucial for safely cleaning up filesystem/network resources -- the C++ alternative is only allocating objects on the stack and implementing destructors that clean up their resources, but then you have the restriction of not being able to allocate on the heap, and it may not also be obvious from looking at the try/catch block what the destructors are doing or in what order they'll be called in...

      I go back and forth between C++ and Java development a lot, and every time I go back to C++, I'm immediately reminded why C++ developers are so averse to using exceptions for error handling.

      --
      Karma: Terrifying (mostly affected by atrocities you've committed)
    3. Re:What instead of an exception? by Anonymous Coward · · Score: 0

      Exactly, check out Rust's Result.

    4. Re:What instead of an exception? by serviscope_minor · · Score: 1

      1) There's a distinction between checked (compile-time) and unchecked (runtime) exceptions. All C++ exceptions are unchecked.

      I agree with that. Exceptions are entirelt typed at runtime which is not very C++ish. I don't really feel all that happy about thar in C++.

      4) try/catch blocks also have a "finally" clause that is guaranteed to be run after the try/catch blocks complete, regardless of whether either one of them runs to completion or throws an exception out of the method. This is crucial for safely cleaning up filesystem/network resources -- the C++ alternative is only allocating objects on the stack and implementing destructors that clean up their resources, but then you have the restriction of not being able to allocate on the heap, and it may not also be obvious from looking at the try/catch block what the destructors are doing or in what order they'll be called in...

      I don't see how that's a downside in C++. RAII and destructors mean that in C++, the finally block is completely unecessary. In both C++ ang Java you've got to have a handle for a resource somewhere accessible and that ultimately means a reference has to be somewhere on the stack if you follow the chain all the way back. Otherwise in Java it will be GC'd. Since you've got to have a reference somewhere, I don't see the problem with having the reference clean up after itself.

      --
      SJW n. One who posts facts.
    5. Re:What instead of an exception? by 0123456 · · Score: 1

      And this is why it often seems that 90% of the Java code I read is catching exceptions and doing stuff with them. Normally throwing another exception.

    6. Re:What instead of an exception? by tepples · · Score: 3, Informative

      Every object that can be thrown/caught must implement the Throwable interface

      Then have all exceptions extend a subclass of std::exception . The guidelines mention use of a subclass as opposed to using the built-in exceptions directly.

      the C++ alternative is only allocating objects on the stack and implementing destructors that clean up their resources

      Also called Resource Acquisition Is Initialization (RAII), or "automatic resource destruction" if you don't want to remind readers of the record industry (RIAA).

      but then you have the restriction of not being able to allocate on the heap

      You can take advantage of automatic resource destruction if you wrap your object on the heap in a smart pointer type (std::unique_ptr or std::shared_ptr as appropriate) on the stack. If that isn't appropriate in a given situation, C++11 supports a scope guard idiom using std::shared_ptr and lambda expressions. The finally factory described in the Guidelines is ultimately an update of a method described in a 2000 article by Andrei Alexandrescu in Dr. Dobb's .

    7. Re:What instead of an exception? by Anonymous Coward · · Score: 0

      Many in the programming community have, after years of experience, come to the opposite conclusion regarding Java's checked exceptions. Checked exceptions, a feature that no other programming language has, are considered by them *failed experiment*.

      The reasons are many.

      Checked exceptions violate encapsulation in that any changes made to any software called by your code, if the code you are calling changes in what exceptions it throws, can result in you having to change your code to add/remove those exceptions in your method signature. This is of no benefit for the most part because what does code typically do? If an exception happens in the body of a method, it is caught in that method, program state is made as clean as it can be, and the exception is then thrown again so that the error can be caught by some outer loop at the highest level where the error message is logged. What exactly is gained by forcing a programmer to declare which TYPE of exception just occurred to the calling method? It's irrelevant. The exception TYPEs will be treated the same. Cleanup was done in the method where the exception happened, and the calling code logs the error.

      The calling code won't know how to handle a specific exception TYPE because how can it know what to do, other than log an error? It doesn't have any context information to do anything else.

      And then in Java you still have to handle UNCHECKED runtime exceptions. Those can happen anytime, anywhere, and they are never declared in the method signature. Programmers seem to handle unchecked exceptions just fine.

      So, what is gained by checked exceptions? Nothing. They aren't even useful for documentation, as they only show *at best* a subset of the exception types that can be thrown, i.e., the checked exceptions.

    8. Re:What instead of an exception? by Anonymous Coward · · Score: 0

      Yep, that's the safe C++ way to do it... You wanted bare metal, right?

    9. Re:What instead of an exception? by david_thornley · · Score: 1

      C++98 did have the "throw" function specification, and in general it was found to be more trouble than it was worth, with the possible exception of "throw()", which should be replaced by "noexcept" in modern C++.

      "finally" does not exist in C++, fortunately, since RAII is much better. There's no reason you can't allocate on the heap and have destructors clean everything up. That's what auto_ptr was for in C++98 and what shared_ptr and unique_ptr are for in C++11. If you need to worry about what the destructors are doing and what order they're called in, you're almost always doing it wrong. (There may be applications I am currently unfamiliar with where that matters, but that would be unfortunate.) A "finally" block has low cohesion and high coupling, whereas destructors have high cohesion and low coupling.

      As far as interfaces go, they're there if you want to use them. C++ allows a lot of things Java forbids, which means Java is better for mediocre programmers than C++ is.

      Smart pointers, to use RAII and the heap, are a very basic features of modern C++. If you don't understand them, you're not going to write good C++.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    10. Re: What instead of an exception? by slack_justyb · · Score: 1

      I too lament the way C++ does exceptions versus how Java handles then. That said, you bring a good point. I've seen new guys in the shop coming from a Java background struggling to completely wrap their heads around RAII. Finally in Java is the typical source for the struggle.

    11. Re:What instead of an exception? by Anonymous Coward · · Score: 0

      Exceptions are crap! Java is crap!

      Get with the program!

    12. Re:What instead of an exception? by Anonymous Coward · · Score: 0

      Because Java "programmers" really have no clue how their programlet will run. All the exception code is what might happen, but they're really not sure.

    13. Re:What instead of an exception? by firewrought · · Score: 1

      That's why checked exceptions are silly. Java assumed you want to handle exceptions close to where they happen (and bad programmers do, returning null values or zeros or whatever that cause further bugs and hide the origin of the real problem).

      No, 99% of the time, if method foo() calls method bar() and method bar() can't do its job properly, then method foo() also fails to do its job properly. Just cleanup/rollback if necessary and let that exception unwind the stack where a thread-level exception handler can log it and take appropriate compensating action (restarting a job loop, showing the user an error message, exiting the process, or whatever).

      C# gets it right, especially with adding using() blocks and letting you attach contextual data to the exception as you unwind. D takes it a step further and lets you add scope(exit) blocks. Rust, alas, eschews exceptions and will always be plagued by panic-prone code (you think real-world programmers are going to diligently inspect each Option/Result instead of unwrap()ing it?).

      Exceptions are powerful tool for writing concise, reliable code. Too bad C++ gave them a bad name.

      --
      -1, Too Many Layers Of Abstraction
    14. Re:What instead of an exception? by lgw · · Score: 1

      And this is why it often seems that 90% of the Java code I read is catching exceptions and doing stuff with them. Normally throwing another exception.

      Ahh, Pokemon code! Gotta catch em all!

      If you can actually find the program logic hiding in all the Java boilerplate, you're doing Java wrong: moar boilerplate!

      --
      Socialism: a lie told by totalitarians and believed by fools.
    15. Re: What instead of an exception? by Anonymous Coward · · Score: 0

      Haskell's "Either monad" is almost identical to checked exceptions

    16. Re:What instead of an exception? by spitzak · · Score: 1

      C++98 did have the "throw" function specification, and in general it was found to be more trouble than it was worth, with the possible exception of "throw()", which should be replaced by "noexcept" in modern C++.

      Apparently it was Visual C++ that made "throw()" do what "noexcept" now does: it means you can be certain that this code will not throw an exception. This caused it to be used a lot, but the actual C++ definition of what "throw()" did was not that at all and was quite useless.

      "finally" does not exist in C++, fortunately, since RAII is much better. There's no reason you can't allocate on the heap and have destructors clean everything up. That's what auto_ptr was for in C++98 and what shared_ptr and unique_ptr are for in C++11. If you need to worry about what the destructors are doing and what order they're called in, you're almost always doing it wrong. (There may be applications I am currently unfamiliar with where that matters, but that would be unfortunate.) A "finally" block has low cohesion and high coupling, whereas destructors have high cohesion and low coupling.

      You are correct that RAII can do everything "finally" does, but it does sometimes require the writing of very strange classes when some kind of finally statement would work better. But to actually work well the statement can't be at the end, it should be next to the definition. Something like this would work just like a local unique_ptr (not suggesting this but imagine a more one-off instance of something that needs destruction):

                char* ptr = new char[BUFSIZE];
                finally { delete[] ptr; }

    17. Re:What instead of an exception? by Anonymous Coward · · Score: 0

      Everything you listed is available in other languages, except for #2. The ONE thing I like about Java exceptions is "throws". THANK YOU for letting me know what the hell can go wrong with your method, so I can ensure that I cover all possible failure cases. Nothing like a program in use for 3 years crashing due to an uncaught exception nobody had hit until that point.

    18. Re:What instead of an exception? by angel'o'sphere · · Score: 1

      All C++ exceptions are unchecked.
      That is wrong.

      If a function signature contains the exceptions that are thrown, the exceptions are checked exceptions.

      If the function signature does not define thrown exceptions, the exceptions coming from it are unchecked, obviously.

      The difference between Java and C++ is: the Exception type already defines in Java if the exception is checked or not, while in C++ every function defines if it wants to throw checked or unchecked exceptions.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    19. Re:What instead of an exception? by Anonymous Coward · · Score: 0

      Java's strict checked exception enforcement is pretty useful, no doubt about that. When wondering why C++ exceptions aren't so strictly enforced, one thing comes to mind. Third party libraries.

      One of C and C++'s strengths is the ability to write system level code which interfaces with things like C and even raw assembly... which have no concept of exceptions. So let's say I have some C++ code, which calls some C code, and THAT code happens to rely on a C++ library, which also happens to throw an exception.

      How will the compiler of my code know this? All it knows is that my code has called some C code which has no throw specifications :-/. Unfortunately, this is probably one of the simpler exceptions. But it would be nice if there was a "enforce-c++-exceptions" flag in compilers to enable it when you think it can.

      Regarding some of your points:

      1 & 2. Good points, I generally agree, but with the above caveats in mind
      3. have your exceptions inherit from std::exception or one of its subclasses. Granted, this would be convention and not a language rule. But its already one that many do anyway.
      4. You can allocate on the heap just fine, just make sure you capture the heap objects in things which will cleanup when they go out of scope(unique_ptr, vector, shared_ptr, etc). To be specific, you can just write things like this:


      try {
              auto p = std::make_unique<MyClass>();
      /* some code which may throw */
      } catch(const std::exception &e) {;
      /* cleanup */
      }

  17. Sad, really by jandersen · · Score: 5, Insightful

    I think it is sad, looking around on the responses so far, to see, yet again, that the overwhelming response to this is to jeer at anything that is beyond people's comprehension. I guess what it boils down to is, that far too many who call themselves coders can't be bothered to sit down and work out a detailed plan before barging ahead. You get nothing but trouble from OOP if you think in terms of simple scripts, and that is particularly true of C++.

    1. Re:Sad, really by myrdos2 · · Score: 4, Insightful

      In short, I suggest that the programmer should continue to understand what he is doing, that his growing product remains firmly within his intellectual grip. It is my sad experience that this suggestion is repulsive to the average experienced programmer, who clearly derives a major part of his professional excitement from not quite understanding what he is doing. In this streamlined age, one of our most undernourished psychological needs is the craving for Black Magic and apparently the automatic computer can satisfy this need for the professional software engineer, who is secretly enthralled by the gigantic risks he takes in his daring irresponsibility. For his frustrations I have no remedy......

      -- Edsger W. Dijkstra

      I love this quote, and I say that as a C++ programmer. It falls in with my own philosophy, which is that the more complicated something is, the less likely people will get it right. And C++ is extremely complicated. It's not the OO design that necessarily trips people up, it's the sheer amount of minutiae you need to remember and the care you must take not to do something stupid.

    2. Re:Sad, really by david_thornley · · Score: 1

      My impression of earlier versions of C++ was that it was a great language to lay formal siege to a problem, but not nearly as good for less formal approaches. Modern C++ has improved the siege engines, and become a lot more mobile.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    3. Re:Sad, really by phantomfive · · Score: 2

      that far too many who call themselves coders can't be bothered to sit down and work out a detailed plan before barging ahead.

      That's a good description of the C++ design process, and why the "approved" way of using the language is completely different than the "approved" way of not long ago.

      How many ways are there to allocate memory in C++? I'm starting to lose count.

      --
      "First they came for the slanderers and i said nothing."
    4. Re:Sad, really by Anonymous Coward · · Score: 0

      Three: static, stack and heap.

    5. Re:Sad, really by phantomfive · · Score: 1

      No, I'm just talking about on the heap. I've got these, probably missing some:

      malloc (alloc, calloc, etc)
      new
      new[]
      new (nothrow)[]
      make_shared
      shared_ptr(new ....)
      allocate_shared
      std::allocator::allocate
      make_unique
      make_unique(new...)

      I am sure I'm missing some. I think most of those are deprecated.

      --
      "First they came for the slanderers and i said nothing."
    6. Re:Sad, really by msobkow · · Score: 1

      A programmer should never "know" what their code is going to look like. It needs to evolve from the initial design, correct oversights and misunderstandings, and organically become what it needs to be instead of what you first thought it would be.

      If you can analyze a problem so thoroughly that there is no room nor need for that evolution, you were dealing with a trivial problem in the first place and probably over-engineered your solution.

      --
      I do not fail; I succeed at finding out what does not work.
    7. Re:Sad, really by myrdos2 · · Score: 1

      A programmer should never "know" what their code is going to look like. It needs to evolve from the initial design, correct oversights and misunderstandings, and organically become what it needs to be instead of what you first thought it would be.

      I agree, more or less. I've completely moderately-sized projects that pretty closely followed my initial design, but other times I realize the design needs to be modified or scrapped completely when I'm halfway through. Dijkstra is just saying that your code should never reach a point where you can no longer fully understand what your're doing when you modify it. It's hard to argue with that.

    8. Re:Sad, really by serviscope_minor · · Score: 1

      How many ways are there to allocate memory in C++? I'm starting to lose count.

      Um... three? Stack, heap and static?

      Everything else is just wrappers around those.

      --
      SJW n. One who posts facts.
    9. Re:Sad, really by phantomfive · · Score: 1
      --
      "First they came for the slanderers and i said nothing."
    10. Re:Sad, really by angel'o'sphere · · Score: 1

      I believe you only forgot "placement new".
      Or if someone wants to nitpick, overwriting new for a class, but that comes down to finally use one of your proposals ;D

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    11. Re:Sad, really by phantomfive · · Score: 1

      And looking back, I messed up on some in that list, too.........make_unique(new...) should be unique_ptr(new...) and I don't think there's an "alloc," I was thinking alloca(), but that allocates on the stack not on the heap!

      --
      "First they came for the slanderers and i said nothing."
    12. Re:Sad, really by Anonymous Coward · · Score: 1

      If you're going to list those functions that just new a particular type of object and return the result as "separate ways to allocate memory", then you're missing quite a few:
      std::string
      std::list
      std::vector
      std::set
      std::map
      std::deque
      std::multimap
      std::multiset

      So confusing! Why isn't there only one way to allocate memory?

    13. Re:Sad, really by goose-incarnated · · Score: 1

      How many ways are there to allocate memory in C++? I'm starting to lose count.

      Um... three? Stack, heap and static?

      Everything else is just wrappers around those.

      C++ says nothing about stack and heap, only about lifetimes. As OP never asked about variable lifetimes and/or scope your answer is a great example of a non-sequitur.

      As far as C++ memory allocation goes, some of ways to allocate an arbitrary memory block/object, regardless of lifetime, is in this post here.

      --
      I'm a minority race. Save your vitriol for white people.
    14. Re:Sad, really by angel'o'sphere · · Score: 1

      I guess the question if there is an alloc depends on the underlying libraries. Usually you have alloc, malloc and calloc ...

      Yeah, the naming problems, can only imagine "alloca" comes from "alloc auto" indicating that the storage class auto is on the stack.

      The auto keyword got reused for something else again, didn't it? I'm not up to date with 11/14 standards.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    15. Re:Sad, really by serviscope_minor · · Score: 1

      Most of what you listed are just library factory functions.

      --
      SJW n. One who posts facts.
    16. Re:Sad, really by phantomfive · · Score: 1

      If 'new' is now deprecated, and using a factory smart-pointer function is the recommended way, the it's fair to list it.

      --
      "First they came for the slanderers and i said nothing."
    17. Re:Sad, really by phantomfive · · Score: 1

      Yeah, auto is what you use when it's really tough to figure out what kind of declaration should actually be used. Kind of like C# 'var'

      --
      "First they came for the slanderers and i said nothing."
    18. Re:Sad, really by angel'o'sphere · · Score: 1

      Ah, type interference, I remember now.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    19. Re:Sad, really by phantomfive · · Score: 1

      lol it's inference, but maybe interference is a better name for it lol

      --
      "First they came for the slanderers and i said nothing."
  18. core guidelines by Anonymous Coward · · Score: 0

    They have to make these core guidelines because C++ leaves open so many possibilities to use it incorrectly and create an abomination that kills people.

    David Emery, who posted above me, got it right. There are SO many better designed languages than C++. Ada is one of them, yes.Hell, even ding dang old Delphi is a better language than C++. And if you don't trust an automated software system to allocate and free memory for you, then what automated computer system DO you trust?

    I've said it once, I'll say it 1000 times: C++ is the product of troubled minds.

    1. Re:core guidelines by Anonymous Coward · · Score: 0

      >And if you don't trust an automated software system to allocate and free memory for you, then what automated computer system DO you trust?

      It's not that I don't trust the system to allocate memory for me, it's that I don't trust the system to allocate memory in a way that will result in my code meeting its performance targets.

  19. As always, guidelines are for beginners by PhrostyMcByte · · Score: 1

    Just like "don't use goto", or "don't use threads", etc., these guidelines and recommendations are really great to prevent beginners from making hard to spot errors, but all those variations and features exist for a reason and have a use.

    1. Re:As always, guidelines are for beginners by 140Mandak262Jamuna · · Score: 4, Insightful

      Just like "don't use goto", or "don't use threads", etc., these guidelines and recommendations are really great to prevent beginners from making hard to spot errors, but all those variations and features exist for a reason and have a use.

      Nobody uses GOTO anymore. With event driven programming and call back functions, it all spaghetti code strewn with COME FROM statements, effectively.

      --
      sed -e 's/Chuck Norris/Rajnikant/g' joke > fact
    2. Re:As always, guidelines are for beginners by Anonymous Coward · · Score: 0

      A lot of them exist for bad reasons and should not be used.

    3. Re:As always, guidelines are for beginners by Anonymous Coward · · Score: 0

      GoTo != 'dangerous' if you have 1 exit point for all uses of it (along with no "going backwards" which creates the "spaghetti code" phenomenon).

    4. Re:As always, guidelines are for beginners by Anonymous Coward · · Score: 0

      What is wrong with threads? I find it much easier to understand what is going on with my code using threads than I do with event loops (which I think is the modern suggestion).

    5. Re:As always, guidelines are for beginners by Bengie · · Score: 2

      I've ran into situations where not using GOTO resulted in much messier code that was harder to read. This rarely happens, but it does happen, and I always take a step back and try to find a better way than using GOTO.

    6. Re:As always, guidelines are for beginners by Anonymous Coward · · Score: 0

      All the cool kids are using actors

    7. Re:As always, guidelines are for beginners by GuB-42 · · Score: 0

      The "don't use goto" should be a "don't use goto that jump backwards or inside a block". I've seen a lot of stupid code that stem from that gotoless ideal. Forward gotos are actually pretty clear, probably more than breaks, continues, and returns that are not on the last line.
      If exceptions are not used, a "no goto" guideline would be counter-productive.

      As for threads, I don't know any beginner that would use them unless there is a good reason as they tend to make everything harder. However some guidelines abut what to do with shared resources like "always protect them with mutexes" are good ones, even if lockless programming is possible, you'd better not leave this to beginners.

    8. Re:As always, guidelines are for beginners by Anonymous Coward · · Score: 0

      If that refers to the stuff like in: https://en.wikipedia.org/wiki/Actor_model then that strikes me as a worse alternative to all of the above. I see no benefit of that compared to the alternatives I know of (threads, processes, event loops, executor pools). Maybe this is just my short-sightedness or there is some nuance I am missing. Plus, it seems like it would depend on the above anyway.

    9. Re:As always, guidelines are for beginners by Darinbob · · Score: 3, Informative

      I use goto. Sometimes. When you're in C then it's can be effective way to do a function clean up before exiting. Sure this can be over done but trying to avoid a goto like a religious taboo can also result in some pretty nasty code to replace it.

    10. Re:As always, guidelines are for beginners by Darinbob · · Score: 1

      Should not be used, or must not be used?

      And which of them are you referring to and what are the bad reasons? Because one day someone noticed the proliferation of spaghetti code and wrote a paper to encourage use of structured programming does not mean he intended to have a fundamental prohibition against one construct.

      But then, programming seems to be all about superstition. It had superstition in the 60s and it still has superstition today. Someone learns a rough rule of thumb as a student and keeps sticking to that for their entire career without thinking about why that rule of thumb was created. Someone had a bad day with threads and declares jihad against them for all time. The adherents of CamelCase struggle for dominance against snake_case believers. One exit from a function shall rule them all. Eat eggs from the little end and not the big end. It all boils down to letting others do the thinking for you.

    11. Re:As always, guidelines are for beginners by w_dragon · · Score: 2

      For C that's a perfectly reasonable use of goto. For C++ you should use unique_ptr or wrap your resource in your own object that you can stack allocate. RAII is a very nice pattern in C++.

    12. Re:As always, guidelines are for beginners by angel'o'sphere · · Score: 2

      RAII is not a "pattern" it is an "idiom".

      A pattern is independent from programming languages, idioms are thins you only can do in one/some language.

      e.g. using pointers and ++ to copy a \0 terminated string like this:

            strcpy(char* dest, char* src) {
                  while (*dest++ = *src++)
                          ;
            }

      is an idiom ... supported by certain languages, not a pattern.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    13. Re:As always, guidelines are for beginners by Darinbob · · Score: 1

      Yes, C++ has nicer ways to manage this, and I've used them.

    14. Re:As always, guidelines are for beginners by Darinbob · · Score: 3, Insightful

      I hate patterns. They're too much like verses from a religious text, because I've run across people who seem unable to understand your code unless it uses patterns from the official pattern Bible. Holding a conversation with them can involve being interrupted every few minutes with "oh, that's a FurblingFunctorFactory, why didn't you say so?" If you don't keep a close watch they'll go and changing existing/working code to rename classes to indicate what pattern they are.

    15. Re:As always, guidelines are for beginners by goose-incarnated · · Score: 2

      For C that's a perfectly reasonable use of goto. For C++ you should use unique_ptr or wrap your resource in your own object that you can stack allocate. RAII is a very nice pattern in C++.

      So unique_ptr will close open file handles and network connections?

      --
      I'm a minority race. Save your vitriol for white people.
    16. Re:As always, guidelines are for beginners by angel'o'sphere · · Score: 1

      Well, for most patterns it makes no sense to have the role names in the class names. Builders and Factories might be exceptions.

      The problem is simply that many developers are uncomfortable outside of their own niche. If they have not written the code or are somehow close to it, they have trouble understanding it.

      On the other hand that can easy be turned around: most programmers are not able to write code that is easy to understand by other programmers.

      I for my part used to document what patterns are used/which roles a class played when I still did C++ ... books about patterns where pretty new that time, luckily I already new most of them, just had no names for them.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    17. Re:As always, guidelines are for beginners by Anonymous Coward · · Score: 0

      For C that's a perfectly reasonable use of goto. For C++ you should use unique_ptr or wrap your resource in your own object that you can stack allocate. RAII is a very nice pattern in C++.

      So unique_ptr will close open file handles and network connections?

      Bolded the part you apparently missed.

    18. Re:As always, guidelines are for beginners by Garfong · · Score: 1

      I think the classic one is error handling in C. Usually each error case has some standard unlock all the locks; free temporary objects; close files, etc. Instead of copying & pasting for every error, put it at the end of the function and do if (error) { goto error_handler; }.

      Dosn't apply to C++ though since you can use exception handling. I think modern compilers will even convert the exception into a goto in many cases.

    19. Re:As always, guidelines are for beginners by Anonymous Coward · · Score: 0

      In a "proper" c++ codebase, yes absolutely it will. I know that your sarcasm is directed at places where C++ meets C APIs, but a good C++ codebase would have a wrapper for things that are allocated in a C-ish way so some file_object will close the file handle in the destructor and the unique_ptr will hold a file_object not a handle/pointer to a file. Same goes for network connections.

    20. Re:As always, guidelines are for beginners by Anonymous Coward · · Score: 0

      Ironically, one of the reasons for coming up with the patterns was communication.. ;)

    21. Re:As always, guidelines are for beginners by w_dragon · · Score: 1

      Yes, it takes a deleter function as an optional parameter, so it can be used for pretty much any resource.

    22. Re:As always, guidelines are for beginners by Anonymous Coward · · Score: 0

      I pretty much do this, but if you're writing script-like code using goto to finish a scope quickly really is acceptable.

    23. Re:As always, guidelines are for beginners by paugq · · Score: 1

      Nobody uses GOTO anymore. With event driven programming and call back functions, it all spaghetti code strewn with COME FROM statements, effectively.

      You have never read the Linux kernel source code, systemd, Samba, etc, have you? They use goto extensively and it results in easy to understand code.

  20. The liberator and the wise crack. by 140Mandak262Jamuna · · Score: 1

    "Within C++ is a smaller, simpler, safer language struggling to get out." -- Bjarne Stroustrup

    Very true, C++ would struggle no matter how laudable the goal is.

    --
    sed -e 's/Chuck Norris/Rajnikant/g' joke > fact
  21. That's obvious by Anonymous Coward · · Score: 0

    It should print "Error: The operation completed successfully."

    1. Re:That's obvious by Anonymous Coward · · Score: 0

      Or "Error: Something happened."

    2. Re:That's obvious by Opportunist · · Score: 1

      Or the ever popular MessageBox with ERROR! in the caption, no text and the choice between the two buttons "yes" and "no".

      Just to keep the user sweating whether he could possibly save his last 2 hours of work just by hitting the right button.

      --
      We used to have a Bill of Rights. Now, with the rights gone, all we have left is the bill.
  22. Ditch C++ by Anonymous Coward · · Score: 0

    There are languages that have learned from the mistakes of past languages and have the freedom tp do things better.

    Myself, I am currently being impressed by the efforts of the golang community. They have thought of most things that annoy me as a C/C++ programmer -- a very low overhead GC (sub-ms in v1.5), built in vet (a lint-likr tool with race-condition detection), coverage analysis, unit testing, and an official git-based package import tool. And messaging in preference to passing pointers around in unsafe ways.

    And a language spec that isn't 2,000 pages long.

    1. Re:Ditch C++ by david_thornley · · Score: 1

      The core language spec isn't much over 400 pages, and the library adds something less than a thousand additional pages. Ever since around 2000, when O'Reilly published "Java in a Nutshell" in four volumes, I've stopped listening to complaints about excessive library size.

      There are unit testing frameworks for C++. Unfortunately, C was not straightforward to parse, and so C++ isn't either, so that hinders the development of additional tools. I expect Clang to improve that eventually, but it's a language problem that can't be fixed.

      There are safe ways to pass pointers around, and there's a lot of work going on on how to do it. It reminds me of people discovering exception safety after the first C++ Standard came out.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    2. Re:Ditch C++ by Anonymous Coward · · Score: 0

      The core language spec isn't much over 400 pages, and the library adds something less than a thousand additional pages.

      Oh yeah, that put a load of my mind. So if a deadtree version of it falls from a bookcase, it won't kill me, but my dog still has to watch out.

    3. Re:Ditch C++ by david_thornley · · Score: 1

      The dead tree versions are expensive. The PDFs are far cheaper, and less dangerous.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    4. Re:Ditch C++ by sribe · · Score: 1

      Myself, I am currently being impressed by the efforts of the golang community.

      No generics? Not only not a set collection in the standard library, but no reasonable way to define one?

      Go is a nice, tidy, compact little language. But...

  23. Should file not found always be a fatal error? by tepples · · Score: 1

    You claim that all exceptions should be fatal. I hope this was sarcasm. If not, then for example, if a program lacks a configuration file because it is being started for the first time, what lesson ought to be taught, to whom, and why?

    1. Re:Should file not found always be a fatal error? by Seq · · Score: 3, Insightful

      You just need to catch the crash. Though it would be helpful if we could pass along some additional information about the crash..

      Oh. Hmmm..

      --
      -- Seq
    2. Re:Should file not found always be a fatal error? by Anonymous Coward · · Score: 0

      A lot of the programs I have used create a configuration file when being started without one.

    3. Re:Should file not found always be a fatal error? by Anonymous Coward · · Score: 0

      if a program lacks a configuration file because it is being started for the first time

      That isn't an exception. That's a given. Exceptions were devised to handle exceptional events, not to handle your main flow of control.

      Seriously. Learn how to use exceptions instead of wasting your time bitching about something you don't know.

    4. Re:Should file not found always be a fatal error? by tepples · · Score: 1

      In order to create the configuration file when the program is run for the first time, the program must first attempt and fail to read the existing configuration file.

    5. Re:Should file not found always be a fatal error? by Anonymous Coward · · Score: 0

      How about checking if the file exists before reading it?

    6. Re:Should file not found always be a fatal error? by mrchaotica · · Score: 1

      The lesson that should be taught to the programmer is that the lack of a configuration file is a totally normal and expected condition which should be handled by the program's normal control flow.

      --

      "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

    7. Re:Should file not found always be a fatal error? by narcc · · Score: 1

      Somehow, we managed to handle errors decades before exceptions. Through arcane magic, we handle errors today in languages without exceptions.

      There are exceptional ways to handle errors that work exceptionally well, exceptions excepted, naturally.

    8. Re:Should file not found always be a fatal error? by tepples · · Score: 1

      Is the distinction between normal failures and exceptional failures true of all languages with exceptions or only of C++? If of all languages, then how should, say, a program in Python detect this "totally normal and expected condition" without catching an exception?

    9. Re:Should file not found always be a fatal error? by tepples · · Score: 1

      Somehow, we managed to handle errors decades before exceptions.

      Decades before exceptions, there wasn't nearly as much multitasking as there is nowadays. Fans of exceptions might claim that exceptions help thwart time of check to time of use (TOCTTOU) attacks.

    10. Re:Should file not found always be a fatal error? by mrchaotica · · Score: 2

      You're trying to make me declare some sort of hard-and-fast rule to something that's really an issue of style, which I won't do. But here's a heuristic: if you expect to succeed in opening the file, you could probably go ahead and use the 'pythonic' 'ask forgiveness, not permission' pattern. But if you're trying to (for some reason) open only one of 50 files and expect the other 49 not to exist, then your loop should probably look more like

      for name in filenames:
      ....if isfile(name):
      ........f = open(name)

      instead of

      for name in filenames:
      ....try:
      ........f = open(name)
      ....except IOError:
      ........#do nothing

      Also, exceptions should be used much more sparingly in C++ than in Python because they don't work as well in the former.

      --

      "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

    11. Re:Should file not found always be a fatal error? by david_thornley · · Score: 2

      Having been handling errors for a long time before I ran into exceptions, I don't agree that having to constantly check some sort of error flag is better than using exceptions.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    12. Re:Should file not found always be a fatal error? by narcc · · Score: 2

      Exceptions are one approach. The mistake is in thinking that one approach supersedes all others.

      It has more than its share of problems, which need to be acknowledged if we're to move beyond them.

    13. Re:Should file not found always be a fatal error? by angel'o'sphere · · Score: 1

      The lack of a configuration file is absolutely not normal.
      For a desktop app it might be possible to recover and be of some use for the user.
      A server application whee a configuration file is missing is by default dysfunctional, and hence should terminate with a useful error message.
      It makes no sense that hundreds or thousands of users are able to connect to the server application and lose their work because a vital item is not configured properly.

      All this has nothing to do with exceptions ... but they help as they usually propagate upwards and lead to thread or program termination, even if they are not properly handled.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    14. Re:Should file not found always be a fatal error? by david_thornley · · Score: 1

      There are many ways to handle errors, and I'm not giving up exceptions unless and until somebody can show me they've got something better.

      For events that may routinely happen, it's reasonable to write specific error-handling code. For events that almost never happen, exceptions beat checking error codes all over the place.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  24. It's pointers all the way down, jake ! by vikingpower · · Score: 1

    More than half of Stroustrup's talk was concerned with pointers. In 2015, we still need the kind of effort Stroustrup is calling for, simply because a fairly advanced OO language STILL uses pointers, with the risk of dangling ones, of pointers outliving the thing they point to, etc. etc. ? I dunno, people... but this is one of the main reasons I never made the switch to C++.

    --
    Religous speak to God. Insane are spoken to by God. When all shut up, one can finally hear Shostakovich in peace
    1. Re:It's pointers all the way down, jake ! by Anonymous Coward · · Score: 0

      The problem you name is solved in modern languages. They use Garbage Collection to take care of that for the programmer. (Well, you have the additional complication in edge cases of having to make something a Weak Reference instead of the usual reference, but it is a very, very seldom encountered thing, used more for implementing object caches.)

      Garbage Collection has its well-known performance and RAM overheads... and this just doesn't fit in with the C++ design philosophy at all.

      So it remains something of a problem for C++ programmers to handle themselves, although smart pointers have gone a long way towards easing the burden.

    2. Re:It's pointers all the way down, jake ! by The+Evil+Atheist · · Score: 2

      Unless you're dealing with hardware directly, you don't need pointers at all.

      --
      Those who do not learn from commit history are doomed to regress it.
    3. Re:It's pointers all the way down, jake ! by david_thornley · · Score: 2

      The other thing about GC is that it solves the resource deallocation problem for memory only. It doesn't support deallocating other resources which may be more important to deallocate promptly. (People are working on C and C++ garbage collection, and there have been attempts, but none have gained much popularity. Whether this is because nobody has worked hard enough, or because it doesn't offer a solution that much better than smart pointers, or that C and C++ just won't work well with GC is an interesting question.)

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    4. Re:It's pointers all the way down, jake ! by firewrought · · Score: 1

      The other thing about GC is that it solves the resource deallocation problem for memory only.

      That's like saying that the "walking on land" (instead of swimming 10 meters below the surface with SCUBA equipment) solves the resource problem for air only... not food or heat or shelter. Hey buddy... air is your most constant, immediate resource; you need it to do the smallest of things. Solving the air problem by walking on land frees up lots mental energy to focus on those other problems.

      If you really need the speed or fine-grained memory control, then sure, use C++. But it's illogical to reject GC for solving "only" 95% of resource/corruption/security problems. Every programming effort--from building a new language to coding a DBMS to designing a website to creating a line-of-business desktop application--is ultimately an attempt to reduce complexity for someone [except maybe game programming, where you're artificially creating complexity for the user!]. GC is one of the biggest wins in the history of computer science, almost up there with concepts like subroutines and version control.

      --
      -1, Too Many Layers Of Abstraction
    5. Re:It's pointers all the way down, jake ! by david_thornley · · Score: 1

      I'm not knocking garbage collection, believe me. I've happily used languages with it. I'm not pointing out how good it is because I think that obvious. However, it isn't uniformly better than C++ resource management.

      GC solves what is almost always the biggest resource management problem in a very simple way, but isn't extendable. C++ and RAII solve a more general problem in a clumsier way. I'd like to see a good combination of these, but I haven't yet. Another advantage of the C++ way is that it can avoid the "finally" block that makes it harder to write clean Java code and know it correct.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    6. Re:It's pointers all the way down, jake ! by vikingpower · · Score: 1

      I know all this. Funny that there seems to be hardly any golden/middle road between the hardcore use of pointers and having full-fledged garbage collection. There was an effort, around the time Java took off - 1996-ish - to bring Ada 95 and Java closer together: http://www.adahome.com/Tutorials/Lovelace/hello.ada  .

      Nothing really came from it, AFAIK. Alas, alas...

      --
      Religous speak to God. Insane are spoken to by God. When all shut up, one can finally hear Shostakovich in peace
    7. Re:It's pointers all the way down, jake ! by Xtifr · · Score: 1

      Tell that to all the C libraries I link to from C++ programs.

      Until someone is motivated to create C++ wrappers for every C library I might possibly want to use, I don't see any way to get away from some use of pointers. And so, until that mythical day, I think having some guidelines for pointer use in C++ is a good thing. Especially if the first one is:don't use raw pointers if there's any reasonable alternative. :)

      (Of course, I could limit myself to languages where you cannot use a C library until someone creates a wrapper for it, but that seems unnecessarily restrictive.)

    8. Re:It's pointers all the way down, jake ! by matfud · · Score: 1

      Java 1.7 has try -with-resources which can auto close any declared AutoCloseable object on any exit from the try block. No need for finally or catch clauses.

      Sort of RAII for non anything you want.

    9. Re:It's pointers all the way down, jake ! by david_thornley · · Score: 1

      Really? Java uses pointers all over the place. If it isn't an elementary data type, it's a pointer.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    10. Re:It's pointers all the way down, jake ! by david_thornley · · Score: 1

      Thank you. I don't keep up with Java, since I don't use it. (This is why I like to rant about features rather than languages. My ranting about finally is still applicable, but as you point out if I made it a rant about Java it would be obsolete by now.)

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    11. Re:It's pointers all the way down, jake ! by vikingpower · · Score: 1

      You're wrong. Java uses references, not pointers. And Java references are garbage collected, as pointed out by more than one poster in this thread. Quite the difference.

      --
      Religous speak to God. Insane are spoken to by God. When all shut up, one can finally hear Shostakovich in peace
    12. Re:It's pointers all the way down, jake ! by The+Evil+Atheist · · Score: 1

      In the context of C++, how does bringing Java into it relevant at all? Any idiot could tell I wasn't talking about all languages in general - but that I was talking about modern usage of C++.

      --
      Those who do not learn from commit history are doomed to regress it.
    13. Re:It's pointers all the way down, jake ! by The+Evil+Atheist · · Score: 1

      In Java, references are pointers. Just because you call them something different doesn't mean they aren't the same. Hell, you can get a "reference" to null in Java. The only difference is that you can't do pointer arithmetic.

      Garbage collection has nothing to do with whether something is a reference or a pointer. C++ has garbage collection in the form of scope based destruction of non-pointer owned objects.

      --
      Those who do not learn from commit history are doomed to regress it.
    14. Re:It's pointers all the way down, jake ! by matfud · · Score: 1

      No problem.

      Catch and finally for resources have been the bane of Java devs forever. Test for null, attempt to close, have to wrap the close call in an exception. It is not to bad when you have one non memory resource (file, network, sql, etc.) but two or more and it became a mess of nested exception handling and complex finally constructs to try to ensure everything was closed and released.

    15. Re:It's pointers all the way down, jake ! by matfud · · Score: 1

      So back to your point about a good combination of memory GC and RAII (memory is well handled by GC, other resources are not handled at all except as a side effect of freeing memory). Java is one language, I am familiar with, that is attempting to give you some features of both without the all out "hang yourself whilst shooting yourself in the foot when jumping out of a plane with a faulty parachute" approach of C++. (It is possible you will miss your foot, hit the rope which will get tangled in the faulty parachute and cause you to land safely with only minor broken bones. It will be fast though ;P

      I'm still out on if they are good. I would say better than before.

    16. Re:It's pointers all the way down, jake ! by david_thornley · · Score: 1

      I was using Java as an example. In C++, I haven't seen a program of significant complexity without explicit use of pointers (raw or smart). They're useful for shared sections of memory, and are valuable in function definitions since they have a specific invalid value. Moreover, they are how dynamic memory allocation works. It seems to me that writing programs without pointers would be limiting.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  25. char *strstrup(char *) by Anonymous Coward · · Score: 0

    For the longest time I thought that people were talking about a C string function when they mentioned his name.

  26. Re: And Yogi Says Dejavu all over again! by Anonymous Coward · · Score: 0

    He really didn't say all the things he said.

    Earlier today he confirmed that he really did say all those things.

  27. Re:Frist! by BlackHawk-666 · · Score: 1

    Safe as houses, safe as fuck!

    --
    All those moments will be lost in time, like tears in rain.
  28. Checked exceptions as API by John+Bayko · · Score: 1

    Checked exceptions are probably better viewed as part of a the API, in the sense that if exceptions didn't exist, these would be implemented as return parameters, which you would also have to declare and either check, or pass to the calling code.

    Maybe all exceptions should have been checked, but the difference (not always followed) is that checked exceptions are supposed to be for things the deployed program or user has some control over (missing file, sleep interrupted - that is, things you should plausibly expect to happen), and unchecked exceptions are for bugs or uncontrollable things (NULL, out of memory - bugs you should have fixed, or can't expect). In other words, handling checked exceptions should be as natural as checking to see if fopen returned NULL in C.

    Not done as consistently as it should have been in Java though. Made them confusing, inconsistent, and irritating to a lot of people who just decided checked exceptions were wrong rather than misimplemented (similar: operator overload abuse makes many people dislike the entire idea).

  29. Re:Frist! by Opportunist · · Score: 1

    It will give you code so secure that it can even order some fruity cocktails with those little umbrellas!

    --
    We used to have a Bill of Rights. Now, with the rights gone, all we have left is the bill.
  30. Exceptions are TOCTTOU safe by tepples · · Score: 1

    if a program lacks a configuration file because it is being started for the first time

    That isn't an exception. That's a given.

    Based on a cursory Google search, "given" appears not to be a term of art in programming. What is the C++ idiom to handle givens? I know Python's idiom is Easier to Ask Forgiveness than Permission (EAFP), which uses exceptions liberally because they're less likely to be vulnerable to time of check to time of use (TOCTTOU) attacks on a multitasking system than the alternative Look Before You Leap (LBYL) paradigm.

    Exceptions were devised to handle exceptional events, not to handle your main flow of control.

    "Use the settings in the configuration file except when the configuration file does not exist." How is that not "exceptional"?

    1. Re:Exceptions are TOCTTOU safe by Anonymous Coward · · Score: 0

      "Use the settings in the configuration file except when the configuration file does not exist." How is that not "exceptional"?

      Again, that just shows plain ignorance of the subject.

      You know with absolute certainty that the config file doesn't exist until your program creates it.

      Additionally, the file that certainly won't exist at a point may also be deleted at some point for some reason.

      The use case where your program needs to recreate the file isn't an exception. It's a clear integral part of your basic flow of control.

      Nothing ensures that the config file exists, and your program is responsible for creating it.

      This means without any doubt that your main flow of control needs to account for the scenario where the file doesn't exist.

      If you're using exceptions to handle your main flow of control then you're simply incompetent.

      Exceptions are there to help programmers handle exceptional events without cluttering the code. Exceptional events are stuff such as running out of memory, stumbling on memory corruption errors, failing a sanity check, etc etc etc. Exceptions let the programmer handle these events in a controlled manner outside of the main flow of control, such as logging the error, cleaning up memory, abort pending operations, warn the user, and either exit the program or return to a stable point.

      Not finding a config file that you need to create yourself doesn't fit this description. By far.

      This is exactly the main problem with exceptions: opinionated people who are completely clueless and blatantly incompetent expressing an opinion on what they simply never understood.

  31. Re:Frist! by slickwillie · · Score: 1

    If you had written it in C++ instead of BASIC it wouldn't be offtopic.

  32. Next step: by mobby_6kl · · Score: 1

    "Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo" becomes legal C++.

    1. Re:Next step: by vux984 · · Score: 1

      #define buffalo x++;
      #define Buffalo x--;

      {

      int x=0;

      Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo

      printf(x);
      }

      That'll pass muster even in K&R C :p

  33. Bleh C++ by Anonymous Coward · · Score: 0

    A lot of the information present was "already solved" by not using C++ in the first place, but telling shops to "only use ISO C99/C11" is kinda difficult when none of the available compilers support the complete thing. C++11/14 are considered "not backwards compatible" with earlier versions of C/C++ since some things are changed. However compiler support is much better.

    On Windows, only C/C++ should ever be used. On MacOS X/iOS only OBJC should be "used" for new projects, but C and C++ can be used if you don't want to use OBJC. On Linux... ugh where do I begin. Linux and FreeBSD projects should only be coded in C if at all possible. I see a lot of "bad" projects that run out the door as C++, but they're little more than frameworks layered over more frameworks, and many of the frameworks add nothing but overhead. It's like some people enjoy massive code bloat because they desperately need their own vanity wrappers every time a new programmer is added to the project because they don't understand another C++ programmers coding style. This damages open source projects right off the bat.

    If you're not comfortable with C++, and you're not willing to write something in C, then don't try to use C++ in the first place. Maybe the project doesn't really need C/C++. Maybe it can be written with Python or or just Lua with C/C++ bindings to an existing library. But once you make this compromise, you also reduce the portability, because NO OS comes with a requirement to support any scripting language (save for Javascript if a GUI+Web Browser is installed.) Linux and FreeBSD used to come with Perl, sometimes Python, sometimes other things, but because of security concerns and maturity of build tools, these have largely disappeared.

    Like given the current state of things, I'd rather see people use a subset of C# (eg Unity), Javascript or Swift on a portable runtime if the project isn't meant to be heavily optimized at the runtime level. Once there is a Swift runtime for Windows and Linux, I'm sure people will wholesale abandon flash (which was the only semi-portable runtime, but is absolutely awful at security because most flash developers are not programmers, but visual artists, and thus the there's a lot of security issues as a result of wanting the flash authoring tool to be easy to use.)

    1. Re:Bleh C++ by david_thornley · · Score: 1

      Except in weird circumstances, valid C++98 code will work in C++14, or it will fail to compile and it'll be obvious what needs to be changed. I've never had any problems upgrading C++ versions.

      There is no C/C++ language. There are two languages, C and C++. Both are useful, but the common subset is suboptimal C and really bad C++. Know which language you're working in. Consider other languages for projects that don't play to the strengths of C++ (for example, Javascript will work much better embedded in web pages than C++).

      There are good C++ compilers for Linux and BSD. There's no reason to restrict yourself to C, unless you're working on a particular project with particular requirements. (Don't try to submit Linux kernel patches in C++, for example.) Both g++ and clang are much better at standards conformance than Visual C++.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    2. Re:Bleh C++ by Anonymous Coward · · Score: 0

      Nothing stops browsers embedding a C++ engine inside their browsers...

  34. Allowing inconsistent objects to exist by tepples · · Score: 1

    Nothing ensures that the config file exists, and your program is responsible for creating it.

    You appear to state that the std::ios::fail() paradigm of C++, which allows an inconsistent stream object to continue to exist, is superior to the exception-on-failure paradigm of Python. Do I understand you correctly?

  35. Re:Uh oh by Anonymous Coward · · Score: 0

    So good you Big Boys have created the Cyber War Domain with your Great Work(TM).

    How would Lockheed Martin and Raytheon "grow" without your Great Work. How would they "advance" mankind without given the opportunity for Cyber WAR ?

    Seriously, can somebody think about the Uniformed Shit-doing Professionals ? I mean, these folks want a career too. They have kids to feed. They have an ego to polish.

    Let's don't deprive these folks by using memory safe languages ! Think about the MIC and all their hungry mouthes !

    Also, Pascal was created a swiss man. Switzerland is way too less belligerent to be accepted as a civilized nation. Using Pascal is un-patriotic, therefore.

    WAR - OUR GOD. HAIL WAR !

  36. You just created a TOCTTOU race bug by tepples · · Score: 2

    for name in filenames:
        if isfile(name):
            f = open(name)

    Congratulations: You just created a time of check to time of use (TOCTTOU) race bug. Consider what happens if another process deletes the file between the call to isfile and the call to open.

    exceptions should be used much more sparingly in C++ than in Python because they don't work as well in the former.

    Could you explain what you mean by this? Is it that Python tends to throw (predictable) exceptions in cases where C++ has (unpredictable) undefined behavior?

    1. Re:You just created a TOCTTOU race bug by mrchaotica · · Score: 1

      Congratulations: You just created a time of check to time of use (TOCTTOU) race bug. Consider what happens if another process deletes the file between the call to isfile and the call to open.

      Then open() throws an exception and you're no worse off than if you had blindly called it, "expecting" the exception, in the first place. My examples were minimal in order to show the overall pattern of execution; I never claimed they were complete or that they included all the error handling they should actually have.

      exceptions should be used much more sparingly in C++ than in Python because they don't work as well in the former.

      Could you explain what you mean by this? Is it that Python tends to throw (predictable) exceptions in cases where C++ has (unpredictable) undefined behavior?

      http://yosefk.com/c++fqa/defec...

      --

      "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

    2. Re:You just created a TOCTTOU race bug by tepples · · Score: 1

      yosefk writes:

      If we use exceptions, we have to write exception-safe code - code which frees all resources when the control is transferred from the point of failure (throw) to the point where explicit error handling is done (catch). [...] To solve this, you are supposed to use RAII, meaning that all pointers have to be "smart"

      I think this was written before C++11 standardized two suitable smart pointers in std::unique_ptr and std::shared_ptr. Stash resources allocated by the constructor in a smart pointer.

      In 17.4, yosefk continues:

      How are you going to figure out whether your program manages resources correctly or not when it's littered with smart pointers of different kinds, especially in [...] cases when "ownership" (the right & duty to dispose a resource) is passed from object to object

      The replacement of the problematic std::auto_ptr with std::unique_ptr that uses C++11's new move-construction semantics and addition of std::shared_ptr solved, as yosefk mentioned with the references to Boost pointer templates that made it into TR1.

      I wonder whether yosefk plans to refactor this page into "Defective Modern C++" to parallel the title of a 2014 book by Scott Meyers (ISBN 9781491903995).

  37. 30 Years Late by Anonymous Coward · · Score: 0

    Isn't this about 3 decades past due, and long past any window of opportunity to become really important?

    Seriously, C++ needed this back in the 80's.

  38. C++: Now mature enough for embedded programming? by Anonymous Coward · · Score: 0

    I was in college when the cfront ("C with Classes", later renamed "C++") preprocessor came out (1983). We continued to use C in class. (Um, making it a C class without "C with Classes".)

    As I shifted to industry and specialized in embedded/real-time programming, I watched many bad C++ compilers appear. But even these compilers, when used correctly, enabled the use of many C++ features in firmware. (Burned into UV-EPROMs, and get off my lawn!)

    By the early '90's a consensus was developing within the embedded community that there should be a standardized subset of C++ that would be "blessed" for embedded use, the main criteria being that only features that would keep us "running light, without overbyte" (relative to C) would be so blessed.

    This notion caught on with several large companies, and many style guides for "Embedded C++" appeared, generally one for each revision of every different C++ compiler out there. But all that changed when the Japanese car makers made their presence known: They decided to sponsor an effort to specify a language to be called "EC++".

    This effort started with great hopes (I was a minor contributor), but came to an abrupt end when we realized the Japanese actually wanted a fixed specification (for a new compiler), not one that would actively track the ongoing advances in C++ compiler technology. Which interested me not at all.

    That was when I largely abandoned following the bleeding edge of C++ compiler developments for use in ROMmed code: The EC++ subset was too limited to be worth using (IMHO), and it was getting too difficult to track compiler advances while actually getting code written. And the ISO C effort was doing a great job cherry-picking many valuable concepts from C++.

    I've been hoping for another industry effort to push C++ into my firmware, and I believe the C++ Core Guidelines may be precisely what I've been waiting for, or at least a giant step in that direction, assuming ISO C++ follows along. The Guidelines emphasize how to do what C++ does best, and they effectively bypass much of the cruft a 32 year old continuously evolving language accumulates.