-
Notifications
You must be signed in to change notification settings - Fork 292
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
Intent, not syntax #1748
Comments
In my experience, most "real world" examples are often convoluted and pack a lot of cruft completely unrelated to the construct presented. That's fine in blog articles and tutorials that go over each example in detail, but in docs, trying to get through 1000% more content, when all you're after is a sample of how to use the particular feature being discussed, can be daunting. I briefly looked at Signature docs and they example showing referencing a variable from the sub one-of-them(:$a, :$b, :$c where { $a.defined ^^ $b.defined ^^ $c.defined }) {
$a // $b // $c
};
say one-of-them(c=>42); # OUTPUT: «42» Not only it requires knowing and understanding a rather obscure On the other hand, a completely useless and made up example below clearly shows I can "just use" a variable in a where clause and have its value used in a typecheck. And even if a person isn't familiar with WhaterCode yet, they can surmise the meaning of sub foo($a, $b where * == $a²) { say "$b is a square of $a" }
foo 2, 3; # OUTPUT: «Constraint type check failed in binding to parameter '$b'…» |
That example is not totally useless. An useless example would be |
And shows intent refs #1748. Also separates code in different examples, leaving the text as text, so it addresses 4 and 5. It closes Still it should also show an example where the method chaining does not work by using some data structure that can be used as the last argument to something, but does not have that something as a method.
To reflect what is indicated by @lizmat here https://stackoverflow.com/questions/41531393/can-i-use-a-standalone-signature-as-a-signature-in-perl-6#comment84619436_41543023 and also reflect the intent of putting signatures into variables, as said in #1748 (by myself, but still). Also modifies the example changed in #1777, so thanks to @jimav for drawing this to our attention.
This is something I have found quite repeatedly through the documentation, and for that matter throughout almost everything that is written for every single language: Examples usually focus on syntax, and not on intent. This is the last one I have found, but I'm sure you can think of many others:
lazy 1..5
when documentinglazy
. This is an absolutely correct and serviceable example. The problem is that when we are dealing with relatively uncommon features such as this one, we would avoid cargo-culting by learners by using examples that could be actually used in real-life code.In this particular case, I guess that a sequence that needs heavy-weight computation and particularly that needs to compute every member based in the last one would be the case. This might be hard to think about, and focusing on syntax is generally OK because, after all, reference docs are not tutorials. However, in some cases, making the intent of the feature clearer would help newcomers to better understand the language and put it to use.
I'm sure you can come up with many other examples you have bumped upon; if that's the case and you can work on then (or assign them to me), that would be fine. If you think this is not a priority now or simply don't agree, I'd like to hear your opinion.
The text was updated successfully, but these errors were encountered: