Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Qualidade de código
Search
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
96
O Básico sobre TDD
brunoadacosta
1
86
Cloud computing
brunoadacosta
3
170
Other Decks in Technology
See All in Technology
More Freedom on the Same Shared GPU Cluster: A Small Team’s Experience with vCluster
nttcom
0
140
全PRの83%が AIレビューだけでマージできるようになった開発組織は その後どうなったか @2026/10
athug
0
130
"優秀な誰か"の下位互換にならないために
yut0naga1_fa
0
1.4k
生成AIと進める探索的データ分析(2026.10.03 第122回Tokyo.R勉強会)
tatamiya
2
1.5k
オンラインゲームのシステム全体像 - コロプラ 2026年度 新卒研修
colopl
0
1.1k
AIに攻撃される前に、AIに攻撃させる
tsuchikazu
0
170
大型犬好きによるPugの紹介
yamanoku
1
100
DevelopersIO 2026 知識の地図を描く ─ オントロジーとは何か?
ishikawa_satoru
1
1.3k
味覇で作るパスタが美味い - 20261001_yabaubuki.dev
livesense
PRO
0
120
AI時代だからこそ推したい!Gitコマンド再入門
munakata
0
170
実践! SRE × AI - ABEMA における AIOps -
tetsuya28
7
2.7k
Cognition AI Japan - ウェビナー2_テストQA_運用監視
cogakira
0
120
Featured
See All Featured
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
490
The Pragmatic Product Professional
lauravandoore
37
7.5k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
740
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
620
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
470
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.2k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
530
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
620
Building a Scalable Design System with Sketch
lauravandoore
464
34k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Typedesign – Prime Four
hannesfritz
42
3.2k
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