Add style guide updates based on CS19 notes#46
Add style guide updates based on CS19 notes#46ZacharyEspiritu wants to merge 3 commits intobrownplt:masterfrom
Conversation
|
(Sorry, my text editor automatically removed trailing whitespace changes which is where some of the extra lines in the diff come from.) |
src/style-guide.scrbl
Outdated
|
|
||
| @codedisp{ | ||
| fun is-this-noah(str :: String) -> String: | ||
| Ask: |
|
Sorry, didn't meant to use the GitHub review feature. Just want to leave comments. |
src/style-guide.scrbl
Outdated
| fun search<A>(lst :: List<A>) -> A: ... end | ||
| } | ||
|
|
||
| Now, the elements of @tt{lst} can be of any type, but all elements of lst will |
There was a problem hiding this comment.
Bad wording -- you just got through saying you don't want to have a list of Any type, but it's ok now to have a list of any type? (Note the capitalization...) You mean to say something closer to "Now, we don't know or care what the type of the elements of lst are, but we are asserting that they all be of the same type -- namely A. This distinction (between "any type at all", and "any single type, for any particular list") is subtle but important."
There was a problem hiding this comment.
Reworded it according to your comments—let me know what you think!
| important distinction between "any type at all" (@tt{List<Any>}) and | ||
| "any single type, for any particular list" (@tt{List<A>}). | ||
|
|
||
| Note that the actual name of the type parameter is arbitrary (we could have |
There was a problem hiding this comment.
I believe recently @jpolitz just changed the documentation for fold so that type variables are not a single letter, which might invalidate this paragraph.
| In other words, @tt{[list: 1, "apple", true]} would satisfy the annotation | ||
| @tt{List<Any>}. Creating @tt{List}s like this is usually bad practice. | ||
|
|
||
| In Pyret, we can do this by parametrizing the type. Rather than: |
There was a problem hiding this comment.
parameterizing? According to https://en.wikipedia.org/wiki/Parametric_polymorphism:
We say that the type of
appendis parameterized byafor all values ofa
|
|
||
| Similarly, do not use an @tt{if} expression to evalulate a predicate, and | ||
| then return @tt{true} or @tt{false}. For example, this would be | ||
| considered incorrect: |
There was a problem hiding this comment.
As this is about style, I feel it's weird to say that something is incorrect. Perhaps use "inappropriate" (or another word) instead?
CS19 has a few style guide updates based on our grading rubrics—we're looking to shift to linking to the Pyret style guide as opposed to our own so we can declutter the website a bit, so if we could add these changes to the pyret-docs style guide, that would be great!