News for hackers. Stuff that matters.
Re:C++11 and Boost - Succinct like Python by viraptor on Wednesday October 31, 2012 @10:32AM (#4722963)
"you will notice that it is more or less as succinct as the Python code." ??? I hope that this person writes better python than this:

    const map<const string, const tuple<int, int, StrToStr>> TagDataMap {
      {"title" , make_tuple( 3, 30, stripnulls)},
      {"artist" , make_tuple( 33, 30, stripnulls)},
      ...
it will be succinct when the whole type can get reduced to "auto". Python would just do:

    TagDataMap = {
        'title': (3, 30, stripnulls),
        'artist': (33, 30, stripnulls),
        ...
Ord implementation is also crazy:

    int i = static_cast<unsigned char>(s[0]);
    return (boost::format("%1%") % i).str(); 
considering it doesn't even handle different string encodings.

I don't want to complain about C++. It's a great language and has its uses. But it's not succinct and it's far away from what scripting languages provide. Claiming otherwise is close to fanboyism. Not being succinct is not a bad thing. There are many other things that C++ does for you that Python doesn't.

Re:C++11 and Boost - Succinct like Python by fusiongyro on Wednesday October 31, 2012 @12:10PM (#4723526)
I think you're being unnecessarily critical. The article begins with "I think that it is possible to write code in a style that is almost as painless as in a modern dynamic language like Python. I also think that is not so well known how much C++ has changed for the better, outside the C++-community. Hence this post."

The difference between make_tuple(...) and (...) is not significant compared to what it would have been before without list initializers at all and having to manually populate the map. That's something people who knew C++ of the past but not C++11 would be happy to see. The rest of the code is a great demonstration of these new features as well. That's the point: to demonstrate C++11, not undermine Python.

The article ends with some cogent criticism of C++. If this sets of your fanboy detector, you should turn it down a little.

Re:C++11 and Boost - Succinct like Python by viraptor on Wednesday October 31, 2012 @12:33PM (#4723658)
But that's a completely different claim. I agree that C++11 is much nicer than old C++. I really like the improvements. I'd be glad to see that argument in his post instead.

That's not what he wrote though. The title is "C++11 and Boost - Succinct Like Python", the contents say "almost as painless as in a modern dynamic language like Python". That's what I can't agree with. There's still lots of supporting syntax that doesn't actually do anything for the end result.

Re:C++11 and Boost - Succinct like Python by alpatters on Wednesday October 31, 2012 @01:31PM (#4724058)
The extra syntax is not there for nothing. It's adding type information. Thus allowing error checking or dispatching by type or optimisations at compile time. It is a cost in terms of syntax and readability but it's not for nothing.

So for correct programs the end result might be the same in terms of values. For buggy code and runtime speed that's not necessarily the case.

Re:C++11 and Boost - Succinct like Python by jlarocco on Wednesday October 31, 2012 @02:00PM (#4724204)
The extra code is there for a reason, but it's still there and it's not there in a language like Python.

Nobody would argue that C++11 code can be much cleaner than old C++ code. But to say it's almost as clean as Python goes to far, and isn't fooling anybody. So why not be satisfied beating old C++?

Re:C++11 and Boost - Succinct like Python by danking00 on Wednesday October 31, 2012 @02:20PM (#4724319)
And this is where I decide the language is too far developed on the wrong foundation.

I cannot put up with type systems that don't have complete or near-complete type inference. I don't know why one would start a new project in a language that didn't support Hindley-Milner.

Re:C++11 and Boost - Succinct like Python by Locke1689 on Wednesday October 31, 2012 @04:04PM (#4724724)
Just to elaborate on what danking00 is saying, the extra syntax in this case is not adding any extra information (to the compiler). The left hand type of the expression can be completely inferred at compile time, in this case. What that required syntax is adding is pain, but no gain (except for imperceptibly faster compile time).

In Haskell this would look like:

  TagDataMap = [
          ("title", ((3, 30, stripnulls)),
          ("artist", ((33, 30, stripnulls)),
          ...
Haskell will correctly infer that TagDataMap :: [(String, (Integer, Integer, String -> String)].

Ok, technically this is an associative list, not a Python dictionary, but it is a map and can be accessed like one. Hell, most people use dictionaries with less than 10 items, which are much slower than arrays most of the time

Re:C++11 and Boost - Succinct like Python by fusiongyro on Wednesday October 31, 2012 @05:09PM (#4724934)
"the extra syntax in this case is not adding any extra information (to the compiler)." This actually isn't true in C++, because there could be many classes in scope that could take a list initializer like this. In Haskell, no literal with [] can "turn into" something besides a list, but that can happen in C++:

    vector<int> items = {1,2,3,4};
    int[] items       = {1,2,3,4};
These have different types, so how would C++ know which one you meant if you instead wrote:

    auto items = {1,2,3,4};
Again, in Haskell this isn't a problem because literals have essentially a single type. (Edge cases around integers and strings notwithstanding).

Edit: Just to clarify, in a Hindley-Milner system you could maybe get away with something like that, but everything you name in an HM system you must use, and that isn't the case in C++:

    void foo() {
      auto items = {1,2,3,4};
      return;
    }
I can then make two classes with list constructors:

    struct FooClass {
      FooClass(std::initializer_list<int> list) {
        cout << "Made a Foo!" << endl;
      }
    };

    struct BarClass {
      BarClass(std::initializer_list<int> list) {
        format_your_hard_disk();
      }
    };
Obviously there are consequences to choosing the right type, but the type of that value never leaks out of the function. Nevertheless, because side-effects can happen anywhere, even in a constructor, C++ cannot optimize that out.

This might be a convoluted example, and it may be flawed, but conjuring up others is not hard and demonstrates that C++ simply cannot ever have true HM type inferencing. Since the "real deal" is not possible, the language is complex and the standard is large, I would not expect to be able to live without annotations in C++-land. (Again, the FQA makes the horror of multiple non-orthogonal solutions to the same problems quite clear).

Re:C++11 and Boost - Succinct like Python by danking00 on Wednesday October 31, 2012 @08:29PM (#4725571)
Your example,

    void foo() {
      auto items = {1,2,3,4};
      return;
    }
is the case of poorly designed syntax, in a truly Hindley-Milner system there is no expression which doesn't have a type. Now, we could add some syntax that screws that up, say:

    let v = I-HAVE-AN-AMBIGUOUS-TYPE in 0
But that's rather silly, isn't it? If a value isn't used then I would, personally, like my language to optimize it away. So why not ditch such silly syntax?

This is part of why I said that the foundations of C++ are too far-gone.

And this syntax isn't necessary to save on typing. In a language that supported syntactic macros (such as Scheme or Racket) we could write something like:

   auto items = my-vector-syntax(1,2,3,4);
which expands to something like:

    auto items;
    items.push_back(1);
    items.push_back(2);
    items.push_back(3);
    items.push_back(4);
If you're interested in true syntactic macros for non-sexp languages (though I do suggest getting over the parentheses, my color settings make them nearly indistinguishable from the background) look at Rust [1].

Actually, Rust also has type inference [2].

Hell, stop programming in C++ and start using Rust! [3]

[1] http://dl.rust-lang.org/doc/tutorial-macros.html [2] http://dl.rust-lang.org/doc/0.4/rust.html#type-system [3] http://www.rust-lang.org/

Re:C++11 and Boost - Succinct like Python by fusiongyro on Wednesday October 31, 2012 @09:05PM (#4725677)
Having programmed Haskell for the last seven years (and C++ for zero) I have a fairly decent handle on what HM is all about. If all you had said is that the foundations of C++ are too far gone, there wouldn't be anything to discuss. But the foundations of C++ being what they are, there's no point being offended when unfixable things go unfixed. I love HM, but you can't just throw it in any old language simply because it's cool. The language's semantics need to allow for it, and they just don't with C++.
Re:C++11 and Boost - Succinct like Python by danking00 on Thursday November 01, 2012 @06:34AM (#4726905)
Correct, I do not suggest adding HM to C++.

I suggest using a HM language when you start a new project.

Re:C++11 and Boost - Succinct like Python by comex on Thursday November 01, 2012 @02:09PM (#4728848)
It's possible to do exactly that (a function that initialized a vector with its arguments) in C++ with variadic templates...

You might end up in trouble if you did something like

    auto v = vec(
                  vec(1.2, 3.4),
                  vec(0)
                )
not sure how well other languages deal with that.
Re:C++11 and Boost - Succinct like Python by daivd on Thursday November 01, 2012 @06:11AM (#4726857)
"Hell, stop programming in C++ and start using Rust!" I plan to try to do that, when Rust has become more stable.
Re:C++11 and Boost - Succinct like Python by kibwen on Friday November 02, 2012 @01:46PM (#4733833)
No need to downvote this; I'm an enthusiastic Rust follower and I as well recommend that you stay far away from Rust until it settles down a bit. Wait for 0.5 if you're adventurous, 0.6 if you expect some degree of feature-completion, 0.7 if you're fine with half-finished standard libraries, and even later if you expect a high degree of stability, ergonomics, documentation, or performance.
Re:C++11 and Boost - Succinct like Python by Locke1689 on Wednesday October 31, 2012 @05:50PM (#4725081)
This is definitely true and demonstrates how competing design decisions can add huge complexity to a language. C++ made earlier design goals to allow heavily context-dependent overriding, which has side effects on what features it can add later.
Re:C++11 and Boost - Succinct like Python by Peaker on Wednesday October 31, 2012 @07:23PM (#4725382)
Integers and Strings aren't edge cases. Their literals are polymorphic and typed.

C++ could also type its list initializers with some polymorphic type (similar to Haskell's Num) but didn't do so.

This is not inherent.

Re:C++11 and Boost - Succinct like Python by fusiongyro on Thursday November 01, 2012 @09:35AM (#4727371)
They're not worth discussing because they're a counterintuitive mess rather than a case study of the glory of HM. Maybe edge case isn't the right word, but they're definitely not something I would hail as a perfect resounding success.

There are no polymorphic literals in ML, just polymorphic math operators, which is enough of a blight on the standard that OCaml discarded it and forces you to use different operators for real and integer arithmetic. And there's only one kind of string in both MLs.

Haskell's Num hierarchy is troublesome. They traded usability for + with complexity for /. It's extremely unlikely that you could write a program in Haskell that does much arithmetic and have it build correctly on the first try without any manifest typing. This is one reason students of Haskell find things so confusing: type declarations are necessary at the top level simply because the extensions and complexity of modern Haskell break HM if you try using it everywhere. Also, the class system in there is not especially mathematically correct, which leads to the numerous replacement Preludes that try to do a better job but haven't caught on.

Strings are edge cases because they are not polymorphic unless you enable OverloadedStrings. Once you do, you will either replace the built-in string with something else (ByteString or Text) or find yourself in the same kind of trouble you'd be in with Num.

Let me be clear: I'm not saying that these problems are showstoppers. They're really minor annoyances once you're experienced, though they contribute to confusion for beginners. The point I'm trying to make is that you can't just drop HM into any old language and expect it to work. A greater point would perhaps be that all languages have warts simply because they're large, complex beasts (Haskell and C++ especially) and it's unproductive to point to a missing feature in one and demand some sort of perfected version of the other's.

Re:C++11 and Boost - Succinct like Python by Peaker on Thursday November 01, 2012 @10:43AM (#4727752)
> They're not worth discussing because they're a counterintuitive mess

Do you really believe Num overloading is a counterintuitive mess? I disagree completely.

> OCaml discarded it and forces you to use different operators for real and integer arithmetic

Which is pretty terrible.

> Haskell's Num hierarchy is troublesome.

Yes, but that's an orthogonal issue.

> This is one reason students of Haskell find things so confusing: type declarations are necessary at the top level simply because the extensions and complexity of modern Haskell break HM if you try using it everywhere

That sounds like FUD to me, a heavy Haskell user. Type declarations at the top-level are generally necessary to avoid the dreaded MR and for documentation purposes. Modern Haskell doesn't heavily use extensions that require type annotations on the top-level.

> Strings are edge cases because they are not polymorphic unless you enable OverloadedStrings. Once you do, you will either replace the built-in string with something else (ByteString or Text) or find yourself in the same kind of trouble you'd be in with Num.

It lets me use literals for Lazy Text, Strict Text, and String with the same syntax, which is nice.

My point is merely that giving a type to a polymorphic initializer is possible, and C++ chose not to.

Re:C++11 and Boost - Succinct like Python by fusiongyro on Thursday November 01, 2012 @02:14PM (#4728876)
The distinction between your point and mine is becoming miniscule, but I must defend my position on Haskell, as a heavy user myself. If Num doesn't seem to be a problem to you, it's because you supply top-level annotations that disambiguate it. Try removing all the annotations from whatever you did last week and see if it still compiles cleanly. I'd wager it doesn't. This isn't an issue in practice because we supply annotations in most cases, but don't be fooled: top level annotations, despite the rhetoric, actually are essential for modern Haskell programs to disambiguate. As for strings, the problem doesn't appear in practice because people mostly don't intermingle string types in the same module. That's what makes Num tricky; it's easy to find yourself with Ints and Integers together, wanting to divide them and get a float, and figuring out how to resolve these minor issues is significant for learners. Just ask my friends!
Re:C++11 and Boost - Succinct like Python by Peaker on Friday November 02, 2012 @07:22AM (#4732090)
This is one of the files in a project I've worked on last week.

https://github.com/Peaker/bottle/blob/master/codeedit/Editor...

I removed all the top-level type declarations, and only one definition broke, because of the MR.

  showP :: Show a => a -> String
  showP = parenify . show
Once I removed the type declaration, I made it work again by adding a parameter to avoid the MR:

  showP x = parenify (show x)
and everything compiles smoothly.

Feel free to browse the bottle repo -- and try to build it without top-level declaration. Apart from a few functions in the entire project that use Rank2, you won't need any declarations.

Re:C++11 and Boost - Succinct like Python by fusiongyro on Friday November 02, 2012 @01:17PM (#4733683)
Thanks for sticking with this conversation.

This is very good code.

One difference I see between our styles that may explain the differences in behavior we see is that you're quite meticulous about importing only the parts of modules you need, and you make heavy use of qualified imports. My style has been to import everything in case I need it later and only use qualified imports when absolutely necessary, and it must be creating the unnecessary ambiguity that I have to deal with. I will try to adopt your style and see if it cleans up my error messages, and I'll encourage my friends to do the same.

Re:C++11 and Boost - Succinct like Python by daivd on Wednesday October 31, 2012 @04:05PM (#4724726)
Even in Hindley-Miller type systems it is considered good practice to add types as documentation to top-level constructs (see Haskell). In Python it is also considered good practice to add argument and return type info in the doc string. In a dynamic language you would also have to add a unit test or two for cases for some of the things that the compiler can catch for you.

Looking at the complete picture makes a language with local type inference (like C++11) more or less as verbose as one with complete type inference.

Re:C++11 and Boost - Succinct like Python by longlivedeath on Wednesday October 31, 2012 @09:12PM (#4725696)
> it is considered good practice to add types as documentation to top-level constructs

But with type inference your tools can do that for you (e.g. C-u C-c C-t in haskell-mode).

Re:C++11 and Boost - Succinct like Python by lmm on Thursday November 01, 2012 @12:36PM (#4728355)
A good IDE can fill in the types in C++ too.
Re:C++11 and Boost - Succinct like Python by longlivedeath on Thursday November 01, 2012 @09:30PM (#4730781)
Is there a C++ IDE that can figure out the function signature after you have written something like

_ f(_ a, _ b, _ c) { YOUR; CODE; HERE; }

?

Re:C++11 and Boost - Succinct like Python by codewright on Thursday November 01, 2012 @03:40AM (#4726575)
Wrong foundation? No. Foundation you don't want? Sure.

Try to remember that Hindley-Milner is very hard to do outside of functional languages like ML and Haskell.

Re:C++11 and Boost - Succinct like Python by danking00 on Thursday November 01, 2012 @12:02PM (#4728178)
Yes type inference is harder with C++'s language design (OO comes to mind as a particular problem), thus my claim that it's the wrong foundation to build on. Of course, people like challenging problems and are working to bring more type inference to OO languages [1].

Furthermore, I assert that this truly is the wrong foundation. For new projects that must have OO, Scala provides local type inference and object orientation. If you're really hurting for some manual memory management, look at Rust [3] or Habit [2].

If we can recover the features we love on a new foundation that provides new features like type inference or memory-safety, then we've found a better foundation, IMHO.

[1] http://www.cs.ucla.edu/~palsberg/typeflow.html

[2] http://hasp.cs.pdx.edu/habit-report-Nov2010.pdf

[3] http://www.rust-lang.org/

Re:C++11 and Boost - Succinct like Python by Myrmornis on Wednesday October 31, 2012 @03:13PM (#4724537)
This is what caught my eye too as being really ugly and hard to read.

  const map<const string, const tuple<int, int, StrToStr>> TagDataMap {
      {"title" , make_tuple( 3, 30, stripnulls)},
Why can't the compiler figure out the types involved in this map structure itself? The user-defined functions are declared above, make_tuple will be declared in some library, and the others are string/int literals.
Re:C++11 and Boost - Succinct like Python by fusiongyro on Wednesday October 31, 2012 @04:45PM (#4724845)
One thing you cannot do is infer `const`ness. This isn't a problem in Hindley-Milner systems because variables are not assignable--they're all `const`, all the time. Literals are inherently immutable but when you assign a C++ variable a literal value, sometimes you want a const variable and sometimes you don't.

I don't think C++ can figure out the map<..> part simply because lots of things could have list initializers that accept lists of 2 item lists. C++'s overloading and implicit conversion conflicts with perfect type inferencing. This is an example of the kind of thing the FQA talks about, where several of C++'s issues collide to produce counter-intuitive behavior.

I do wonder if you could get away with this:

    const map<const auto, const auto> TagDataMap { ...
I don't have access to a C++11 compiler from where I am to find out though. I am particularly unclear on the interaction between `auto` and other aspects of a type declaration--I don't know if you can nest `auto` like this deep inside some other type declaration. I don't see why you couldn't, but wouldn't be shocked either.
Re:C++11 and Boost - Succinct like Python by bcoates on Wednesday October 31, 2012 @06:33PM (#4725243)
You can't do it with that syntax. 'auto' never infers constructor calls, just takes the static type of an LHS to capture a temporary into. You'd have to use a non-constructor template function that inspects the type of its argument to guess what kind of map you want.

  const auto TagDataMap = map_initializer( { "foo", { 1, 20, func }, ... } );
where map_initializer would be a template function that inspects the typedefs of its std::initializer_list<T> argument and generates an appropriate map.

In real C++ code, this would almost never be what you actually want, though, as the types in an initializer list in C++ do not imply the types being initialized, they are parameters to a constructor to be determined elsewhere.

Re:C++11 and Boost - Succinct like Python by fusiongyro on Wednesday October 31, 2012 @06:46PM (#4725277)
Thanks for clearing that up. I'm just starting to play with C++11 and have some trouble getting to a supporting compiler from work.
Re:C++11 and Boost - Succinct like Python by Evbn on Wednesday October 31, 2012 @11:20PM (#4726039)
It would help a lot if the keyword 'const' were replaced by a punctuation character or shorter simpler keyword like 'val'
Re:C++11 and Boost - Succinct like Python by hnriot on Wednesday October 31, 2012 @02:01PM (#4724208)
that's not entirely true, take make_tuple for example, this doesn't add anything except verbosity (by comparison to Python)
Re:C++11 and Boost - Succinct like Python by derleth on Wednesday October 31, 2012 @02:40PM (#4724401)
> The extra syntax is not there for nothing.

You could say the same thing about everything old C++ compelled you to type. Or old COBOL, for that matter.

I'm more interested in what the C++ memory allocation style does to verbosity. Memory-handling styles are often more important than the traditional paradigms (functional, OO, etc.) in determining what's reasonable/pleasant to do in a given language.

https://sites.google.com/site/steveyegge2/allocation-styles

Re:C++11 and Boost - Succinct like Python by eru on Wednesday October 31, 2012 @07:20PM (#4725371)
But aren't all allocation styles basically the same once you get GC? (I guess unless you broaden the scope of the word, and let it describe the lengths you go in Haskell to avoid allocation at all, aka triggering stream fusion and automatic deforrestation in general.)
Re:C++11 and Boost - Succinct like Python by Evbn on Wednesday October 31, 2012 @11:15PM (#4726021)
There are other issues: Go has stuff like slice for efficiently allocating array data more finely than a Java array, perl has autovivication.
Re:C++11 and Boost - Succinct like Python by drivebyacct2 on Wednesday October 31, 2012 @02:03PM (#4724213)
Yeah, I agree with the claim that this is not in the same realm of readability (seriously, just consider for 10 seconds what an at-scale C++11 codebase looks like versus a scaled up python code base. But I understand why they're different and I can't get enough of the statically typed kool-aid lately.
Re:C++11 and Boost - Succinct like Python by Evbn on Wednesday October 31, 2012 @11:17PM (#4726028)
I am picturing Python drowning in isinstance checks to avoid constant crashing every time a new function is added.
Re:C++11 and Boost - Succinct like Python by drivebyacct2 on Thursday November 01, 2012 @01:38AM (#4726361)
I'm just imagining how many nights in a row I've committed more lines of code than exist in my project in a snapshot because it's so damn confusing, interconnected, and concurrent. The thought of doing it in a dynamic language is downright nauseating.
Re:C++11 and Boost - Succinct like Python by daivd on Wednesday October 31, 2012 @10:48AM (#4723033)
You misunderstand the purpose of ord. The mp3 metadata uses one byte to encode an integer between 0 and 255, which represents genre. It is not a string.
Re:C++11 and Boost - Succinct like Python by viraptor on Wednesday October 31, 2012 @11:09AM (#4723143)
I did misunderstand it. But then the first point is even stronger. Those two lines are definitely not as short/clean/readable as "str(ord(s[0]))"
Re:C++11 and Boost - Succinct like Python by ajross on Wednesday October 31, 2012 @11:37AM (#4723319)
No, because they have some extra tokens in the syntax (mostly to deal with strong typing). But they're semantically identical, which I think was the author's point. You declare the data instead of assembling it, and you do it in the same order and in the same manner. There's more typing but the idiom is the same.

This is something that I think a lot of people miss about modern C++. They make the mistake of assuming you still program it using C idioms, when often you don't have to. They assume you have to "manually manage memory" when obvious and simple RAII techniques have basically obsoleted that for probably 90% of cases.

It's just not like that. If you have a problem that is "easy to express" in Python/Perl/Ruby/Javascript it is expressable in essentially the same way in C++.

The gotcha to my mind is more that the C++ environment is unforgiving -- a novice python programmer making a syntax error generally bangs around and gets it to work, maybe with some odd thought errors someone else will have to clean up. A novice C++ programmer is lost until they find an expert to explain the problem. So I don't think web engineers need to worry about losing their jobs to C++ hackers quite yet.

But at the same time, the intuition that C++ is "hard" is mostly wrong. A true expert can solve the same problems the scripting languages do, arriving at essentially equivalent code, in very similar time and with very similar (potentially higher due to typesafety) quality.

Re:C++11 and Boost - Succinct like Python by Symmetry on Wednesday October 31, 2012 @12:37PM (#4723684)
A true expert can solve the same problems

That's true, but I think ignores the main problem with C++. I'd say I know about three times as many things about how C++ as I do about how Python works, but I still feel like I'm more of an expert in Python than C++ just because C++ is such a stupendously large language now.

Re:C++11 and Boost - Succinct like Python by ajross on Wednesday October 31, 2012 @12:48PM (#4723755)
To be fair, I think that's absolutely correct and tried to point it out. It's a legitimate reason for sane people to choose Python over C++.

Nonetheless, the really are "true experts" in the world. These people tend to write most of the really important software, and they tend to work with each other on teams where "everyone" (or nearly so) is another expert. In those environments, I think a very strong case can be made for C++ as the best overall choice.

The real point is that simplistic arguments like "C++ isn't as clean as python" are off target.

Re:C++11 and Boost - Succinct like Python by tedmielczarek on Wednesday October 31, 2012 @02:12PM (#4724277)
I write a lot of C++ every day. I work with a lot of people that write C++ all day every day. I don't know anyone that would consider themselves an expert in C++. The language is just too big.
Re:C++11 and Boost - Succinct like Python by daivd on Wednesday October 31, 2012 @11:36AM (#4723314)
I agree, it is much uglier. Part of it is that Python thinks a character is unsigned, whereas C++ thinks it is signed. This arbitrarily works in Python's favor here. Part of it is that Python just handles this better.
Re:C++11 and Boost - Succinct like Python by pbsd on Wednesday October 31, 2012 @12:28PM (#4723629)
I suppose he wanted to showcase boost::format. You can do it simpler with std::to_string:

    return to_string(static_cast<unsigned char>(s[0]));
Re:C++11 and Boost - Succinct like Python by fafner on Wednesday October 31, 2012 @12:25PM (#4723610)
For ord he could use std::to_string

    string ord(string const &s) {
      return to_string(unsigned(s[0]));
    }
He skips all the const-refs...
Re:C++11 and Boost - Succinct like Python by daivd on Wednesday October 31, 2012 @12:39PM (#4723695)
Yes, to_string would have been better

The C-style cast is shorter, but less safe, so you should not use it: http://stackoverflow.com/questions/1609163/what-is-the-diffe...

Yeah, I couldn't quite decide if I should include const refs. On the one hand, it is idiomatic, but on the other hand I didn't want to clutter the code with something that is just an optimization on paper.

Re:C++11 and Boost - Succinct like Python by fafner on Wednesday October 31, 2012 @01:03PM (#4723865)
I know the C-style casts are bad (although this is more of a C++-style-C-style cast. (unsigned) would have been the C-cast. But still bad). But in this situation it should be safe and for use in an example more readable.

btw. Please fix either the size of your code or the margins of your blog. You use only half the screen width but I still have to scroll sideways in the code listing.

Re:C++11 and Boost - Succinct like Python by mikeash on Wednesday October 31, 2012 @06:46PM (#4725279)
How can a C-style cast from char to unsigned possibly be "less safe", and how could a different style of cast be more safe?
Re:C++11 and Boost - Succinct like Python by daivd on Thursday November 01, 2012 @06:15AM (#4726865)
In this case it obviously doesn't matter, but in the general case it is better to be explicit on which type of cast you are doing. That way the compiler can statically stop you from doing stupid things. Read the link I gave.