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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
91
O Básico sobre TDD
brunoadacosta
1
82
Cloud computing
brunoadacosta
3
170
Other Decks in Technology
See All in Technology
Amplify Gen2でbackend.tsにCDKを定義する/しない事によるCDKの挙動の違いとユースケース
smt7174
1
440
Oracle Exadata Database Service on Cloud@Customer X11M (ExaDB-C@C) サービス概要
oracle4engineer
PRO
2
8.4k
AIコード生成×サプライチェーン攻撃 — PHPが直面する“二重の信頼問題
shinyasaita
0
240
AI時代の開発生産性は、個人技からチーム設計へ
moongift
PRO
4
2.4k
DMM.com 購入改善推進チーム におけるCodeRabbitを用いた レビューフロー改善の一例
ysknsid25
2
670
複数プロダクトで進めるAI機能実装 ── 実践から得たリアルな学びとロードマップ実現への挑戦 / AICon2026_yanari
rakus_dev
0
160
人とエージェントが高め合う協業設計
kintotechdev
0
110
ガバナンスの「ちょうどいい落とし所」を探れ!開発スピードを妨げない運用判断の勘所 / SRE NEXT 2026
genda
1
260
タスクの複雑さでモデルを選ぶ ── Thompson Samplingで動かす“トークン/コスト最適化
satohy0323
0
580
“それは自分の仕事じゃない"を越えて行け
yuukiyo
1
490
ファミコンでPHPを動かす / PHP on the Famicom
tomzoh
2
500
最適な自走を最小限の支援で — M&Aで拡大する組織で少人数SREが挑んだ1年 / SRE NEXT 2026
genda
0
1.6k
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
The SEO identity crisis: Don't let AI make you average
varn
0
520
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
2
340
エンジニアに許された特別な時間の終わり
watany
108
250k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Producing Creativity
orderedlist
PRO
348
40k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.6k
Optimising Largest Contentful Paint
csswizardry
37
3.8k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
400
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
Mind Mapping
helmedeiros
PRO
1
290
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
220
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