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

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
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
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Recently uploaded (20)

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
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
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

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.