SlideShare a Scribd company logo
1 of 27
@martincronje Solutions Architect and Agile Coach www.metagen.co.za 10 ways to make your code rock TRACK: COMMUNITY SESSIONS
rule[0]; its not about the cool tech its about fundamentals
rule[1]; “switch” and “if” are evil structure vs. behaviour
publicvoidGeneratePayslip(Employee employee) { var salary = CalculateGrossSalary(employee); // do some other stuff } publicdecimalCalculateGrossSalary(Employee employee) { switch (employee.Type)    { caseEmployeeType.Permanent: if (DateTime.Today.Month == Calendar.YearEnd) // bonus month returnemployee.BaseSalary + (employee.PerformanceRating*employee.Bonus);         else           returnemployee.BaseSalary; caseEmployeeType.Contractor: returnemployee.HourlyRate * employee.TimeSheet.TotalHoursWorked; default: thrownewArgumentOutOfRangeException();    } }
publicabstractclassEmployee {     publicabstractdecimalCalculateGrossSalary(); } publicclassContractor : Employee { publicoverridedecimalCalculateGrossSalary()     { returnHourlyRate * TimeSheet.TotalHoursWorked;     } // properties and stuff } publicclassPermanent : Employee { publicoverridedecimalCalculateGrossSalary()     { if (DateTime.Today.Month == Calendar.YearEnd) // bonus month returnBaseSalary + (PerformanceRating * Bonus); returnBaseSalary;     } // properties and stuff }
publicvoidGeneratePayslip(Employee employee) { var salary = employee.CalculateGrossSalary(); // do some other stuff }
rule[2]; comments are bad… mostly bad code needs explanation
publicclassSomeClass { ///<summary> /// Returns a boolean to indicate whether a class is /// in read-only mode or not. ///</summary> publicboolReadOnly { get; set; } }
///<summary> /// Helper class to find the shorted path within the graph from one point to  /// another. ///</summary> publicclassShortestPath { ///<summary> /// Find the shortest path within the graph from one point to another. /// This method makes used of Dijkstra's algorithm to find the path. ///</summary> ///<param name="point1">GraphNode representing the starting point</param> ///<param name="point2">GraphNode representing the end point</param> ///<returns>The shortest path between two points.</returns> publicStack Calculate(GraphNode point1, GraphNode point2)     { // do stuff     } }
///<summary> /// Non-recursive implementation of Dijkstra’s shortest path. This class is /// not thread-safe. (Ref: http://en.wikipedia.org/wiki/Dijkstra's_algorithm) ///</summary> publicclassDijsktraShortestPath : IShortestPath { publicStack Find(GraphNodestartNode, GraphNodeendNode)     { // do stuff     } }
publicclassUserManagement { publicvoid Register(UserProfile profile)     { // Throw exception if the user exists if (_repository.Load(profile.ClaimIdentifier) != null)         { thrownewUserAlreadyExistsException(profile);         }         _repository.Store(profile);     } // other stuff }
publicclassUserManagement { publicvoid Register(UserProfile profile)     {         if (UserExists(profile))         { thrownewUserAlreadyExistsException(profile);         }         _repository.Store(profile);     } privateboolUserExists(UserProfile profile)     { return _repository.Load(profile.ClaimIdentifier) != null;     } // other stuff }
rule[3]; understandability 4 line rule
rule[4]; don’t repeat yourself don’t repeat yourself
rule[5]; code reviews never happen static code analysis / pair programming
rule[6]; don’t underestimate the power of TDD young Skywalker
rule[7]; use frameworks don’t build them
It looks like you are writing a framework. What do you want to do? Delete all code Looks for something online Find a new job Neal Ford – 10 ways to improve your code
rule[8]; premature optimisation is the root of all evil
rule[9]; understand quality …and purpose
Software is an asset!
Overview “97 Things Every Programmer Should Know”,O'Reilly Media Robert C. Martin, “Clean Code - A Handbook of Agile Software Craftsmanship”, Prentice Hall Martin Fowler, “Refactoring-Improving The Design Of Existing Code”, Addison-Wesley Steve McConnell, “Code Complete - A Practical Handbook Of Software Construction”, Microsoft Press Krzysztof Cwalina, Brad Abrams, “Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries”, Addison-Wesley(http://msdn.microsoft.com/en-us/library/ms229042.aspx)
Keep in Touch facebook.com/msdevsa @msdevsa http://blogs.msdn.com/southafrica
Don’t forget the Kinect show- down after sessions this evening!
DevDays 2011 Sponsors PLATINUM SPONSOR www.bbd.co.za SILVER SPONSOR www.dvt.co.za SILVER SPONSOR www.ctutraining.co.za
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation.  Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation.  MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

More Related Content

Viewers also liked

150921 UBS workshop - Taking control of your career with ME+®
150921 UBS workshop - Taking control of your career with ME+®150921 UBS workshop - Taking control of your career with ME+®
150921 UBS workshop - Taking control of your career with ME+®ME+
 
2012 GMC Sierra 3500HD For Sale Near Howell NJ
2012 GMC Sierra 3500HD For Sale Near Howell NJ2012 GMC Sierra 3500HD For Sale Near Howell NJ
2012 GMC Sierra 3500HD For Sale Near Howell NJJim Curley Buick GMC Kia
 
TCM- SH Reference, Ingrid
TCM- SH Reference, IngridTCM- SH Reference, Ingrid
TCM- SH Reference, IngridBrenton Harvey
 
Chapter 13
Chapter 13Chapter 13
Chapter 13mcfalltj
 
2012 GMC Sierra 3500HD For Sale Near Jackson NJ
2012 GMC Sierra 3500HD For Sale Near Jackson NJ2012 GMC Sierra 3500HD For Sale Near Jackson NJ
2012 GMC Sierra 3500HD For Sale Near Jackson NJJim Curley Buick GMC Kia
 
Software Freedom Day Adverte: Softwares Nao Livres podem ser prejudiciais a s...
Software Freedom Day Adverte: Softwares Nao Livres podem ser prejudiciais a s...Software Freedom Day Adverte: Softwares Nao Livres podem ser prejudiciais a s...
Software Freedom Day Adverte: Softwares Nao Livres podem ser prejudiciais a s...PotiLivre Sobrenome
 
Exercise can improve the quality of life of mesothelioma patients
Exercise can improve the quality of life of mesothelioma patientsExercise can improve the quality of life of mesothelioma patients
Exercise can improve the quality of life of mesothelioma patientsTanzil Al Gazmir
 
Chapter 16
Chapter 16Chapter 16
Chapter 16mcfalltj
 
阪大理系体育会就活イベント案内資料
阪大理系体育会就活イベント案内資料阪大理系体育会就活イベント案内資料
阪大理系体育会就活イベント案内資料gakusei_sien
 
DOCUMENTOS FIFA - 11 - EL ENTRENAMIENTO DEL PORTERO
DOCUMENTOS FIFA - 11 - EL ENTRENAMIENTO DEL PORTERODOCUMENTOS FIFA - 11 - EL ENTRENAMIENTO DEL PORTERO
DOCUMENTOS FIFA - 11 - EL ENTRENAMIENTO DEL PORTERODiego Menino
 
Slide minggu 1-PERKEMBANGAN PENDIDIKAN ZAMAN RASULULLAH
Slide minggu 1-PERKEMBANGAN PENDIDIKAN ZAMAN RASULULLAHSlide minggu 1-PERKEMBANGAN PENDIDIKAN ZAMAN RASULULLAH
Slide minggu 1-PERKEMBANGAN PENDIDIKAN ZAMAN RASULULLAHFarra Shahirra
 
Falsafah Pendidikan Awal Kanak-Kanak
Falsafah Pendidikan Awal Kanak-KanakFalsafah Pendidikan Awal Kanak-Kanak
Falsafah Pendidikan Awal Kanak-KanakAntasha Kamaruzzaman
 
KURIKULUM PENDIDIKAN
KURIKULUM PENDIDIKANKURIKULUM PENDIDIKAN
KURIKULUM PENDIDIKANsafyah
 
Writing ws day3
Writing ws day3Writing ws day3
Writing ws day3Jon Gulley
 

Viewers also liked (18)

150921 UBS workshop - Taking control of your career with ME+®
150921 UBS workshop - Taking control of your career with ME+®150921 UBS workshop - Taking control of your career with ME+®
150921 UBS workshop - Taking control of your career with ME+®
 
Coparticipación setiembre-2015
Coparticipación setiembre-2015Coparticipación setiembre-2015
Coparticipación setiembre-2015
 
2012 GMC Sierra 3500HD For Sale Near Howell NJ
2012 GMC Sierra 3500HD For Sale Near Howell NJ2012 GMC Sierra 3500HD For Sale Near Howell NJ
2012 GMC Sierra 3500HD For Sale Near Howell NJ
 
TCM- SH Reference, Ingrid
TCM- SH Reference, IngridTCM- SH Reference, Ingrid
TCM- SH Reference, Ingrid
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
2012 GMC Sierra 3500HD For Sale Near Jackson NJ
2012 GMC Sierra 3500HD For Sale Near Jackson NJ2012 GMC Sierra 3500HD For Sale Near Jackson NJ
2012 GMC Sierra 3500HD For Sale Near Jackson NJ
 
Taller arduino uno
Taller arduino unoTaller arduino uno
Taller arduino uno
 
Software Freedom Day Adverte: Softwares Nao Livres podem ser prejudiciais a s...
Software Freedom Day Adverte: Softwares Nao Livres podem ser prejudiciais a s...Software Freedom Day Adverte: Softwares Nao Livres podem ser prejudiciais a s...
Software Freedom Day Adverte: Softwares Nao Livres podem ser prejudiciais a s...
 
บทที่ 2 สารสนเทศชุมชน pb
บทที่ 2 สารสนเทศชุมชน pbบทที่ 2 สารสนเทศชุมชน pb
บทที่ 2 สารสนเทศชุมชน pb
 
Exercise can improve the quality of life of mesothelioma patients
Exercise can improve the quality of life of mesothelioma patientsExercise can improve the quality of life of mesothelioma patients
Exercise can improve the quality of life of mesothelioma patients
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
 
阪大理系体育会就活イベント案内資料
阪大理系体育会就活イベント案内資料阪大理系体育会就活イベント案内資料
阪大理系体育会就活イベント案内資料
 
DOCUMENTOS FIFA - 11 - EL ENTRENAMIENTO DEL PORTERO
DOCUMENTOS FIFA - 11 - EL ENTRENAMIENTO DEL PORTERODOCUMENTOS FIFA - 11 - EL ENTRENAMIENTO DEL PORTERO
DOCUMENTOS FIFA - 11 - EL ENTRENAMIENTO DEL PORTERO
 
Slide minggu 1-PERKEMBANGAN PENDIDIKAN ZAMAN RASULULLAH
Slide minggu 1-PERKEMBANGAN PENDIDIKAN ZAMAN RASULULLAHSlide minggu 1-PERKEMBANGAN PENDIDIKAN ZAMAN RASULULLAH
Slide minggu 1-PERKEMBANGAN PENDIDIKAN ZAMAN RASULULLAH
 
Falsafah Pendidikan Awal Kanak-Kanak
Falsafah Pendidikan Awal Kanak-KanakFalsafah Pendidikan Awal Kanak-Kanak
Falsafah Pendidikan Awal Kanak-Kanak
 
KURIKULUM PENDIDIKAN
KURIKULUM PENDIDIKANKURIKULUM PENDIDIKAN
KURIKULUM PENDIDIKAN
 
Writing ws day3
Writing ws day3Writing ws day3
Writing ws day3
 
7. Por qué leer a los clásicos
7. Por qué leer a los clásicos7. Por qué leer a los clásicos
7. Por qué leer a los clásicos
 

Similar to 10 ways to make your code rock

HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)Jose Manuel Pereira Garcia
 
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023Nicolas HAAN
 
AFUP Lorraine - Symfony Webpack Encore
AFUP Lorraine - Symfony Webpack EncoreAFUP Lorraine - Symfony Webpack Encore
AFUP Lorraine - Symfony Webpack EncoreEngineor
 
He stopped using for/while loops, you won't believe what happened next!
He stopped using for/while loops, you won't believe what happened next!He stopped using for/while loops, you won't believe what happened next!
He stopped using for/while loops, you won't believe what happened next!François-Guillaume Ribreau
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Strut2-Spring-Hibernate
Strut2-Spring-HibernateStrut2-Spring-Hibernate
Strut2-Spring-HibernateJay Shah
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0Russell Jurney
 
Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​ Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​ Luciano Mammino
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiRan Mizrahi
 
Kerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-Malla
Kerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-MallaKerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-Malla
Kerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-MallaSpark Summit
 
Multilingualism makes better programmers
Multilingualism makes better programmersMultilingualism makes better programmers
Multilingualism makes better programmersAlexander Varwijk
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0Russell Jurney
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For ManagersAgileThought
 
Relevance trilogy may dream be with you! (dec17)
Relevance trilogy  may dream be with you! (dec17)Relevance trilogy  may dream be with you! (dec17)
Relevance trilogy may dream be with you! (dec17)Woonsan Ko
 
Introduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceIntroduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceBo-Yi Wu
 

Similar to 10 ways to make your code rock (20)

Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
 
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023
Comment développer une application mobile en 8 semaines - Meetup PAUG 24-01-2023
 
AFUP Lorraine - Symfony Webpack Encore
AFUP Lorraine - Symfony Webpack EncoreAFUP Lorraine - Symfony Webpack Encore
AFUP Lorraine - Symfony Webpack Encore
 
He stopped using for/while loops, you won't believe what happened next!
He stopped using for/while loops, you won't believe what happened next!He stopped using for/while loops, you won't believe what happened next!
He stopped using for/while loops, you won't believe what happened next!
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Strut2-Spring-Hibernate
Strut2-Spring-HibernateStrut2-Spring-Hibernate
Strut2-Spring-Hibernate
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0
 
Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​ Middy.js - A powerful Node.js middleware framework for your lambdas​
Middy.js - A powerful Node.js middleware framework for your lambdas​
 
Agile Data Science
Agile Data ScienceAgile Data Science
Agile Data Science
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran Mizrahi
 
Clean Architecture @ Taxibeat
Clean Architecture @ TaxibeatClean Architecture @ Taxibeat
Clean Architecture @ Taxibeat
 
Kerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-Malla
Kerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-MallaKerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-Malla
Kerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-Malla
 
Multilingualism makes better programmers
Multilingualism makes better programmersMultilingualism makes better programmers
Multilingualism makes better programmers
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For Managers
 
Relevance trilogy may dream be with you! (dec17)
Relevance trilogy  may dream be with you! (dec17)Relevance trilogy  may dream be with you! (dec17)
Relevance trilogy may dream be with you! (dec17)
 
Introduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceIntroduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript Conference
 

Recently uploaded

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

10 ways to make your code rock

  • 1.
  • 2. @martincronje Solutions Architect and Agile Coach www.metagen.co.za 10 ways to make your code rock TRACK: COMMUNITY SESSIONS
  • 3. rule[0]; its not about the cool tech its about fundamentals
  • 4. rule[1]; “switch” and “if” are evil structure vs. behaviour
  • 5. publicvoidGeneratePayslip(Employee employee) { var salary = CalculateGrossSalary(employee); // do some other stuff } publicdecimalCalculateGrossSalary(Employee employee) { switch (employee.Type) { caseEmployeeType.Permanent: if (DateTime.Today.Month == Calendar.YearEnd) // bonus month returnemployee.BaseSalary + (employee.PerformanceRating*employee.Bonus); else returnemployee.BaseSalary; caseEmployeeType.Contractor: returnemployee.HourlyRate * employee.TimeSheet.TotalHoursWorked; default: thrownewArgumentOutOfRangeException(); } }
  • 6. publicabstractclassEmployee { publicabstractdecimalCalculateGrossSalary(); } publicclassContractor : Employee { publicoverridedecimalCalculateGrossSalary() { returnHourlyRate * TimeSheet.TotalHoursWorked; } // properties and stuff } publicclassPermanent : Employee { publicoverridedecimalCalculateGrossSalary() { if (DateTime.Today.Month == Calendar.YearEnd) // bonus month returnBaseSalary + (PerformanceRating * Bonus); returnBaseSalary; } // properties and stuff }
  • 7. publicvoidGeneratePayslip(Employee employee) { var salary = employee.CalculateGrossSalary(); // do some other stuff }
  • 8. rule[2]; comments are bad… mostly bad code needs explanation
  • 9. publicclassSomeClass { ///<summary> /// Returns a boolean to indicate whether a class is /// in read-only mode or not. ///</summary> publicboolReadOnly { get; set; } }
  • 10. ///<summary> /// Helper class to find the shorted path within the graph from one point to /// another. ///</summary> publicclassShortestPath { ///<summary> /// Find the shortest path within the graph from one point to another. /// This method makes used of Dijkstra's algorithm to find the path. ///</summary> ///<param name="point1">GraphNode representing the starting point</param> ///<param name="point2">GraphNode representing the end point</param> ///<returns>The shortest path between two points.</returns> publicStack Calculate(GraphNode point1, GraphNode point2) { // do stuff } }
  • 11. ///<summary> /// Non-recursive implementation of Dijkstra’s shortest path. This class is /// not thread-safe. (Ref: http://en.wikipedia.org/wiki/Dijkstra's_algorithm) ///</summary> publicclassDijsktraShortestPath : IShortestPath { publicStack Find(GraphNodestartNode, GraphNodeendNode) { // do stuff } }
  • 12. publicclassUserManagement { publicvoid Register(UserProfile profile) { // Throw exception if the user exists if (_repository.Load(profile.ClaimIdentifier) != null) { thrownewUserAlreadyExistsException(profile); } _repository.Store(profile); } // other stuff }
  • 13. publicclassUserManagement { publicvoid Register(UserProfile profile) { if (UserExists(profile)) { thrownewUserAlreadyExistsException(profile); } _repository.Store(profile); } privateboolUserExists(UserProfile profile) { return _repository.Load(profile.ClaimIdentifier) != null; } // other stuff }
  • 15. rule[4]; don’t repeat yourself don’t repeat yourself
  • 16. rule[5]; code reviews never happen static code analysis / pair programming
  • 17. rule[6]; don’t underestimate the power of TDD young Skywalker
  • 18. rule[7]; use frameworks don’t build them
  • 19. It looks like you are writing a framework. What do you want to do? Delete all code Looks for something online Find a new job Neal Ford – 10 ways to improve your code
  • 20. rule[8]; premature optimisation is the root of all evil
  • 21. rule[9]; understand quality …and purpose
  • 22. Software is an asset!
  • 23. Overview “97 Things Every Programmer Should Know”,O'Reilly Media Robert C. Martin, “Clean Code - A Handbook of Agile Software Craftsmanship”, Prentice Hall Martin Fowler, “Refactoring-Improving The Design Of Existing Code”, Addison-Wesley Steve McConnell, “Code Complete - A Practical Handbook Of Software Construction”, Microsoft Press Krzysztof Cwalina, Brad Abrams, “Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries”, Addison-Wesley(http://msdn.microsoft.com/en-us/library/ms229042.aspx)
  • 24. Keep in Touch facebook.com/msdevsa @msdevsa http://blogs.msdn.com/southafrica
  • 25. Don’t forget the Kinect show- down after sessions this evening!
  • 26. DevDays 2011 Sponsors PLATINUM SPONSOR www.bbd.co.za SILVER SPONSOR www.dvt.co.za SILVER SPONSOR www.ctutraining.co.za
  • 27. © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.