Live data from Hacker News

C++11 and Boost - Succinct like Python

fendrich.se

51–60 of 172 posts

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

#51
post #10

The only point that finds me in disagreement is the need for a code standard that decides well on which parts should be used and how . I don't understand: why limiting ourselves? Why choosing such a well-tested instrument and choosing NOT to use some of it?

It is because C++ is a large language and it has some features (e.g. macros) that can be horribly misused.

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

#52
post #31

Earlier quoted context omitted.

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

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

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

#53
post #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...

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

#54
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…

Decorators aren't difficult to understand. It tells you that the function is modified in some way. Iterables and list comprehensions are also easy to read, and I do not have a deep understanding of Python at all.

Right. I saw my first decorator before I knew what one was, and just from looking at it I knew enough to ask my friend "This thing looks like it's modifying the function somehow, what is it?".

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

#56
post #31

Earlier quoted context omitted.

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

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.

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

#57
I think people who jump on the "C++11 is as good as Python/Ruby/Javascript/other-language-of-the-week" bandwagon are missing the point, and that is that limitations are a good thing. Can C++ be made as concise and easily-readable as one of the above languages? I wouldn't doubt it.

C++ can be made to do lots of things, and it doesn't achieve that by being elegant. It achieves that by trying to do everything possible under the sun. Because of that, C++ is and always will be much more complex than the other languages.

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

#58
I find C++ much easier to read than Python. Here's how to reverse a string in C++:

string s = "string";

reverse(s.begin(), s.end());

And here's how to reverse a string in Python:

s = "string"

print s[::-1]

In my opinion, the C++ version is far easier to read and just makes more sense. Edit - This is just one small example, however, I find it holds true for the entire languages in general. Also, I do a lot of Python and C++ systems programming so I use both frequently and while I prefer C++, I think Python is the best scripting language available today.

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

#59
post #58

I find C++ much easier to read than Python. Here's how to reverse a string in C++: string s = "string"; reverse(s.begin(), s.end()); And here's how to reverse a string in Python: s = "string" print s[::-1] In my opinion, the C++ version is far easier to read and just makes more sense. Edit - This is just one small example, however, I find it holds true for the entire languages in general. Also, I do a lot of Python a…

Or you could use the "reversed" built-in function:

  s = "string"
  reversed(s)
It also has the plus of creating a generator, saving memory from a new array allocation.

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

#60
post #58

I find C++ much easier to read than Python. Here's how to reverse a string in C++: string s = "string"; reverse(s.begin(), s.end()); And here's how to reverse a string in Python: s = "string" print s[::-1] In my opinion, the C++ version is far easier to read and just makes more sense. Edit - This is just one small example, however, I find it holds true for the entire languages in general. Also, I do a lot of Python a…

That's python 2 syntax.
Post reply on HN