Live data from Hacker News

C++11 and Boost - Succinct like Python

fendrich.se

41–50 of 172 posts

Re: C++11 and Boost - Succinct like Python

#41
No thanks. I'll use D if I want a ton of features for free. This is not beautiful code. I could work around it I guess because I've seen much worse coming from C++ but it's really not my ideal of C++. But this is a small example, the source code of the STL offers much more madness. Not to mention the compiler messages you get for using templates...

Re: C++11 and Boost - Succinct like Python

#42
post #3

"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 > 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), .…

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

#43

Is it possible to build Boost for iOS with c++11 enabled in llvm-clang?

On iOS 5 and newer (required for libc++), using clang 3.0 and newer (required for decent c++11 support), yes.

Can you explain how, or point me to a resource describing how to do it?

Re: C++11 and Boost - Succinct like Python

#44
post #34
post #27

It's succint, all right (well, sort of). But Python's major strength is readability, even more than coinciseness, or better, to provide both at the same time. C was born as a terse language, sacrificing readability for coinciseness (the original examples in K&R are incredibly succint, almost elegant, but far from readable). I can't see many improvements in C++ (a language that arguably has worse coinciseness than C,…

I call shenanigans. That's true of simple scripts, I'm sure. But you can't seriously claim to me that you can understand decorator idioms, iterables or list comprehensions without a deep understanding of the language. What you say might have been true for Python c. 1998, it certainly isn't true today. Broadly: reading code is just hard. It's much harder than writing code. There are no non-trivial codebases that can b…

List comprehensions are not deep magic. If you use SQL as your frame of reference, it's actually pretty easy to pick up. They also add a hell of a lot to readability once you know what it does.

Re: C++11 and Boost - Succinct like Python

#45
post #8
post #2

Great post, it's always fun to see the cutting edge of C++ revealed. It's such a strange land. :) To me, this post would have been 10X more interesting if there was some elementary benchmarking included. If it's about the same speed as the corresponding Python code, which I'd bet is easier to write for more programmers, then I don't quite see the point being as clearly proven. If it's 100 times faster (or whatever),…

I wrote this post. The program is I/O-bound, so the only speed improvement comes from not having to start up the Python interpreter. If the task was CPU bound, you would get a great performance boost (sometimes 100x over CPython), but that is well known. There can be other reasons than performance for writing in C++. Used well, the strong static type system can catch many bugs. I suspect (but I cannot prove) that it…

[deleted]

Re: C++11 and Boost - Succinct like Python

#46

cout I'm sorry, but as "succinct" as it is, this is basically an unreadable bullshit. Reminds me strongly of a macro abuse in C.

you might not like the syntax of this particular boost lib, but it bears no relation to macro abuse in C. For one it is strongly typed. Of course it is unreadable if you don't know C++ or boost range. But it is not more complex than a python map or filter with a lambda, if you don't know python.

Re: C++11 and Boost - Succinct like Python

#47
post #37
post #34

Earlier quoted context omitted.

I call shenanigans. That's true of simple scripts, I'm sure. But you can't seriously claim to me that you can understand decorator idioms, iterables or list comprehensions without a deep understanding of the language. What you say might have been true for Python c. 1998, it certainly isn't true today. Broadly: reading code is just hard. It's much harder than writing code. There are no non-trivial codebases that can b…

That is a given, I agree. But a complex program written in C++ (or using advanced C++ constructs) will scale much worse than a Python one, in my opinion.

I don't think that's necessarily true. In my opinion, both languages can be used by novices for simple scripts and by experts for complicated tasks. However, C++ seems to be getting easier for simple tasks (lambdas, initializers, auto, alias templates, etc.), while Python is getting more complex/powerful (metaclasses, exception tweaks, new I/O and function annotations — just to name a few).

Re: C++11 and Boost - Succinct like Python

#48
post #3

"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 > 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), .…

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

#49
post #6

Earlier quoted context omitted.

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.

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]))"

I suppose he wanted to showcase boost::format. You can do it simpler with std::to_string:

    return to_string(static_cast(s[0]));

Re: C++11 and Boost - Succinct like Python

#50
post #3

"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 > 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), .…

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 b…

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.

Post reply on HN