News for hackers. Stuff that matters.
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]));