Rabbit Slide Show

Coding Conventions in Ruby

2017-10-16

Description

This talk gives intro about coding conventions and how can it be enforced in ruby.

Text

Page: 1

Coding
Conventions in
Ruby
Giovanni Sakti
Starqle

Page: 2

What is coding conventions?

Page: 3

Coding Conventions
A set of guidelines
for specifc programming languages
recommend programming styles,
practics and methods

Page: 4

What does it cover?
fle organization
indentation
comments
declarations
statements

Page: 5

What does it cover? (cont'd)
white space
naming conventions
practices & principles
architectural
etc

Page: 6

Coding conventions may be applied to
organization, specifc project or
specifc product

Page: 7

Benefts
Improve readability
Make software maintenance easier

Page: 8

Rationale
40-80% of the lifetime cost of a piece
of software goes to maintenance
Hardly any software is maintained for
its whole life by the original author

Page: 9

Rationale (cont'd)
Code conventions improve the
readability of the software, allowing
engineers to understand new code
more quickly and thoroughly
If you ship your source code as a
product, you need to make sure it is
as well packaged and clean as any
other product you create

Page: 10

Conventions may be formalized in a
documented set of rules or may be as
informal as the habitual coding practices
of an individual

Page: 11

Ruby Style Guide
Ruby has coding conventions document
called the Ruby Style Guide that serve
as a generic reference for Ruby
programmer
github.com/bbatsov/ruby-style-guide

Page: 12

RuboCop
Ruby also has interesting software to
enforce coding convention called
RuboCop

Page: 13

Installing RuboCop
% gem install rubocop

Page: 14

Using RuboCop
% rubocop <file-name>

Page: 15

Default Style Guide
By default, RuboCop use the ruby style
guide as the default confguration

Page: 16

Custom Style Guide
If you want to customize the style guide,
you can create a .rubocop.yml in the
same directory where you run rubocop

Page: 17

Custom Style Guide
You can use following default
confguration fle of RuboCop as
reference to create .rubocop.yml
github.com/bbatsov/rubocop/blob/
master/confg/default.yml

Page: 18

Custom Style Guide
Consult the following url for more info
about confguration
rubocop.readthedocs.io/en/latest/
confguration

Page: 19

Exercise
Implement a custom .rubocop.yml
confguration fle according to your
organization convention

Page: 20

Thanks

Other slides