r/cpp • • Oct 15 '13

C++ has become a scripting language

http://voices.canonical.com/jussi.pakkanen/2013/10/15/c-has-become-a-scripting-language/
1 Upvotes

53 comments sorted by

View all comments

32

u/[deleted] Oct 15 '13

Not a convincing argument (1) most of the scripting languages ar dynamic, (2) that code would be 3 lines of python, (3) since when does C++ have a large standard library?

Bjarne was just was just saying it doesn't as they don't have a curator for it. Plus there are so many gaps in the standard library. Where are the GUI tools, the unicode support?

Don't get me wrong: C++ is an amazing language but it is not, nor was it designed to be, nor will it ever be, a Python. It's very very good at what it does but whatever that is, isn't scripting.

3

u/guepier Bioinformatican Oct 15 '13

Re (2): to be fair, the same could be done (quite efficiently) in C++ with proper libraries. Now this doesn’t weaken your point because C++ specifically lacks those libraries. That’s an issue that should be tacked sooner rather than later, IMHO.

Such stuff is much more generally applicable and useful than a standardised graphics library, for instance.

5

u/bames53 Oct 15 '13

I think pretty much the only missing thing necessary to achieve a basically 3 line version of this program is ranges. With ranges in C++ it looks something like this:

vector<string> lines;
copy(getlines(ifstream(argv[1])), back_inserter(lines));
sort(lines);
copy(all(lines), ostream_range(argv[2], "\n"));

Where getlines returns a lazy range, all() is the range equivalent of std::begin() and std::end(), etc.

And the committee's Ranges Study Group was started earlier than the Graphics Study Group.

3

u/matthieum Oct 15 '13

Note: if copy was specified in terms of range, then all would be unnecessary as you would just pass lines directly.

Note 2: Range (as a concept) already appeared in the range-for loop.

2

u/bames53 Oct 15 '13 edited Oct 15 '13

Sure, though it depends on if a container counts as a range.

A range isn't necessarily defined just as something with begin() and end() methods (or non-member overloads). I know some have argued that ranges should not be based on iterators. For example istream_iterator's default constructor is a way of shoe-horning into iterator form something that doesn't naturally fit that model. Instead, they say, ranges should be independent.

Here's Andre's 'Iterators Must Go' slide deck: http://www.slideshare.net/rawwell/iteratorsmustgo

1

u/matthieum Oct 16 '13

I agree (the input/output iterators are just awkward), however it is not how the range-for was defined.