All Code
- Configure your editor for soft tabs, not hard tabs
- Expand tabs to two spaces
- Leave a trailing newline at the end of each file
C Code
-
No space between condition and paren.
if(1), NOTif (1) - Put the opening brace on the same line as the function declaration or conditional
- Always use curly braces, even if they can be left out.
- Prefer parentheses to implicit precedence rules (within reason)
- Alternate versions of functions should be named why they are different from the primary.
If there is a function person() and you want a version that takes the name of the person, it should be person_with_name(char *name) or person_with_details(char *name, ...). NOT person1(char *name).
Ruby Code
-
See
kernel/core/array.rbfor a style reference. -
Methods: Try to keep your methods short--one screenful and try to adhere to DRY within reason. Generally common functionality should be abstracted to helper methods (which you can make
private) but in some cases, particularly working with Core, sometimes trying to DRY things up is just an obstacle if you have to maneuver around several different error conditions, for example. -
Method names: should be clear, expressive and meaningful. Avoid using underscores to 'protect' the method (
__send__) with some exceptions.
Smalltalk-style method names are OK, meaning that you could have a
method SomeClass.make_from when it is intended to be invoked as
SomeClass.make_from file or SomeClass.make_from :file => name. There the parameter name 'completes' the method name and makes for more natural reading.
-
Variable names: make them clear and meaningful (with some well-known exceptions like using
ifor a counter.) Try to avoid shadowing method names, for example within Array useidxin favour ofindexbecause the latter is also a method name. - Postconditions: use postconditions only if your expression is a one-liner and you do not have many conditions.
-
Blocks: Use either
do..endor{..}, spaces between the delimiters and code (foo { |arg| code }). Split long or complex expressions over multiple
lines like this:
mapped = foo.map do |elem|
do_something_with elem
end
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
0.10—69% complete
Completed 9 of 13 tickets
Pages
- Home
- FAQ
- IRC Info and Who's Who
- Releases
- Using Git
- Installation
- Getting Started
- Common Build Problems and Solutions
- Howto - Contribute
- Howto - Write a ticket
- Howto - Run my Rails app with Rubinius
- Howto - Write a Ruby spec
- Howto - Write a Rubinius spec
- Howto - Fix a failing spec
- Howto - Develop with a separate RubySpec repo
- Howto - Debug shotgun
- The Rubinius specs
- Shotgun - The Rubinius Virtual Machine
- Developer Readme
- Core Library - Coding Guidelines
- Coding Style Guide
- Contributor Platforms
- Stuff to read
- Extending Standard Library Specs
- Improve Gem Support in Rubinius
- Actors - Concurrent Rubinius
- FFI or Foreign Function Interface
