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
実体験から学ぶ分析エージェントの開発と運⽤
recruitengineers
PRO
1
330
SDDの運用にめげずに向き合った話
sansantech
PRO
1
130
転んだ話が背中を預ける理由になる / A_story_about_falling_down_gives_you_a_reason_to_watch_each_other_s_backs.pdf
pauli
3
310
分析の民主化を支えるメタデータ整備の実践
kakehashi
PRO
1
680
DWH の限界突破! AI エージェント向け爆速リアルタイムデータ基盤 ClickHouse
jozono
1
210
子育てエンジニアの可処分時間が減っても成長を諦めない戦い方
sudoakiy
1
1.4k
Meet AgentCore Identity Consent Portal
hironobuiga
3
190
ミイダス株式会社 テックチームのご紹介 / MIIDAS Tech Team
miidas
0
160
Datadog の学び方 - あるいは、オブザーバビリティを学ぶとは何か
mananyuki
1
490
並行性の問題を防げ!実践トランザクション入門
occhi
0
280
IoTデバイスを繋げるプロトコルMatterをAndroidで使用する方法
harutiro
0
120
AIは爆速なのに、私が詰まっていた話 ― 音声入力と鳴くマスコットでボトルネックを削る
yama3133
0
530
Featured
See All Featured
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
580
Paper Plane
katiecoart
PRO
4
54k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
450
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
390
Side Projects
sachag
456
43k
The Cult of Friendly URLs
andyhume
79
7k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
620
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Test your architecture with Archunit
thirion
2
2.4k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
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