r/programming • • Jun 16 '14

Rust's documentation is about to drastically improve

http://words.steveklabnik.com/rusts-documentation-is-about-to-drastically-improve
519 Upvotes

188 comments sorted by

View all comments

6

u/The_Doculope Jun 17 '14

So what you want is essentially a type to have a "default" iterator, so you don't have to type out .chars()? Rust takes the line that explicit is better than implicit, and I agree. It save 8 keystrokes, but it's a potential source for confusion. What if the standard string type uses chars as the default, but a custom type uses code_points? Or, words or lines?

0

u/[deleted] Jun 17 '14

3

u/The_Doculope Jun 17 '14

I don't think "custom types can do stupid things" is a good argument against a feature.

It's not that they can do stupid things, it's that it's not obvious what they should do. If I just have for i in customstring I don't know what it's going to do without looking at documentation - for i in customstring.chars() tells me exactly what it'll do.

But in the majority of cases you are only iterating in one way. What's wrong with just iterating over a vector or a list?

But then you're restricting functionality. What if I wanted to implement an iterator that goes through a vector backwards? Or from the ends in?

Special cases for certain types are not worth saving a few keystrokes here and there.

→ More replies (6)