Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Qualidade de código
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Bruno Alvares da Costa
September 12, 2012
Technology
190
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Qualidade de código
Bruno Alvares da Costa
September 12, 2012
More Decks by Bruno Alvares da Costa
See All by Bruno Alvares da Costa
Go para Rubystas
brunoadacosta
0
92
O Básico sobre TDD
brunoadacosta
1
82
Cloud computing
brunoadacosta
3
170
Other Decks in Technology
See All in Technology
強化学習「理論」入門
enakai00
3
3.6k
サイバー捜査員研修(後半)
nomizone
1
870
[ChatGPT Work LT]事務作業が苦手な人のための バックオフィスの「半」自動化
chimaki_iot
0
280
Webアクセシビリティ入門 2026
recruitengineers
PRO
3
560
私がブラウザを自作したくなった理由
supurazako
1
230
生成 AI の基礎 〜 サンプル実装で学ぶ基本原理
enakai00
7
4.4k
クラウドセキュリティ入門 ~安全なクラウド利用のための基礎知識~
lhazy
13
8.7k
ホームラボ紹介
y_sera15
0
170
事業価値と Engineering 2026年度版
recruitengineers
PRO
49
23k
猫付きpingコマンドを自作
uyuki234
0
230
Forza Horizon 6 のテレメトリ機能で 自動運転に使えそうな学習データを集める話
henjin0
0
170
会社紹介資料 / Sansan Company Profile
sansan33
PRO
23
430k
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Documentation Writing (for coders)
carmenintech
77
5.4k
The untapped power of vector embeddings
frankvandijk
2
1.8k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
280
AI: The stuff that nobody shows you
jnunemaker
PRO
9
910
What's in a price? How to price your products and services
michaelherold
247
13k
Context Engineering - Making Every Token Count
addyosmani
9
1k
WENDY [Excerpt]
tessaabrams
11
39k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
210
Building the Perfect Custom Keyboard
takai
2
840
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
Music & Morning Musume
bryan
47
7.3k
Transcript
Qualidade do código Monday, November 12, 12
[email protected]
@brunoadacosta Bruno Alvares da Costa http:/ /hungroo.com /brunoadacosta Monday,
November 12, 12
Monday, November 12, 12
Inploy Hypertemplate Factory_girl-preload /brunoadacosta Monday, November 12, 12
Referências Monday, November 12, 12
Vamos ter em mente Manter um sistema ao longo do
tempo Implementar mudanças Corrigir bugs Evoluir Monday, November 12, 12
Codificar é dificil Monday, November 12, 12
Codificar é MUITO dificil Monday, November 12, 12
def update password_changed = false @user = current_user if u
= params[:user] u.delete(:password) if u[:password].blank? u.delete(:password_confirmation) if u[:password].blank? and u[:password_confirmation].blank? u.delete(:language) if u[:language].blank? # change email notifications if u[:email_preferences] @user.update_user_preferences(u[:email_preferences]) flash[:notice] = I18n.t 'users.update.email_notifications_changed' # change password elsif u[:current_password] && u[:password] && u[:password_confirmation] if @user.update_with_password(u) password_changed = true flash[:notice] = I18n.t 'users.update.password_changed' else flash[:error] = I18n.t 'users.update.password_not_changed' end elsif u[:show_community_spotlight_in_stream] || u[:getting_started] if @user.update_attributes(u) flash[:notice] = I18n.t 'users.update.settings_updated' else flash[:notice] = I18n.t 'users.update.settings_not_updated' end elsif u[:language] if @user.update_attributes(u) I18n.locale = @user.language flash[:notice] = I18n.t 'users.update.language_changed' else flash[:error] = I18n.t 'users.update.language_not_changed' end elsif u[:email] @user.unconfirmed_email = u[:email] if @user.save @user.mail_confirm_email flash[:notice] = I18n.t 'users.update.unconfirmed_email_changed' else flash[:error] = I18n.t 'users.update.unconfirmed_email_not_changed' end elsif u[:auto_follow_back] if @user.update_attributes(u) flash[:notice] = I18n.t 'users.update.follow_settings_changed' else flash[:error] = I18n.t 'users.update.follow_settings_not_changed' end end elsif aspect_order = params[:reorder_aspects] @user.reorder_aspects(aspect_order) end respond_to do |format| format.js { render :nothing => true, :status => 204 } format.all { redirect_to password_changed ? new_user_session_path : edit_user_path } end end Monday, November 12, 12
def update password_changed = false @user = current_user if u
= params[:user] u.delete(:password) if u[:password].blank? u.delete(:password_confirmation) if u[:password].blank? and u[:password_confirmation].blank? u.delete(:language) if u[:language].blank? # change email notifications if u[:email_preferences] @user.update_user_preferences(u[:email_preferences]) flash[:notice] = I18n.t 'users.update.email_notifications_changed' # change password elsif u[:current_password] && u[:password] && u[:password_confirmation] if @user.update_with_password(u) password_changed = true flash[:notice] = I18n.t 'users.update.password_changed' else flash[:error] = I18n.t 'users.update.password_not_changed' end elsif u[:show_community_spotlight_in_stream] || u[:getting_started] if @user.update_attributes(u) flash[:notice] = I18n.t 'users.update.settings_updated' else flash[:notice] = I18n.t 'users.update.settings_not_updated' end elsif u[:language] if @user.update_attributes(u) I18n.locale = @user.language flash[:notice] = I18n.t 'users.update.language_changed' else flash[:error] = I18n.t 'users.update.language_not_changed' end elsif u[:email] @user.unconfirmed_email = u[:email] if @user.save @user.mail_confirm_email flash[:notice] = I18n.t 'users.update.unconfirmed_email_changed' else flash[:error] = I18n.t 'users.update.unconfirmed_email_not_changed' end elsif u[:auto_follow_back] if @user.update_attributes(u) flash[:notice] = I18n.t 'users.update.follow_settings_changed' else flash[:error] = I18n.t 'users.update.follow_settings_not_changed' end end elsif aspect_order = params[:reorder_aspects] @user.reorder_aspects(aspect_order) end respond_to do |format| format.js { render :nothing => true, :status => 204 } format.all { redirect_to password_changed ? new_user_session_path : edit_user_path } end end Monday, November 12, 12
u[:password_confirmation].blank? u.delete(:language) if u[:language].blank? # change email notifications if u[:email_preferences]
@user.update_user_preferences(u[:email_preferences]) flash[:notice] = I18n.t 'users.update.email_notifications_changed' # change password elsif u[:current_password] && u[:password] && u[:password_confirmation] if @user.update_with_password(u) password_changed = true flash[:notice] = I18n.t 'users.update.password_changed' else flash[:error] = I18n.t 'users.update.password_not_changed' end elsif u[:show_community_spotlight_in_stream] || u[:getting_started] if @user.update_attributes(u) flash[:notice] = I18n.t 'users.update.settings_updated' else flash[:notice] = I18n.t 'users.update.settings_not_updated' end elsif u[:language] if @user.update_attributes(u) I18n.locale = @user.language flash[:notice] = I18n.t 'users.update.language_changed' else flash[:error] = I18n.t 'users.update.language_not_changed' end elsif u[:email] @user.unconfirmed_email = u[:email] if @user.save @user.mail_confirm_email flash[:notice] = I18n.t 'users.update.unconfirmed_email_changed' else flash[:error] = I18n.t 'users.update.unconfirmed_email_not_changed' end elsif u[:auto_follow_back] if @user.update_attributes(u) flash[:notice] = I18n.t 'users.update.follow_settings_changed' else flash[:error] = I18n.t 'users.update.follow_settings_not_changed' end end elsif aspect_order = params[:reorder_aspects] @user.reorder_aspects(aspect_order) end Monday, November 12, 12
Monday, November 12, 12
Code smell Monday, November 12, 12
Code smell Monday, November 12, 12
Monday, November 12, 12
Rigidez “Cada vez que você altera algo, outra coisa precisa
ser modificada” Monday, November 12, 12
Fragilidade “Uma mudança de uma parte do sistema, quebra em
muitas outras partes completamente alheios” Monday, November 12, 12
Imobilidade “É dificil separar o sistema em componentes que podem
ser utilizados em outros sistemas” Monday, November 12, 12
Complexidade desnecessária “Há muitas estruturas de código complexa sem necessidade,
ou otimização prematura” Monday, November 12, 12
Repetições inúteis “Código parece que foi escrito por dois programadores
chamados recortar e colar” Monday, November 12, 12
Qualidade do código boas práticas princípios e padrões Monday, November
12, 12
Monday, November 12, 12
Monday, November 12, 12
Refatoração “Não sou um grande programador, sou apenas um bom
programador com ótimos hábitos. Refatorar me ajuda a ser muito mais efetivo na escrita de código robusto” Kent Beck Monday, November 12, 12
S O L I D ingle Responsibility Principle (SRP) pen/Closed
Principle (OCP) iskov substitution principle (LSP) nterface Segregation Principle (ISP) ependency Inversion Principle (DIP) Monday, November 12, 12
Single Responsibility Principle Uma entidade, deve ter uma única responsabilidade
Responsabilidade pode ser definida como “razão para mudar” Monday, November 12, 12
Código ruim Monday, November 12, 12
SRP Monday, November 12, 12
Open Closed Principle Uma classe deve manter sua interface (API
pública) A implementação pode ser alterada livremente Monday, November 12, 12
Implementação mudou mas a interface permaneceu Monday, November 12, 12
Liskov substitution principle Deve ser possível subistituir uma classe por
suas classes derivadas em qualquer ponto do código O código não deve ser alterado para isso acontecer Monday, November 12, 12
Liskov substitution principle Monday, November 12, 12
Interface Segregation Principle Classes não devem ser obrigadas a depender
de interfaces que elas não utilizam Deve-se utilizar interfaces concisas, com apenas o que é usado O SRP resolve este problema Monday, November 12, 12
Classe marota :) Monday, November 12, 12
Aplicando o SRP, se aplica ISP Monday, November 12, 12
Dependency Inversion Principle Módulos de alto nível não devem depender
de módulos de baixo nível, ambos devem depender de abstrações (interface) Abstrações não devem depender de detalhes , detalhes devem depender de abstrações Monday, November 12, 12
Código muito acoplado Monday, November 12, 12
E se no lugar de salvar no banco de dados
eu quero jogar em um memcache? Monday, November 12, 12
Monday, November 12, 12
Monday, November 12, 12
Monday, November 12, 12
Dúvidas? Monday, November 12, 12
http://www.meetup.com/devinsantos http://twitter.com/guruBaixada https://groups.google.com/forum/?fromgroups#!forum/devinsantos https://groups.google.com/forum/?fromgroups#!forum/guru-baixada Monday, November 12, 12
Obrigado.
[email protected]
@brunoadacosta Bruno Alvares da Costa /brunoadacosta Monday, November
12, 12