clean_code 
by @wilq_
Bible 
http://www.amazon.com/Clean-Code-Handbook-Software- 
Craftsmanship/dp/0132350882
“It is not the language that makes a program 
look simple, but the programmer who makes 
the language appear simple” 
–Rob...
What is clean code? 
• Bad code does too much – Clean code is focused 
• The language you wrote your code with should look...
Productivity vs time
Coding Style 
• http://blog.arkency.com/2014/07/code-style-matters/ 
• https://github.com/bbatsov/ruby-style-guide 
ex. Us...
Variables 
• int day 
------------------------- 
int d 
• int elapsedTimeInDays 
------------------------- 
int elapsed 
•...
Variables 
• date generationTimestamp 
------------------------- 
date genymdhms 
• private const int WorkDaysPerWeek = 5;...
Classes 
• Noun phrase, e.g. Cusomer, WikiPage, Account, 
AddressParser 
• Never verb e.g. make, do, prepare etc. 
• http:...
Functions 
• The Stepdown Rule 
• Flags 
e.g. private void AddPageInfo(string title, bool 
add)
Functions 
• Niladic 
• Monadic 
private void BuildPageText() { 
StringBuilder pageInfo = new StringBuilder(); 
pageInfo.A...
Functions 
• Dyadic 
• Triadic 
• Polyadic 
public Availability(string contract, string languageCode, string 
depTLC, int ...
Comments 
• Explain yourself 
//checking is it working day or not 
if (this.day >= 1 && this.day <= 5) 
------------------...
Train Wrecks 
• string outputDir = 
ctxt.GetOptions().GetScratchDir().GetAbsoluteP 
ath(); 
------------------------- 
Opt...
Sources 
• http://blog.goyello.com/2013/01/21/top-9- 
principles-clean-code/ 
• http://technocracy.anixe.pl/2009/06/24/ 
s...
Images 
• http://blog.claudiupersoiu.ro/wp-content/ 
uploads/2011/08/DSC_3540_2.jpg 
• http://javastart.pl/wp-content/uplo...
Thank you
Upcoming SlideShare
Loading in …5
×

Clean code

737 views
631 views

Published on

Clean code

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
737
On SlideShare
0
From Embeds
0
Number of Embeds
24
Actions
Shares
0
Downloads
1
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Clean code

  1. 1. clean_code by @wilq_
  2. 2. Bible http://www.amazon.com/Clean-Code-Handbook-Software- Craftsmanship/dp/0132350882
  3. 3. “It is not the language that makes a program look simple, but the programmer who makes the language appear simple” –Robert C. Martin
  4. 4. What is clean code? • Bad code does too much – Clean code is focused • The language you wrote your code with should look like it was made for the problem • It should not be redundant • Reading your code should be pleasant • Can be easily extended by any other developer • It should have minimal dependencies • Smaller is better • It should have unit and acceptance tests • It should be expressive
  5. 5. Productivity vs time
  6. 6. Coding Style • http://blog.arkency.com/2014/07/code-style-matters/ • https://github.com/bbatsov/ruby-style-guide ex. Use two spaces per indentation level (aka soft tabs). No hard tabs. • http://google-styleguide.googlecode.com/svn/ trunk/javaguide.html
  7. 7. Variables • int day ------------------------- int d • int elapsedTimeInDays ------------------------- int elapsed • public static void Copy(string source, string destination) ------------------------- public static void Copy(string a, string b) • exception: i, j, k ...
  8. 8. Variables • date generationTimestamp ------------------------- date genymdhms • private const int WorkDaysPerWeek = 5; for (int i = 0; i < WorkDaysPerWeek; i++) ------------------------- for (int i = 0; i < 5; i++)
  9. 9. Classes • Noun phrase, e.g. Cusomer, WikiPage, Account, AddressParser • Never verb e.g. make, do, prepare etc. • http://stackoverflow.com/questions/1866794/ naming-classes-how-to-avoid-calling-everything-a- whatevermanager
  10. 10. Functions • The Stepdown Rule • Flags e.g. private void AddPageInfo(string title, bool add)
  11. 11. Functions • Niladic • Monadic private void BuildPageText() { StringBuilder pageInfo = new StringBuilder(); pageInfo.Add(AddPageInfo()); } private string AddPageInfo() ------------------------- private void IncludePageInfo(StringBuilder pageText)
  12. 12. Functions • Dyadic • Triadic • Polyadic public Availability(string contract, string languageCode, string depTLC, int depRadius, string arrTLC, int arrRadius, string isoDepDate, int depOffsetBefore, int depOffsetAfter, string isoRetDate, int retOffsetBefore, int retOffsetAfter, string isoDepTime, string isoRetTime, string cabinClass, int ADTCount, int CHDCount, int INFCount, int INSCount, int SRCCount, int STUCount, int YTHCount, EasyTravel.Serialization.Objects.Air.FlightType flightType, List<EasyTravel.Serialization.Objects.Air.Airline> mandatoryAirlines, List<EasyTravel.Serialization.Objects.Air.Airline> excludedAirlines)
  13. 13. Comments • Explain yourself //checking is it working day or not if (this.day >= 1 && this.day <= 5) ------------------------- IsWorkingDay()
  14. 14. Train Wrecks • string outputDir = ctxt.GetOptions().GetScratchDir().GetAbsoluteP ath(); ------------------------- Options option = ctxt.GetOptions(); FileStream fileStream = option.GetScratchDir(); string outputDir = fileStream.GetAbsolutePath();
  15. 15. Sources • http://blog.goyello.com/2013/01/21/top-9- principles-clean-code/ • http://technocracy.anixe.pl/2009/06/24/ szkolenie-technocracy-vi-clean-code/
  16. 16. Images • http://blog.claudiupersoiu.ro/wp-content/ uploads/2011/08/DSC_3540_2.jpg • http://javastart.pl/wp-content/uploads/2013/12/ cleancode1.jpg
  17. 17. Thank you

×