rubyx/CodeStyle.md

34 lines
1.3 KiB
Markdown
Raw Normal View History

2015-06-29 19:52:36 +02:00
# Code Style and Conventions
2018-03-20 11:22:16 +01:00
Just few things that have become important enough to write down. Apart from what is written here 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
2018-03-20 11:22:16 +01:00
While ruby allows the omission of brackets even with arguments, i try to avoid that because
of readability. There may be an exception for an assignment, a single call with a single arg.
2017-01-01 23:29:20 +01:00
Brackets without arguments look funny though.
2015-06-29 19:52:36 +02:00
## 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 Risc.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