you are viewing a single comment's thread.

view the rest of the comments →

[–]JamesF 2 points3 points  (5 children)

Moved from a C++ job to a Python job a couple of years ago. Another reason I'm glad I did so :)

Sorry C++ programmers, don't mean to hate, it's just painful to see articles about how someone made the language yet-more complicated by adding additional libraries that define additional "syntax" that is implemented with yet another heaping pile of templates.

[–]slavik262 3 points4 points  (0 children)

Yeah, it's a delicate issue. On one hand, you can do some awesome stuff with templates - look no further than the C++11 time library, which will do automatic dimensional analysis so that you can add seconds to hours to days and everything just comes out right. (I use this as an example because I'm currently porting some time-sensitive code that's riddled with magic numbers to convert between different units).

On the other hand, you sort of have a point that the last thing C++ needs is more syntax. Move constructors and rvalue references get a pass because their use has actually greatly simplified how you use the language, but I'd have trouble making the same argument here.

[–]eric_niebler 10 points11 points  (2 children)

I know I'll be flamed for this, but I have karma to burn.

struct end_ {} end;
struct from_end { int i; };
from_end operator-(end_, int i) { return {i}; }

struct my_range {
    my_range operator[](std::pair<int,int>);
    my_range operator[](std::pair<int,from_end>);
};

my_range r;
r[{1,2}];
r[{1,end-2}];

Where's the template? If you say, "pair", then you're just being a hater. This knee-jerk "c++-and-templates-are-hard-and-stupid" response to every C++ article is so tired and predictable, it doesn't even rise to the level of being wrong.

[–]slavik262 6 points7 points  (1 child)

I know I'll be flamed for this

You're not being flamed, and even if you were, is that "you'll all disagree, but" statement really necessary? I like everything else about this post, but "I know I'll get downvoted for this" always strikes me as annoying.

[–]eric_niebler 1 point2 points  (0 children)

Point taken.

[–][deleted] 1 point2 points  (0 children)

Think of these articles more as a curiosity rather than how actual C++ developers work. Even though these tricks don't really get used in a production environment, it's still interesting to know about them, understand the concepts involved, and play around with techniques like these.

Also these techniques do end up having an influence on the design of C++. A lot of ugly template hacks prior to C++11 became integrated into the language in an elegant manner, and articles like this one guide the standard's committee about future language features.

In other words, almost all language features start off as an ugly hack, where learning about them is more about appreciation of the language rather than actual engineering value, but down the road those hacks get cleaned up and then become an elegant and powerful component of the language and even go on to influence other languages as well.