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
84
Cloud computing
brunoadacosta
3
170
Other Decks in Technology
See All in Technology
全社に広がるMCPサーバーを、 どう安全に管理するか MCPass開発の舞台裏
mtpooh
3
240
PdMをやめて、 "プロダクトビルダー"という 働き方に変えました / PdM to Product Builder
shikichee
2
620
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
4
25k
多摩川(.dev)ランニング入門 / Tamagawa.dev#3
fujiwara3
2
140
20260903 Tokyo Jazug Night #62 | Azure エンジニアよ、 その環境は本当にセキュアか?
olivia_0707
1
290
プロダクトエンジニアに必要な「いい感じ」に作る能力 〜たくさん作れる時代に、どこまで作るかの決め方〜
jnishime_dresscode
1
190
DINO-EdgeQuery:Edge-First Polygon Decoding for Building Footprint Extraction from Satellite Imagery
lehupa
0
110
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
1.3k
人気商品が「ちゃんと買える」をつくる ー ECの負荷改善
ykagano
1
190
Eight Engineering Unit 紹介資料
sansan33
PRO
3
8.3k
Bet AI Day 2026丨AIによって本質に戻るシステムリスク管理
layerx
PRO
0
580
KAEN Company Deck
kaen
PRO
0
240
Featured
See All Featured
Utilizing Notion as your number one productivity tool
mfonobong
4
560
Optimising Largest Contentful Paint
csswizardry
37
3.9k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
57k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
500
Discover your Explorer Soul
emna__ayadi
2
1.3k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
230
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
Design in an AI World
tapps
1
290
Embracing the Ebb and Flow
colly
88
5.2k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.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