News for hackers. Stuff that matters.
Re:Replacing Python by alextingle on Sunday September 29, 2013 @07:11AM (#6464811)
Wouldn't it be better to avoid calling the V() default constructor every time the function is called? You never know, it might have some long-winded side effect...

    template<typename V, typename R>
    R defaulted(const V& val, const R& default_val) {
      const static V v0;
      return val == v0 ? default_val : val;
    }
Re:Replacing Python by fauigerzigerk on Sunday September 29, 2013 @07:33AM (#6464858)
There was a time (before C++11) when not even local static variable initialization was guaranteed to be thread safe. And there are a few other reasons why it is discouraged: http://google-styleguide.googlecode.com/svn/trunk/cppguide.x...

So it's basically defensive programming, but I agree with you that it's probably too defensive nowadays.

Re:Replacing Python by alextingle on Sunday September 29, 2013 @08:25AM (#6464985)
With GCC, at least, you can guarantee that it's thread-safe. (Of course, in some pathological cases you can get then get deadlocks during global static initialisation. C++ is such a lovely language!)

Also, I don't think Google's style guide is the be-all-and-end-all of good C++ style. Virtually non of Boost's code would comply with it. "We do not use C++ exceptions" indeed!

Re:Replacing Python by nostrademons on Sunday September 29, 2013 @02:14PM (#6465992)
Google's styleguide makes it clear that the reason they don't use exceptions is because all code that calls a function that may throw an exception needs to be exception-safe, and Google has a large body of code that was written before exceptions were reliably supported by many compilers and so isn't exception-safe. It's a historical accident, in other words. The styleguide is also clear that if they were designing the it in the present without having to deal with a large body of legacy code, they might make a very different choice.
Re:Replacing Python by RogerL on Sunday September 29, 2013 @01:40PM (#6465874)
Google's style guide is written so that mediocre programmers don't get too trapped by C++ nuances.
Re:Replacing Python by cmccabe on Sunday September 29, 2013 @01:27PM (#6465818)
You're starting from a false premise, which is that Boost is good. In reality, Boost is stuff that either couldn't make the cut to get into the C++ standard library, or is so new that nobody knows whether it's any good or not.
Re:Replacing Python by CountSessine on Sunday September 29, 2013 @11:16PM (#6467584)
Boost is stuff that everyone wants to use but can't because they're forced to use an old or broken compiler that isn't capable of building real C++0x/C++2011 code. It's a staging ground. How else are you going to use std::bind or std::thread et. al. with visual c++ 2005?

Also, there are plenty of nice modules in boost that just don't belong in the standard library. ASIO is quite nice, but it has io_service implementations that are platform dependent. Statechart is pretty good, but it isn't the only state machine implementation in Boost and neither is clearly better than the other. Spirit has it's uses, but does it belong in the standard library?

Re:Replacing Python by alextingle on Sunday September 29, 2013 @05:15PM (#6466544)
You would never catch me saying that Boost is good. Heaven forfend! Some of it is good, and other bits are awful. The Boost "style" is, however, quite popular in commercial C++ projects.