Live data from Hacker News

C++11 and Boost - Succinct like Python

fendrich.se

71–80 of 172 posts

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

#71
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.

My experience has been the opposite in some cases, mainly due to C++ being statically typed, and having fewer implicit happenings.

Yesterday I spent a chunk of my day debugging why my Python script reported that zero computers on the network were using DHCP. Apparently the Win32_NetworkAdapterConfiguration property DHCPEnabled returns 'True' or 'False' in Python (those are strings, not bools). In C++ that's a compile time error. The Microsoft documentation says DHCPEnabled is a bool. So between implicit functionality (evaluating strings as bools) and dynamic typing, this isn't screaming scalability to me.

Yes, this is just one example, but it points to a whole class of errors that are lurking out there in production code. My guess would be, a complex C++ program written in the Lakos style would be more scalable than the equivalent Python program.

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

#72
post #64
post #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 u…

Is there really such a bandwagon?

Yes, it apparently has. The largest problem I see in this new trend is portability. Certainly, if you have full control over the environment and require everything to be bleeding-edge you are fine. If not... Well, just have a look at boost source code and you will see how concise nested workarounds in #ifdefs really are.

If your environment is solely your own and you don't care about having your users build something, fine.

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

#73
post #13

The changes to C++ are too little, too late. These changes should have been made years ago, and C++ has lost momentum and credibility. Is anyone comparing Python to c++? nope, only the other way around.

>C++ has lost momentum and credibility.

Could you expand on this a bit? I'm not a C++ guy, but I was thinking of picking it up. By what metric do you mean it has "lost credibility?"

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

#74

Earlier quoted context omitted.

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

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

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

In the spirit of the article, boost range also has a reverse filter, so the following would return a reversed range similar to python's generator expression

using namespace boost::adaptors;

  s | reversed
or

  reverse(s)

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

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

It won't be as good as Haskell for memory safety. For example, this program, using only C++11 idioms, crashes:

    #include 
    #include 

    int main() {
        std::vector v;
        v.push_back(std::string("Hello"));
        v.push_back(std::string("there"));
        for (auto ii = v.begin(), ie = v.end(); ii != ie; ++ii) {
            v.clear();
            std::cout 
Preventing this sort of thing requires strong guarantees about aliasing (to ensure that "v" can't alias the vector being iterated over), which the C++ type system can't help you with.

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

#77
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,…

That is a strawman requirement.

It is sufficient if the C++ code I write is reasonably readable to a fellow C++ programmer. I really don't care if it is not readable to a casual observer.

It is nice that Python code is readable to even to non python people. But it is not a requirement for every language.

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

#78
post #32

Earlier quoted context omitted.

Hey, hey my story is like yours. My go-to project (ha) is one that I've written in Boost.asio though it was back when C++11 was still C++-0x, but I also switched to Go for the project and saw gains in how easy it was to write efficient code. To be fair, threading is much easier now, but then again, it's still threading...

It's not essentially threads since multiple goroutines are mapped onto one thread (or more if set). It feels like threading but you could just use it as much as you need since it doesn't bring as much overhead as a thread :-) Check this out: http://en.munknex.net/2011/12/golang-goroutines-performance....

Sorry, that was my point. The new concurrency stuff in C++11 still isn't the same as go's goroutines. Certainly my application would not work very well if a goroutine mapped to a thread. :o

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

#79
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,…

Python, like all dynamically typed languages, has no readability once you start using multiple modules. Static types are important for declaring interfaces between components. I have pretty much written off Python, particularly now that Go exists. I've wasted too many hours tracing down data types in complicated Python programs, usually resorting to printing out the types at runtime to decode them. The problem with Python: it is great for simple programs, where the effort to writing the simple program is much less than the comparable program in C/C++/Java; but simple programs often grow into complicated programs, and then the effort of maintaining Python far exceeds the effort to maintain C/C++/Java. Go, on the other hand, is pretty nice for writing a simple program, and can then scale into a complicated program.

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

#80
I work with C++ daily and it still has many rough edges:

* Horrible error messages

* Even simple programs take ages to compile due to massive header files.

LLVM/Clang help on both fronts but it's still quite difficult.

D2 seems much more promising if you can do without the libraries.

Post reply on HN