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

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
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
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

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.