New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add example for std.stdio.stdin #2806
Conversation
Are documented unit tests restricted to functions right now? If not, this should probably be one to prevent bit-rot. |
On second thought, why add this example only for |
A useful example for stdin really needs to be a whole program, not a function. I struggled to create this program a couple years ago - it covers a number of unclear, implied how-to-use-it aspects of ranges. It does belong in std.stdio, as it illustrates basic use of stdio functions and how they fit together. Putting it under stdin is as good a place as any, as it is the most likely place a new user of stdio will look. |
I don't disagree with that. If you want to leave it in the However, please do make it a documented |
ok |
7110fa6
to
b1a657c
Compare
Uh, this somehow seems to crash DMD. Sorry for the hassle. |
b1a657c
to
c28a32b
Compare
It doesn't crash dmd, it errors with an admonition to use std.algorithm.sort. I put it back the way it was. |
copy( // copy output of .sort to an OutputRange | ||
stdout.lockingTextWriter()); // the OutputRange | ||
} | ||
---- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Put brace on separate line and put dots at the beginning of each line:
void main()
{
stdin // read from stdin
.byLine(KeepTerminator.yes) // a line at a time
.map!(a => a.idup) // byLine() reuses its buffer, so copy the lines
.array // convert to array of lines
.sort // sort the lines
.copy( // copy output of .sort to an OutputRange
stdout.lockingTextWriter()); // the OutputRange
}
I think this is a more established formatting convention for method chaining.
Examples:
D: http://ddili.org/ders/d.en/ufcs.html (see the example at the bottom of the page).
C#: http://visualstudiomagazine.com/Articles/2013/04/10/Essential-Reactive-Extensions.aspx?Page=2
Java: http://www.oracle.com/technetwork/articles/java/ma14-java-se-8-streams-2177646.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put the { on the same line as main() because vertical space is a bit important now that people view web pages on small screens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't help much on small screens and make snippets look awkward on normal screen. Also horizontal space is much more important as mobile devices are optimized for vertical scrolling.
Oh, sorry, I was waiting for a C++ project that doesn't use |
c28a32b
to
5156308
Compare
I've incorporated all requests. Please pull - Phobos doc desperately needs more examples. |
Auto-merge toggled on |
add example for std.stdio.stdin
Thanks. Although I didn't insist on it here, I think that generally most people would argue that separating out mass white space changes into their own commits is a good idea. |
Thank you. The whitespace changes came about because I run all code through a filter program, |
In modern D it's better to write ".map!idup" instead of ".map!(a => a.idup)". |
noice |
Also removes some unnecessary trailing whitespace.