The Ruby Minimalist
Counterculture

Michel Martens

https://twitter.com/soveran

https://github.com/soveran

https://openredis.com

Write less code

The Shell from Plan9

Switch in bash

case $1 in
  "bar")
    ... ;;
  "baz")
    ... ;;
esac
            

For-loop in bash

for f in *; do ...; done
            

If/else in bash

if [ condition ]; then
  ...
else
  ...
fi
               

Switch in rc

switch ($1) {
  case "bar"
    ...
  case "baz"
    ...
}
                

For-loop in rc

for (f in *) { ... }
                

If/else in rc

if (condition) {
  ...
} else {
  ...
}
                

Case study about dependencies
Version tracking and isolation

Dependency tracking
github.com/cyx/dep

$ cat .gems
ohm -v 2.0.0
cutest -v 1.2.1
                

$ dep
dep: missing libraries
  ohm -v 2.0.0
  cutest -v 1.2.1
                

$ dep install
  gem install ohm -v 2.0.0
  gem install cutest -v 1.2.1
                

$ dep
dep: all cool
                

$ dep add cuba
dep: added cuba -v 3.1.1
                

$ dep
dep: missing libraries
  cuba -v 3.1.1
                

...and so on.

Gemsets and isolation
github.com/soveran/gs

$ gs init
                

$ find .
.
.gs
                

$ gem install clap
Fetching: clap-1.0.0.gem (100%)
Successfully installed clap-1.0.0
1 gem installed
                

$ gem list

*** LOCAL GEMS ***

clap (1.0.0)
                

$ rm -rf .gs
                

$ gem list

*** LOCAL GEMS ***
                

Trivial tools, but
powerful when combined

Comparison

dep + gs
---------------------
lines of code     189
complexity        197

bundler
---------------------
lines of code   10403
complexity      14103
                

Size

dep + gs
---------------------
x


bundler (x55)
---------------------
xxxxxxxxxx xxxxxxxxxx
xxxxxxxxxx xxxxxxxxxx
xxxxxxxxxx xxxxx
                

Complexity

dep + gs
---------------------
x


bundler (x71)
---------------------
xxxxxxxxxx xxxxxxxxxx
xxxxxxxxxx xxxxxxxxxx
xxxxxxxxxx xxxxxxxxxx
xxxxxxxxxx x
                

Back in 1905
If a body gives off the energy L in the form of radiation, its mass diminishes by L/V2.

In 1907
M=μ+E0/c2

In 1951
E=mc2

Evolution of chess notation

Back in 1614
The white king commands his owne knight into the third house before his owne bishop.

In 1750
K. knight to His Bishop's 3d.

In 1859
K. Kt. to B. 3d.

In 1946
N-KB3

Now
Nf3

Evolution of testing in Ruby

Back in 2003

assert_equal(2 + 2, 4)
                

In 2005

it "should be four" do
  (2 + 2).should eql(4)
end
                

In 2010

it "should be four" do
  expect(2 + 2).to eq(4)
end
                

In 2012

subject { 2 + 2 }

it "should be four" do
  subject.should eq(4)
end
                

Now

Feature: Addition
  In order to test
  As a programmer
  I want to write a lot
Scenario: Add two numbers
  Given I have 2
  And I add 2 more
  When I actually add them
  Then the result should be 4
                

Write less code

Forking tests
github.com/djanowski/cutest

Basic example

test do
  assert_equal(2 + 2, 4)
end
                

$ cutest ./my_tests.rb
.............................
$
                

Comparison

cutest
---------------------
lines of code     130
complexity        160

rspec
---------------------
lines of code    8955
complexity       8272
                

Size

cutest
---------------------
x


rspec (x68)
---------------------
xxxxxxxxxx xxxxxxxxxx
xxxxxxxxxx xxxxxxxxxx
xxxxxxxxxx xxxxxxxxxx
xxxxxxxx
                

Complexity

cutest
---------------------
x


rspec (x51)
---------------------
xxxxxxxxxx xxxxxxxxxx
xxxxxxxxxx xxxxxxxxxx
xxxxxxxxxx x
                

A Minimal Stack
ohm cuba nobi malone redic
shield scrivener armor mote hache

Only 1446 lines of code

A Marketplace for Learning
http://educabilia.com.br

Redis
http://redis.io

Redis Hosting
http://openredis.com

Job Board
http://jobs.punchgirls.com

Join us at #lesscode
on freenode, every day
at any time.

And visit lesscode.is for more info.

Thank you!