SlideShare a Scribd company logo
High-Quality Programming Code
Code Correctness, Readability,
Maintainability
Svetlin Nakov
Technical Trainer
www.nakov.com
Software University
http://softuni.bg
2
ο‚§ Why Quality Is Important?
ο‚§ Software Quality: External and Internal
ο‚§ What is High-Quality Code?
ο‚§ Code Conventions
ο‚§ Managing Complexity
ο‚§ Characteristics of Quality Code
Table of Contents
What is High-Quality
Programming Code?
4
ο‚§ What does this code do? Is it correct?
Why Quality Is Important?
static void Main()
{
int value=010, i=5, w;
switch(value){case 10:w=5;Console.WriteLine(w);break;case
9:i=0;break;
case 8:Console.WriteLine("8 ");break;
default:Console.WriteLine("def ");{
Console.WriteLine("hoho "); }
for (int k = 0; k < i; k++, Console.WriteLine(k - 'f'));break;}
{ Console.WriteLine("loop!"); }
}
5
ο‚§ Now the code is formatted, but is still unclear.
Why Quality Is Important? (2)
static void Main()
{
int value = 010, i = 5, w;
switch (value)
{
case 10: w = 5; Console.WriteLine(w); break;
case 9: i = 0; break;
case 8: Console.WriteLine("8 "); break;
default:
Console.WriteLine("def ");
Console.WriteLine("hoho ");
for (int k = 0; k < i; k++,
Console.WriteLine(k - 'f')) ;
break;
}
Console.WriteLine("loop!");
}
6
ο‚§ External quality
ο‚§ Does the software behave correctly?
ο‚§ Are the produced results correct?
ο‚§ Does the software run fast?
ο‚§ Is the software UI easy-to-use?
ο‚§ Is the code secure enough?
ο‚§ Internal quality
ο‚§ Is the code easy to read and understand?
ο‚§ Is the code well structured?
ο‚§ Is the code easy to modify?
Software Quality
7
ο‚§ High-quality programming code:
ο‚§ Easy to read and understand
ο‚§ Easy to modify and maintain
ο‚§ Correct behavior in all cases
ο‚§ Well tested
ο‚§ Well architectured and designed
ο‚§ Well documented
ο‚§ Self-documenting code
ο‚§ Well formatted
What is High-Quality Programming Code?
8
ο‚§ High-quality programming code:
ο‚§ Strong cohesion at all levels: modules, classes, methods, etc.
ο‚§ Single unit is responsible for single task
ο‚§ Loose coupling between modules, classes, methods, etc.
ο‚§ Units are independent one of another
ο‚§ Good formatting
ο‚§ Good names for classes, methods, variables, etc.
ο‚§ Self-documenting code style
What is High-Quality Programming Code? (2)
Code Conventions
10
ο‚§ Code conventions are formal guidelines about the style of the source
code:
ο‚§ Code formatting conventions
ο‚§ Indentation, whitespace, etc.
ο‚§ Naming conventions
ο‚§ PascalCase or camelCase, prefixes, suffixes, etc.
ο‚§ Best practices
ο‚§ Classes, interfaces, enumerations, structures, inheritance,
exceptions, properties, events, constructors, fields, operators, etc.
Code Conventions
11
ο‚§ Microsoft official C# code conventions
ο‚§ Design Guidelines for Developing Class Libraries:
http://msdn.microsoft.com/en-us/library/ms229042.aspx
ο‚§ Java official code conventions
ο‚§ http://www.oracle.com/technetwork/java/codeconvtoc-136057.html
ο‚§ Semi-official JavaScript code conventions
ο‚§ http://javascript.crockford.com/code.html,
http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
ο‚§ Semi-official PHP conventions
ο‚§ http://www.php-fig.org/psr/psr-1/
Code Conventions (2)
Managing Complexity
13
ο‚§ Managing complexity has central role in software construction
ο‚§ Minimize the amount of complexity that anyone’s brain has to deal with at
certain time
ο‚§ Architecture and design challenges
ο‚§ Design modules and classes to reduce complexity
ο‚§ Code construction challenges
ο‚§ Apply good software construction practices: classes, methods, variables,
naming, statements, error handling, formatting, comments, etc.
Managing Complexity
14
ο‚§ Key to being an effective programmer:
ο‚§ Maximizing the portion of a program that you can safely ignore
ο‚§ While working on any one section of code
ο‚§ Most practices discussed later propose ways to achieve this
important goal
Managing Complexity (2)
Code Quality: Characteristics
16
ο‚§ Correct behavior
ο‚§ Conforming to the requirements
ο‚§ Stable, no hangs, no crashes
ο‚§ Bug free – works as expected
ο‚§ Correct response to incorrect usage
ο‚§ Readable – easy to read
ο‚§ Understandable – self-documenting
ο‚§ Maintainable – easy to modify when required
Key Characteristics of High-Quality Code
17
ο‚§ Good identifiers names
ο‚§ Good names for variables, constants, methods, parameters,
classes, structures, fields, properties, interfaces, structures,
enumerations, namespaces,
ο‚§ High-quality classes, interfaces and class hierarchies
ο‚§ Good abstraction and encapsulation
ο‚§ Simplicity, reusability, minimal complexity
ο‚§ Strong cohesion, loose coupling
Key Characteristics of High-Quality Code (2)
18
ο‚§ High-quality methods
ο‚§ Reduced complexity, improved readability
ο‚§ Good method names and parameter names
ο‚§ Strong cohesion, loose coupling
ο‚§ Variables, data, expressions and constants
ο‚§ Minimal variable scope, span, live time
ο‚§ Simple expressions
ο‚§ Correctly used constants
ο‚§ Correctly organized data
Key Characteristics of High-Quality Code (3)
19
ο‚§ Correctly used control structures
ο‚§ Simple statements
ο‚§ Simple conditional statements and simple conditions
ο‚§ Well organized loops without deep nesting
ο‚§ Good code formatting
ο‚§ Reflecting the logical structure of the program
ο‚§ Good formatting of classes, methods, blocks, whitespace, long
lines, alignment, etc.
Key Characteristics of High-Quality Code (4)
20
ο‚§ High-quality documentation and comments
ο‚§ Effective comments
ο‚§ Self-documenting code
ο‚§ Defensive programming and exceptions
ο‚§ Ubiquitous use of defensive programming
ο‚§ Well organized exception handling
ο‚§ Code tuning and optimization
ο‚§ Quality code instead of good performance
ο‚§ Code performance when required
Key Characteristics of High-Quality Code (5)
21
ο‚§ Following the corporate code conventions
ο‚§ Formatting and style, naming, etc.
ο‚§ Domain-specific best practices
ο‚§ Well tested and reviewed
ο‚§ Testable code
ο‚§ Well designed unit tests
ο‚§ Tests for all scenarios
ο‚§ High code coverage
ο‚§ Passed code reviews and inspections
Key Characteristics of High-Quality Code (6)
22
1. Classes define specific structure for objects
ο‚§ Objects are particular instances of a class
2. Classes define fields, methods, constructors,
3. properties and other members
ο‚§ Access modifiers limit the access to class members
4. Constructors are invoked when creating new class instances and
initialize the object's internal state
5. Properties expose the class data in safe, controlled way
Summary
?
https://softuni.bg/courses/high-quality-code/
High-Quality Programming Code
License
ο‚§ This course (slides, examples, demos, videos, homework, etc.)
is licensed under the "Creative Commons Attribution-
NonCommercial-ShareAlike 4.0 International" license
24
ο‚§ Attribution: this work may contain portions from
ο‚§ "High Quality Code" course by Telerik Academy under CC-BY-NC-SA license
Free Trainings @ Software University
ο‚§ Software University Foundation – softuni.org
ο‚§ Software University – High-Quality Education,
Profession and Job for Software Developers
ο‚§ softuni.bg
ο‚§ Software University @ Facebook
ο‚§ facebook.com/SoftwareUniversity
ο‚§ Software University @ YouTube
ο‚§ youtube.com/SoftwareUniversity
ο‚§ Software University Forums – forum.softuni.bg

More Related Content

PPTX
21. Java High Quality Programming Code
PPT
0. Course Introduction
PDF
Object oriented-programming-in-c-sharp
Β 
PPT
Introduction to c_sharp
PPTX
Introduction To C#
PDF
C# c# for beginners crash course master c# programming fast and easy today
PPTX
Selenium online training
PPT
C#.NET
21. Java High Quality Programming Code
0. Course Introduction
Object oriented-programming-in-c-sharp
Β 
Introduction to c_sharp
Introduction To C#
C# c# for beginners crash course master c# programming fast and easy today
Selenium online training
C#.NET

What's hot (17)

PPTX
.NET and C# introduction
PPTX
Java vs python
PPTX
Introduction to c#
PPT
Programming in c#
PPT
c#.Net Windows application
Β 
PPT
Nakov - .NET Framework Overview - English
PPTX
Introduction to vb.net
PPTX
01 intro to programming in .net
PPTX
C# programming language
PPTX
.Net language support
PPTX
Introduction of .net framework
PPTX
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
PPTX
Java v/s .NET - Which is Better?
PPT
Lecture 10 software development
PPT
Java for C++ programers
PDF
Delphi developer certification study guide
PPTX
Introduction to .NET Framework and C# (English)
.NET and C# introduction
Java vs python
Introduction to c#
Programming in c#
c#.Net Windows application
Β 
Nakov - .NET Framework Overview - English
Introduction to vb.net
01 intro to programming in .net
C# programming language
.Net language support
Introduction of .net framework
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
Java v/s .NET - Which is Better?
Lecture 10 software development
Java for C++ programers
Delphi developer certification study guide
Introduction to .NET Framework and C# (English)
Ad

Similar to 21. High-Quality Programming Code (20)

PPTX
Writing High Quality Code in C#
PPTX
Code review
PDF
SE2018_Lec 17_ Coding
PPT
Best practices in enterprise applications
PPTX
Improving Code Quality Through Effective Review Process
PDF
SE2_Lec 18_ Coding
PDF
Clean Infrastructure as Code
PDF
Top 50 .NET Interview Questions and Answers 2019 | Edureka
PPTX
.NET Fundamentals and Business Application Development
PDF
How to do code review and use analysis tool in software development
PPTX
presentation slides of Week 3 for 1st.pptx
PPT
Rhapsody Software
PPTX
PPT
Comparing the code quality of ECMs
Β 
TXT
PDF
C++ Made Easy: Common Mistakes Students Make in Programming Assignments
PDF
C++ Made Easy: Common Mistakes Students Make in Programming Assignments
PPTX
Best-Practices-in-Writing-Clean-Maintainable-Code
PPT
Ensuring code quality
PDF
How Virtual Compilation Transforms Static Code Analysis
Writing High Quality Code in C#
Code review
SE2018_Lec 17_ Coding
Best practices in enterprise applications
Improving Code Quality Through Effective Review Process
SE2_Lec 18_ Coding
Clean Infrastructure as Code
Top 50 .NET Interview Questions and Answers 2019 | Edureka
.NET Fundamentals and Business Application Development
How to do code review and use analysis tool in software development
presentation slides of Week 3 for 1st.pptx
Rhapsody Software
Comparing the code quality of ECMs
Β 
C++ Made Easy: Common Mistakes Students Make in Programming Assignments
C++ Made Easy: Common Mistakes Students Make in Programming Assignments
Best-Practices-in-Writing-Clean-Maintainable-Code
Ensuring code quality
How Virtual Compilation Transforms Static Code Analysis
Ad

More from Intro C# Book (20)

PPTX
17. Java data structures trees representation and traversal
PPTX
Java Problem solving
PPTX
20.5 Java polymorphism
PPTX
20.4 Java interfaces and abstraction
PPTX
20.3 Java encapsulation
PPTX
20.2 Java inheritance
PPTX
20.1 Java working with abstraction
PPTX
19. Java data structures algorithms and complexity
PPTX
18. Java associative arrays
PPTX
16. Java stacks and queues
PPTX
14. Java defining classes
PPTX
13. Java text processing
PPTX
12. Java Exceptions and error handling
PPTX
11. Java Objects and classes
PPTX
09. Java Methods
PPTX
05. Java Loops Methods and Classes
PPTX
07. Java Array, Set and Maps
PPTX
03 and 04 .Operators, Expressions, working with the console and conditional s...
PPTX
02. Data Types and variables
PPTX
01. Introduction to programming with java
17. Java data structures trees representation and traversal
Java Problem solving
20.5 Java polymorphism
20.4 Java interfaces and abstraction
20.3 Java encapsulation
20.2 Java inheritance
20.1 Java working with abstraction
19. Java data structures algorithms and complexity
18. Java associative arrays
16. Java stacks and queues
14. Java defining classes
13. Java text processing
12. Java Exceptions and error handling
11. Java Objects and classes
09. Java Methods
05. Java Loops Methods and Classes
07. Java Array, Set and Maps
03 and 04 .Operators, Expressions, working with the console and conditional s...
02. Data Types and variables
01. Introduction to programming with java

Recently uploaded (20)

PDF
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PPTX
Introduction to Information and Communication Technology
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
Β 
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PDF
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
PPTX
Digital Literacy And Online Safety on internet
PPTX
artificial intelligence overview of it and more
PPTX
Internet___Basics___Styled_ presentation
PDF
Testing WebRTC applications at scale.pdf
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPTX
SAP Ariba Sourcing PPT for learning material
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
DOCX
Unit-3 cyber security network security of internet system
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PDF
WebRTC in SignalWire - troubleshooting media negotiation
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
introduction about ICD -10 & ICD-11 ppt.pptx
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
An introduction to the IFRS (ISSB) Stndards.pdf
Slides PDF The World Game (s) Eco Economic Epochs.pdf
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
Introduction to Information and Communication Technology
Power Point - Lesson 3_2.pptx grad school presentation
Β 
INTERNET------BASICS-------UPDATED PPT PRESENTATION
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
Digital Literacy And Online Safety on internet
artificial intelligence overview of it and more
Internet___Basics___Styled_ presentation
Testing WebRTC applications at scale.pdf
Unit-1 introduction to cyber security discuss about how to secure a system
SAP Ariba Sourcing PPT for learning material
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
Unit-3 cyber security network security of internet system
Module 1 - Cyber Law and Ethics 101.pptx
WebRTC in SignalWire - troubleshooting media negotiation

21. High-Quality Programming Code

  • 1. High-Quality Programming Code Code Correctness, Readability, Maintainability Svetlin Nakov Technical Trainer www.nakov.com Software University http://softuni.bg
  • 2. 2 ο‚§ Why Quality Is Important? ο‚§ Software Quality: External and Internal ο‚§ What is High-Quality Code? ο‚§ Code Conventions ο‚§ Managing Complexity ο‚§ Characteristics of Quality Code Table of Contents
  • 4. 4 ο‚§ What does this code do? Is it correct? Why Quality Is Important? static void Main() { int value=010, i=5, w; switch(value){case 10:w=5;Console.WriteLine(w);break;case 9:i=0;break; case 8:Console.WriteLine("8 ");break; default:Console.WriteLine("def ");{ Console.WriteLine("hoho "); } for (int k = 0; k < i; k++, Console.WriteLine(k - 'f'));break;} { Console.WriteLine("loop!"); } }
  • 5. 5 ο‚§ Now the code is formatted, but is still unclear. Why Quality Is Important? (2) static void Main() { int value = 010, i = 5, w; switch (value) { case 10: w = 5; Console.WriteLine(w); break; case 9: i = 0; break; case 8: Console.WriteLine("8 "); break; default: Console.WriteLine("def "); Console.WriteLine("hoho "); for (int k = 0; k < i; k++, Console.WriteLine(k - 'f')) ; break; } Console.WriteLine("loop!"); }
  • 6. 6 ο‚§ External quality ο‚§ Does the software behave correctly? ο‚§ Are the produced results correct? ο‚§ Does the software run fast? ο‚§ Is the software UI easy-to-use? ο‚§ Is the code secure enough? ο‚§ Internal quality ο‚§ Is the code easy to read and understand? ο‚§ Is the code well structured? ο‚§ Is the code easy to modify? Software Quality
  • 7. 7 ο‚§ High-quality programming code: ο‚§ Easy to read and understand ο‚§ Easy to modify and maintain ο‚§ Correct behavior in all cases ο‚§ Well tested ο‚§ Well architectured and designed ο‚§ Well documented ο‚§ Self-documenting code ο‚§ Well formatted What is High-Quality Programming Code?
  • 8. 8 ο‚§ High-quality programming code: ο‚§ Strong cohesion at all levels: modules, classes, methods, etc. ο‚§ Single unit is responsible for single task ο‚§ Loose coupling between modules, classes, methods, etc. ο‚§ Units are independent one of another ο‚§ Good formatting ο‚§ Good names for classes, methods, variables, etc. ο‚§ Self-documenting code style What is High-Quality Programming Code? (2)
  • 10. 10 ο‚§ Code conventions are formal guidelines about the style of the source code: ο‚§ Code formatting conventions ο‚§ Indentation, whitespace, etc. ο‚§ Naming conventions ο‚§ PascalCase or camelCase, prefixes, suffixes, etc. ο‚§ Best practices ο‚§ Classes, interfaces, enumerations, structures, inheritance, exceptions, properties, events, constructors, fields, operators, etc. Code Conventions
  • 11. 11 ο‚§ Microsoft official C# code conventions ο‚§ Design Guidelines for Developing Class Libraries: http://msdn.microsoft.com/en-us/library/ms229042.aspx ο‚§ Java official code conventions ο‚§ http://www.oracle.com/technetwork/java/codeconvtoc-136057.html ο‚§ Semi-official JavaScript code conventions ο‚§ http://javascript.crockford.com/code.html, http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml ο‚§ Semi-official PHP conventions ο‚§ http://www.php-fig.org/psr/psr-1/ Code Conventions (2)
  • 13. 13 ο‚§ Managing complexity has central role in software construction ο‚§ Minimize the amount of complexity that anyone’s brain has to deal with at certain time ο‚§ Architecture and design challenges ο‚§ Design modules and classes to reduce complexity ο‚§ Code construction challenges ο‚§ Apply good software construction practices: classes, methods, variables, naming, statements, error handling, formatting, comments, etc. Managing Complexity
  • 14. 14 ο‚§ Key to being an effective programmer: ο‚§ Maximizing the portion of a program that you can safely ignore ο‚§ While working on any one section of code ο‚§ Most practices discussed later propose ways to achieve this important goal Managing Complexity (2)
  • 16. 16 ο‚§ Correct behavior ο‚§ Conforming to the requirements ο‚§ Stable, no hangs, no crashes ο‚§ Bug free – works as expected ο‚§ Correct response to incorrect usage ο‚§ Readable – easy to read ο‚§ Understandable – self-documenting ο‚§ Maintainable – easy to modify when required Key Characteristics of High-Quality Code
  • 17. 17 ο‚§ Good identifiers names ο‚§ Good names for variables, constants, methods, parameters, classes, structures, fields, properties, interfaces, structures, enumerations, namespaces, ο‚§ High-quality classes, interfaces and class hierarchies ο‚§ Good abstraction and encapsulation ο‚§ Simplicity, reusability, minimal complexity ο‚§ Strong cohesion, loose coupling Key Characteristics of High-Quality Code (2)
  • 18. 18 ο‚§ High-quality methods ο‚§ Reduced complexity, improved readability ο‚§ Good method names and parameter names ο‚§ Strong cohesion, loose coupling ο‚§ Variables, data, expressions and constants ο‚§ Minimal variable scope, span, live time ο‚§ Simple expressions ο‚§ Correctly used constants ο‚§ Correctly organized data Key Characteristics of High-Quality Code (3)
  • 19. 19 ο‚§ Correctly used control structures ο‚§ Simple statements ο‚§ Simple conditional statements and simple conditions ο‚§ Well organized loops without deep nesting ο‚§ Good code formatting ο‚§ Reflecting the logical structure of the program ο‚§ Good formatting of classes, methods, blocks, whitespace, long lines, alignment, etc. Key Characteristics of High-Quality Code (4)
  • 20. 20 ο‚§ High-quality documentation and comments ο‚§ Effective comments ο‚§ Self-documenting code ο‚§ Defensive programming and exceptions ο‚§ Ubiquitous use of defensive programming ο‚§ Well organized exception handling ο‚§ Code tuning and optimization ο‚§ Quality code instead of good performance ο‚§ Code performance when required Key Characteristics of High-Quality Code (5)
  • 21. 21 ο‚§ Following the corporate code conventions ο‚§ Formatting and style, naming, etc. ο‚§ Domain-specific best practices ο‚§ Well tested and reviewed ο‚§ Testable code ο‚§ Well designed unit tests ο‚§ Tests for all scenarios ο‚§ High code coverage ο‚§ Passed code reviews and inspections Key Characteristics of High-Quality Code (6)
  • 22. 22 1. Classes define specific structure for objects ο‚§ Objects are particular instances of a class 2. Classes define fields, methods, constructors, 3. properties and other members ο‚§ Access modifiers limit the access to class members 4. Constructors are invoked when creating new class instances and initialize the object's internal state 5. Properties expose the class data in safe, controlled way Summary
  • 24. License ο‚§ This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" license 24 ο‚§ Attribution: this work may contain portions from ο‚§ "High Quality Code" course by Telerik Academy under CC-BY-NC-SA license
  • 25. Free Trainings @ Software University ο‚§ Software University Foundation – softuni.org ο‚§ Software University – High-Quality Education, Profession and Job for Software Developers ο‚§ softuni.bg ο‚§ Software University @ Facebook ο‚§ facebook.com/SoftwareUniversity ο‚§ Software University @ YouTube ο‚§ youtube.com/SoftwareUniversity ο‚§ Software University Forums – forum.softuni.bg