google / blockly

The web-based visual programming editor.
https://developers.google.com/blockly/
Apache License 2.0
12.48k stars 3.71k forks source link

Generate code comments to indicate ONE_BASED_INDEXING #681

Open AnmAtAnm opened 8 years ago

AnmAtAnm commented 8 years ago

Blockly currently uses one-based indexing for lists and strings. This can be surprising to developers accustom to zero-based indexing, or Blockly users who see their code (extra math not found in the blocks, constants being changed).

We should document these differences in the generated code, in a single comment at the top of the code. Any block that uses ONE_BASED_INDEXING should trigger it.

We can write the message in a fun way, targeted towards young/new programmers, creating a learning opportunity:

"Notice something funny? Computer people like to count things starting from zero. We've shifted your list and string indices by one to match this convention."

The same string should be in our documentation, adjacent to documentation on disabling ONE_BASED_INDEXING. Developers who search the English string text will then learn why we chose that default, and how to disable it, if it doesn't fit their need.

NeilFraser commented 8 years ago

We can write the message in a fun way, targeted towards young/new programmers, creating a learning opportunity

Please remember that Blockly is a general purpose graphical programming editor. Generating a code comment is not appropriate for Blockly. This is something that might be appropriate for some Blockly-based projects used in education, such as Scratch. Also be sure to internationalize.

Related: 7928fac3cebd4ba310d94727e7b32ead06cb16b0

AnmAtAnm commented 8 years ago

Good point about internationalization.

As for being inappropriate for all uses, that is why we include configuration to disable it (even if it is on by default).

MNSDivya commented 4 years ago

Is this reported issue still needs a fix?