gbdev / pandocs

The single, most comprehensive Game Boy technical reference.
https://gbdev.io/pandocs/
Creative Commons Zero v1.0 Universal
599 stars 92 forks source link

Standardize pseudocode #95

Closed avivace closed 3 years ago

avivace commented 3 years ago

There's still some syntax from the BASIC era (<> for !=, ..).

Pseudocode syntax should be standardized to use Python/C style

aaaaaa123456789 commented 3 years ago

Is there any reason for this besides "I know Python and C"?

pinobatch commented 3 years ago

In order to pick the right one, is there an advantage of one over the other?

aaaaaa123456789 commented 3 years ago

I'd say that = is the universally agreed symbol for equality, and since this is pseudocode, the tokenization/parsing ambiguity that caused == to be invented is not at all relevant. As for inequality, why not just use ? Are we trying to support browsers from 1999 that don't support Unicode?

Rangi42 commented 3 years ago

In papers with pseudocode I've sometimes seen math-standard = and for equality/inequality, with for assignment (as in sum ← 2 + 2).

avivace commented 3 years ago

Is there any reason for this besides "I know Python and C"?

I don't have a strong opinion on that, I just want to set a standard rule to follow.

I tought maybe following a language syntax gives a more "familiar" look to the pseudocode? Are there examples of people writing pseudocode with ?

aaaaaa123456789 commented 3 years ago

≠ is mathematical notation that everyone knows and understands; it's (hopefully) taught in primary school. Same with =. I don't have any pseudocode examples at hand (using that syntax or any other), but it's certainly common. After all, pseudocode is not code.

Rangi42 commented 3 years ago

Arguably C operators would also be okay since it's similarly low-level and snippets of it map well to asm. Like ld a, [hli] being a = *hl++.

But yes, there's plenty of pseudocode that uses ≠ and other Unicode: https://en.wikipedia.org/wiki/Pseudocode#Mathematical_style_pseudocode

aaaaaa123456789 commented 3 years ago

Someone unfamiliar with C wouldn't know if that mapped to *(hl ++) (as it does) or (*hl) ++. That's generally not too great.

pinobatch commented 3 years ago

Especially because those correspond almost perfectly to the instructions ld a, [hl+] and inc [hl].

avivace commented 3 years ago

How about:

References: http://www.cs.cornell.edu/courses/cs482/2003su/handouts/pseudocode.pdf , https://blog.usejournal.com/how-to-write-pseudocode-a-beginners-guide-29956242698, https://cs.wmich.edu/gupta/teaching/cs3310/sp18cs3310web/lecture%20notes%20cs3310/PseudocodeBasics.pdf, https://en.wikipedia.org/wiki/Pseudocode#Mathematical_style_pseudocode

JL2210 commented 3 years ago

/, mod

maybe ÷ and % instead?

AntonioND commented 3 years ago

I'm not a fan of % because it's also used for percentages.

avivace commented 3 years ago

/, mod

maybe ÷ and % instead?

÷ is okay, but what's wrong with /?

aaaaaa123456789 commented 3 years ago

/ is standard (see: fractions), so I see no issues with it.

Rangi42 commented 3 years ago

Also ÷ can be hard to distinguish from +.

avivace commented 3 years ago

Added to the Pan Docs document style guide: https://github.com/gbdev/pandocs/wiki/Document-Style