Clean code

download Clean code

of 17

  • date post

    19-Aug-2014
  • Category

    Engineering

  • view

    414
  • download

    12

Embed Size (px)

description

Clean code

Transcript of Clean code

  • clean_code by @wilq_
  • Bible http://www.amazon.com/Clean-Code-Handbook-Software- Craftsmanship/dp/0132350882
  • Robert C. Martin It is not the language that makes a program look simple, but the programmer who makes the language appear simple
  • 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
  • Productivity vs time
  • 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
  • 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 ...
  • Variables date generationTimestamp ------------------------- date genymdhms private const int WorkDaysPerWeek = 5; for (int i = 0; i < WorkDaysPerWeek; i++) ------------------------- for (int i = 0; i < 5; i++)
  • Classes Noun phrase, e.g. Cusomer, WikiPage, Account, AddressParser Never verb e.g. make, do, prepare etc. http://stackoverow.com/questions/1866794/ naming-classes-how-to-avoid-calling-everything- a-whatevermanager
  • 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.Add(AddPageInfo()); } private string AddPageInfo() ------------------------- private void IncludePageInfo(StringBuilder pageText)
  • 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 ightType, List mandatoryAirlines, List excludedAirlines)
  • Comments Explain yourself //checking is it working day or not if (this.day >= 1 && this.day