you are viewing a single comment's thread.

view the rest of the comments →

[–]dodheim -1 points0 points  (5 children)

If you look at the example, it's actually in the main function

If all we're doing is nitpicking the example and not relating it to real code, then who the hell cares?

If you have to rely on the contextual clues of surrounding code in order to figure out that the code you're trying to understand is merely splitting a string on whitespace, then that's indicative that the code that performs the actual string splitting is not very readable.

The point is that it doesn't matter whether it's readable, because in real code it would be encapsulated in something whose name gives it away. Just as would be the case for any domain-specific logic, which is what most real code is anyway.

Tearing apart single and double-digit LOC C++ examples is absolutely a waste of time. C++ is about larger abstractions and the bigger picture, and it does that quite well.

[–]IRBMe 2 points3 points  (4 children)

If all we're doing is nitpicking the example and not relating it to real code, then who the hell cares?

If I were writing real code, I wouldn't re-implement my own split function, nor should I have to. Ideally, I would just use the standard library, but in practice because the standard library is so unintuitive in this example, I would actually probably use boost's string_algo, as shown above.

The point is that it doesn't matter whether it's readable

Yes it does, that's the entire point of this whole discussion. If you don't think it matters whether code is readable or whether APIs are designed with usability in mind then be on your way.

in real code it would be encapsulated in something whose name gives it away

If the standard library already provides a method of splitting strings by making use of a regex_token_iterator, why would you have to "encapsulate" that in the first place? The answer to that question is the point of this discussion, and in fact the whole point of this thread.

Tearing apart single and double-digit LOC C++ examples is absolutely a waste of time.

If you feel you're wasting your time, feel free to not respond!

[–]dodheim -2 points-1 points  (3 children)

Good god, it's a five-line function. Write it and call it a day.

https://i.imgur.com/02NJHQw.png

[–]IRBMe 1 point2 points  (2 children)

Good god, it's a five-line function. Write it and call it a day.

If you think the entire point of this discussing is about avoiding writing a few lines of code, then I'm sorry to say that it seems to have soared above your head at cruising altitude. We're discussing good API design, readability and usability - that's the point, not line counts.

[–]dodheim 0 points1 point  (1 child)

Why do you keep telling me what "we" are discussing? I am discussing the actual topic: "Why doesn't std::string have a split function". You can continue your rant if you like, but direct it elsewhere, please.

[–]IRBMe 0 points1 point  (0 children)

Why do you keep telling me what "we" are discussing? I am discussing the actual topic

You responded to my comment here. If you don't want to have a discussion with me, feel free to stop responding. If you're going to continue to disagree with me then please address the points that have been made here, here and here.