Ruby
Or... Python?
by Eric Steven Raymond
/* C */
int fact( int n ) {
if (n <= 1)
return 1;
else
return n * fact(n - 1);
}
;;Lisp
(define (fact n)
(if (= n 0)
1
(* n (fact (- n 1)))))
#Python
def fact(n):
return reduce(lambda x, y:
x * y,
range(1, n + 1))
#Ruby
def fact(n)
(1..n).reduce(:*)
end
Programming is a process of designing DSL for your own application
by Dave Thomas
#Rails ActiveSupport
1.month.from_now
#Sinatra
get '/hi' do
"Hello World!"
end
#Rake
task :test do
ruby "unittest.rb"
end
#RSpec
describe Programmer do
it "should say hello to world" do
...
end
end
#Kaminari
User.page(7).per(50).padding(3)
module ActiveModel
...
autoload :AttributeMethods
autoload :Callbacks
autoload :Conversion
autoload :Model
autoload :Naming
autoload :SecurePassword
autoload :Translation
autoload :Validations
...
end
.thing_wrapper
header#thing_header= render "things/header"
section#thing_actions= render "things/actions"
section#thing_content= yield
.photos= render "carousel"
= tp.content
Not So Good
Not So Good
(1..10).detect { |i| i % 3 == 0 }
(1..10).select { |i| i % 3 == 0 }
(1..10).reject { |i| i % 3 == 0 }
(1..10).collect { |i| i*i }
(1..10).inject { |fac, i| fac*i }
(1..10).each { |i| puts i }
(1..10).group_by { |i| i % 3 == 0 }
(1..10).sort_by { |i| -i }
@mixin section-decorate {
background: white;
@include border-radius(8px);
@include box-shadow(rgba(0, 0, 0, 0.1) 1px 1px 10px);
}
@mixin icon-fixed-width {
display: inline-block;
width: 1.1428571428571428em;
padding-right: 0.2857142857142857em;
}
Not So Good
Grid System
Not So Good
# Use snake_case for symbols, methods and variables.
:some_symbol
def some_method
...
end
# Use SCREAMING_SNAKE_CASE for other constants.
SOME_CONST = 5
# Use CamelCase for classes and modules.
class SomeClass
...
end
$linkColor: #588cc7;
$headingsFontWeight: normal;
$btnPrimaryBackground: #049cdb;
Not So Good
Be Careful