O documento discute as vantagens e desvantagens do framework Ruby on Rails. Apresenta como Rails popularizou conceitos como convention over configuration e test-driven development, mas também simplificou demais alguns princípios de programação orientada a objetos. Debate que é importante sair da zona de conforto de Rails para entender melhor programação, projeto de software e padrões de projeto.
21. ‘the messiest, nastiest big-
ball-of-mud code I have
seen in my entire career has
been in Ruby on Rails
projects.’
Avdi Grimm - Autor do Exceptional Ruby,
com mais de 10 anos de experiência em C++
segunda-feira, 12 de setembro de 11
22. explicit dynamic_bitset(const std::basic_string<CharT, Traits, Alloc>& s,
typename std::basic_string<CharT, Traits, Alloc>::size_type pos = 0,
typename std::basic_string<CharT, Traits, Alloc>::size_type n =
std::basic_string<CharT, Traits, Alloc>::npos,
const Allocator& alloc = Allocator());
segunda-feira, 12 de setembro de 11
23. Assets Pipeline!
Complexidade do Rails *
0.01 1.2 2.x 3.0 3.1
* dados sem nenhum valor científico
segunda-feira, 12 de setembro de 11
24. Será que as opiniões do
rails são suficientes?
segunda-feira, 12 de setembro de 11
30. ‘‘Se eu fizesse isso em
Java, seria chamado de
criminoso’’
-- Cliente anônimo, que estava olhando um código
<sarcasm>bonito</sarcasm> em Ruby, mas tolerante
segunda-feira, 12 de setembro de 11
31. ‘‘Design Pattern é coisa
de Javeiro’’
-- Trocentos rubistas
segunda-feira, 12 de setembro de 11
34. ... e outros builtin:
irb(main):001:0> iterator = [1,2,3].each
=> #<Enumerable::Enumerator:0x10ece8d30>
irb(main):002:0> iterator.next
=> 1
irb(main):003:0> iterator.next
=> 2
irb(main):004:0> iterator.next
=> 3
irb(main):005:0> iterator.next
StopIteration: iteration reached at end
! from /Users/vinibaggio/.rbenv/versions/ree-2011.03/lib/ruby/
1.8/generator.rb:193:in `next'
! from (irb):6
segunda-feira, 12 de setembro de 11
35. Lei de Deméter e Princípio
da menor surpresa
segunda-feira, 12 de setembro de 11
36. def verify_status_change(site, current_event)
if current_event.status == :error &&
site.last_event.status == :success
site.create_error_change_report
elsif current_event.status == :success &&
site.last_event.status == :error
site.create_success_change_report
end
end
segunda-feira, 12 de setembro de 11
37. def verify_status_change(site, current_event)
if current_event.status == :error &&
site.last_event.status == :success
site.create_error_change_report
elsif current_event.status == :success &&
site.last_event.status == :error
site.create_success_change_report
end
end
segunda-feira, 12 de setembro de 11
38. def verify_status_change(site, current_event)
if site.success? && current_event.error?
site.create_error_change_report
elsif site.error? && current_event.success?
site.create_success_change_report
✓
end
end
segunda-feira, 12 de setembro de 11
39. class TreeNodeParentTransferController < ApplicationController
def update
current_tree_node = tree_nodes.find(params[:id])
current_tree_node.parent = tree_nodes.find(params[:parent_id])
current_tree_node.save
redirect_to tree_nodes_path
end
private
def tree_nodes
current_user.tree_nodes
end
end
segunda-feira, 12 de setembro de 11
40. class TreeNode < ActiveRecord::Base
has_many :children, :foreign_key => :parent_id,
:class_name => 'TreeNode'
belongs_to :parent, :class_name => 'TreeNode'
before_save :update_name
after_save :update_parents
private
def update_name
self.full_name = "#{parent.full_name}::#{name}"
end
def update_children
children.each(&:save)
end
end
segunda-feira, 12 de setembro de 11
41. class TreeNode < ActiveRecord::Base
has_many :children, :foreign_key => :parent_id,
:class_name => 'TreeNode'
belongs_to :parent, :class_name => 'TreeNode'
before_save :update_name
after_save :update_parents
private
def update_name
self.full_name = "#{parent.name_cache}::#{name}"
end
def update_children
children.each(&:save)
end
end
segunda-feira, 12 de setembro de 11
46. Violação de Single
Responsibility
class Client < ActiveRecord::Base
validates_presence_of :name, :cnpj
after_save :insert_in_workflow
after_save :log
end
segunda-feira, 12 de setembro de 11
47. Exemplos montados
são fáceis de mostrar,
mas é difícil aplicar no
dia-a-dia, requer prática
segunda-feira, 12 de setembro de 11
51. Funções definidas a
partir de outras
f(g(x)) = (f o g)(x) = h(x)
segunda-feira, 12 de setembro de 11
52. Programas inteiros
definidos a partir de
outros
segunda-feira, 12 de setembro de 11
53. ‘‘A language that doesn’t
affect the way you think
about programming, is not
worth knowing’’
-- Alan Perlis, pioneiro em técnicas de construção de
compiladores
segunda-feira, 12 de setembro de 11
54. Connascence, ou o Cálice
Sagrado
segunda-feira, 12 de setembro de 11
55. Baixo acoplamento
1. Connascence of Name
2. Connascence of Type
3. Connascence of Meaning
4. Connascence of Position
5. Connascence of Algorithm
6. Connascence of Execution
7. Connascence of Timing
8. Connascence of Identity
Alto acoplamento
segunda-feira, 12 de setembro de 11
56. 1. Connascence of
Name
def verify_status_change(site, current_event)
if site.success? && current_event.error?
site.create_error_change_report
elsif site.error? && current_event.success?
site.create_success_change_report
end
end
segunda-feira, 12 de setembro de 11
57. 1. Connascence of
Name
def verify_status_change(site, current_event)
if site.success? && current_event.error?
site.create_error_change_report
elsif site.error? && current_event.success?
site.create_success_change_report
end
end
segunda-feira, 12 de setembro de 11
58. 1. Connascence of
Name
def verify_status_change(site, current_event)
if site.success? && current_event.error?
site.create_error_change_report
elsif site.error? && current_event.success?
site.create_success_change_report
end
end
segunda-feira, 12 de setembro de 11
59. 4. Connascence of
Position
def find(type, conditions, joins, order, count)
...
end
segunda-feira, 12 de setembro de 11