rubyx/CodeStyle.md

39 lines
1.4 KiB
Markdown
Raw Normal View History

2015-06-29 19:52:36 +02:00
# Code Style and Conventions
Just few things that have become important enough to write down. Apart from what is written here
2017-01-01 23:29:20 +01:00
standard blah applies (ie RoboCop/Reek stuff).
2015-06-29 19:52:36 +02:00
## Formatting
### Line Length
2015-10-07 10:32:48 +02:00
2015-06-29 19:52:36 +02:00
While the days of 80 are over, too big steps seems difficult. I've settled on 100 (ish)
2017-01-01 23:29:20 +01:00
### Brackets
While ruby allows the ommision of brackets even with arguments, i try to avoid that because
of readablity. There may be an exception for an assignment, a single call with a single arg.
Brackets without arguments look funny though.
2015-06-29 19:52:36 +02:00
### Hash
I still prefer 1.9 => style , it makes the association more obvious.
## Code style
### Module functions are global
Often one thinks so much in classes that classes get what are basically global functions.
2015-10-07 10:32:48 +02:00
Global functions are usually meant for a module, so module scope is fitting.
2015-06-29 19:52:36 +02:00
A perfect example are singleton accessors. These are often found clumsily on the classes but
the code reads much nicer when they are on the module.
### Code generators
Instead of SlotToReg.new( register, index , register) we use Register.slot_to_reg( name , name , name).
2016-02-25 21:03:11 +01:00
All names are resolved to registers, or index via Type. More readable code less repetition.
2015-10-07 10:32:48 +02:00
As the example shows, in this case the module function name should be the instruction class name.
2017-01-01 23:29:20 +01:00
Singletons should hang off the module (not the class), eg Parfait.object_space