Code Formatting - NetLogo/Tortoise GitHub Wiki

This document mainly concerns itself with CoffeeScript-related formatting. For Scala code, we'll follow any rules from the NetLogo code formatting wiki page. A lot of the same rules from that page are also applicable for CoffeeScript:

Because CoffeeScript uses whitespace to indicate blocks of code, some code formatting is enforced automatically. We also have a CoffeeScript linter setup in both Tortoise and Galapagos that can check for a bunch of common formatting issues. When in doubt, you can always use existing code from the Tortoise engine as a reference. If something is done a certain way in that code it's likely okay (or we need a reminder to clean it up anyway!).

No Implicit Parenthesis

Rule

Always use parenthesis to wrap method calls. Good: console.log(myObj), bad: console.log myObj

Exceptions

None

Reason

The lack of parenthesis can make order of operations very confusing, especially since everything in CoffeeScript is an expression! We have a linter rule to catch this, but it's worth calling out on its own.

Naming Things

Rule

  • File names should be all lower case. In Galapagos, they are in kebab-case (widget-controller.coffee), and in Tortoise, just all lowercase, no punctuation (abstractagentset.coffee).
  • Event names (mostly used by Ractive components in Galapagos), should be in kebab-case, like resize-window.
  • Class names should be in PascalCase, as in WidgetController or AbstractAgentSet.
  • Variable names and method names should be in camelCase.
    • When creating a class field or method that you intend to be "private", you can prefix it with _ to indicate it's not meant for external use, like @_values or @_setup.

Exceptions

There aren't many good reasons for going against the naming scheme.

Reason

Maintaining clarity in naming makes it easier to quickly understand what the code you're reading does, and what the names you're seeing refer to.