Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rubynorte 2011

regedor
March 26, 2012

Rubynorte 2011

Best Practices presentation slides for rubynorte 2011 (http://rubynorte.heroku.com/).

regedor

March 26, 2012
Tweet

More Decks by regedor

Other Decks in Research

Transcript

  1. Tabel of Contents 1 Context/Motivation 2 Assessing Open Source Software

    3 Software Metrics 4 Available Tools 5 Gorgeous Code Plan
  2. Open Source Software Nowadays, Open Source Software is disseminated Open

    Source Projects Android Apache Mozilla Firefox Open Office Ubuntu 4 / 28
  3. Open Source Software Thousands of OSS packages can be found

    online and free to download OSS is not only used by computer specialists 5 / 28
  4. Open Source Software Thousands of OSS packages can be found

    online and free to download OSS is not only used by computer specialists Open Source can be now considered the largest software industry in the world 5 / 28
  5. Open Source Software Thousands of OSS packages can be found

    online and free to download OSS is not only used by computer specialists Open Source can be now considered the largest software industry in the world Measuring the savings that people are making in licence fees, the open source industry is worth 60 billion dollars. 5 / 28
  6. Development Process Open Source communities work in a bazaar style

    Traditional Software Development Process Similar to building cathedrals Few specialized individuals working in isolation Open Source Development Process Chaotic way Resemble a great babbling bazaar. 6 / 28
  7. Quality Can software that is developed in such chaotic way

    be trusted as a high quality product? 7 / 28
  8. Quality Can software that is developed in such chaotic way

    be trusted as a high quality product? The shock is that in fact the bazaar style seemed to work 7 / 28
  9. Quality Can software that is developed in such chaotic way

    be trusted as a high quality product? The shock is that in fact the bazaar style seemed to work However, how can the quality of an open source software project be measured? 7 / 28
  10. Meusuring Open Source Sofware quality A OSSP is built up

    from hundreds, sometimes thousands, of files 8 / 28
  11. Meusuring Open Source Sofware quality A OSSP is built up

    from hundreds, sometimes thousands, of files To analyse manually a software project is a very hard and time consuming task 8 / 28
  12. Meusuring Open Source Sofware quality A OSSP is built up

    from hundreds, sometimes thousands, of files To analyse manually a software project is a very hard and time consuming task With that in mind A system capable of automatically analysing and producing reports would enable users to make better choices, and developers to further improve their software. 8 / 28
  13. Open Source Project Hosting Web Sites Name Established Available VCS

    Users Projects Alexa rank SourceForge 1999 CVS 2,000,000 236,319 136 SVN Bazar GIT Mercurial GitHub 2008 GIT 505,000 1,516,000 742 Google Code 2006 SVN ? 250,000 900 Mercurial Code Plex 2006 SVN 151,782 15.955 2,343 Microsoft TFS Mercurial Assembla 2006 SVN 180,000 60,000 6,628 GIT Launchpad 2005 Bazar 1,140,345 19,016 12,466 BerliOS 2000 CVS 47,285 5,448 17,299 SVN GIT Mercurial Bitbucket 2008 Mercurial 51,600 27,769 12,047 Gitorious 2008 GIT ? 8,336 28,531 9 / 28
  14. Assessing Open Source Software IISO/IEC 912 software quality attributes Functionality

    (meeting of the functional requirements) Reliability (fault tolerance and recoverability) Usability (effort to learn, and operate the software) Efficiency (performance and resource consumption) Maintainability (effort to modify the software) Portability (effort to transfer to another environment) 10 / 28
  15. Software Metrics Lines of Code Cyclomatic Complexity Fan-In and Fan-Out

    Object-Oriented Metrics Coding Standards? 11 / 28
  16. Best Practices Best Practices are not rules but instead best

    practices that are spread through the community and everybody does it that way. Furthermore, best practices discourage: 12 / 28
  17. Best Practices Best Practices are not rules but instead best

    practices that are spread through the community and everybody does it that way. Furthermore, best practices discourage: Poor performance (due to bad patterns) 12 / 28
  18. Best Practices Best Practices are not rules but instead best

    practices that are spread through the community and everybody does it that way. Furthermore, best practices discourage: Poor performance (due to bad patterns) Poor error checking (defensive programming) 12 / 28
  19. Best Practices Best Practices are not rules but instead best

    practices that are spread through the community and everybody does it that way. Furthermore, best practices discourage: Poor performance (due to bad patterns) Poor error checking (defensive programming) Inconsistent exception handling / Maintainability (long-term quality) 12 / 28
  20. Available Tools FindBugs find ”bugs” in Java Programs FxCop reports

    information about the assemblies PMD scans Java source code for potential problems PreFast identifies defects in C/C++ programs RATS finds C/C++, Perl and Python security problems SWAAT scans Java, JSP, ASP .Net and PHP Flawfinder scans C and C++ 14 / 28
  21. Get your hands durty RailsCast #252 where Ryan talks about

    metrics bash gem install metrical metrical bundle rake spec open coverage/index.html gem install rails best practices rails best practices -f html –with-textmate open rails best practices output.html 15 / 28
  22. Plan Gemfile gem ”simplecov”, :require =¿ false, :group =¿ :test

    .metrics MetricFu::Configuration.run do —config— config.metrics -= [:rcov] end 16 / 28
  23. Plan 1. Chose a language: Ruby 2. Select a set

    of projects 3. Find patterns 19 / 28
  24. Plan 1. Chose a language: Ruby 2. Select a set

    of projects 3. Find patterns 4. Create a systematic way to measure it 19 / 28
  25. Someone did the work for me http://www.slideshare.net/ihower/rails-best-practices Works in smilar

    way to a web forum and its objective is to engage developers to discuss which practices should be considered best practices to follow, when building a RoR web application 20 / 28
  26. Someone did the work for me http://www.slideshare.net/ihower/rails-best-practices Works in smilar

    way to a web forum and its objective is to engage developers to discuss which practices should be considered best practices to follow, when building a RoR web application But what is is a best practice after all? 20 / 28
  27. Ruby Best Practices Best practices can be related to code

    formatting: Use two spaces to indent code and no tabs. 21 / 28
  28. Ruby Best Practices Best practices can be related to code

    formatting: Use two spaces to indent code and no tabs. Remove trailing whitespace, trailing whitespace makes noises in version control systems. 21 / 28
  29. Ruby Best Practices Can be related to syntax: Avoid return

    where not required. Suppress superfluous parentheses, when calling methods, but keep them when calling ¨ functions¨ (when you use the return value in the same line). 22 / 28
  30. Ruby Best Practices Can be related to naming: Use snake

    case for methods. Other method naming conventions: Use map over collect, find over detect, find all over select, size over length. 23 / 28
  31. Best practices And can also be specific to a framework,

    rails best practices: Law of Demeter, A model should only talk to its immediate association. 24 / 28
  32. Best practices And can also be specific to a framework,

    rails best practices: Law of Demeter, A model should only talk to its immediate association. Move code into controller, according to MVC architecture, there should not be logic codes in view. 24 / 28
  33. Best practices And can also be specific to a framework,

    rails best practices: Law of Demeter, A model should only talk to its immediate association. Move code into controller, according to MVC architecture, there should not be logic codes in view. Isolate seed data, do not insert seed data during migrations, a rake task can be used instead. 24 / 28
  34. Best practices And can also be specific to a framework,

    rails best practices: Law of Demeter, A model should only talk to its immediate association. Move code into controller, according to MVC architecture, there should not be logic codes in view. Isolate seed data, do not insert seed data during migrations, a rake task can be used instead. Do not use default route, When using a RESTful design. The default RoR routes can cause a security problems. 24 / 28
  35. Best practices And can also be specific to a framework,

    rails best practices: Law of Demeter, A model should only talk to its immediate association. Move code into controller, according to MVC architecture, there should not be logic codes in view. Isolate seed data, do not insert seed data during migrations, a rake task can be used instead. Do not use default route, When using a RESTful design. The default RoR routes can cause a security problems. Replace Complex Creation with Factory Method, Sometimes you will build a complex model with params, current user and other logics in controller, but it makes your controller too big, you should move them into model with a factory method. 24 / 28
  36. Best practices And can also be specific to a framework,

    rails best practices: Law of Demeter, A model should only talk to its immediate association. Move code into controller, according to MVC architecture, there should not be logic codes in view. Isolate seed data, do not insert seed data during migrations, a rake task can be used instead. Do not use default route, When using a RESTful design. The default RoR routes can cause a security problems. Replace Complex Creation with Factory Method, Sometimes you will build a complex model with params, current user and other logics in controller, but it makes your controller too big, you should move them into model with a factory method. 24 / 28
  37. Rails Best Practices Results Rails Best Practices Results Best Practice

    A B C D E F G Always add db index - - - 43 - - 51 Isolate seed data - - - - - 79 17 Law of demeter 20 38 45 6 30 164 85 Move code into cont.. - - - - 2 - 4 Move code into model - 26 - 7 1 3 19 Move model logic in.. - - 76 11 11 98 100 Move finder to name.. - 4 9 2 4 25 - Not use default root - 1 1 - 1 1 1 Remove trailing whi.. 68 57 126 110 330 316 100 Use factory method - 15 9 5 1 8 19 Wrong email content.. - 3 - - - - - Use query attribute - - 11 5 8 29 6 ... ... ... ... ... ... ... ... Total 109 156 402 450 559 834 864 Table: Results obtainned by running the best practices analizer gem on 7 Open Source Project/Time Managment Applications, this data was produced on April, 2011. Rubytime Notes Tracks Handy Ant Retrospectiva Redmine Clockingit
  38. Rails Best Practices Results Rails Best Practices Results Best Practice

    A B C D E F G Total 109 156 402 450 559 834 864 TOTAL trailing whitespace 41 99 276 340 229 518 764 SIZE 12 11 11 29 26 58 31 Total /S 9 14 37 16 23 15 28 Total trailing whitespace /S 3 9 25 12 9 9 25 Table: Results obtainned by running the best practices analizer gem on 7 Open Source Project/Time Managment Applications, this data was produced on April, 2011.