2. what is high-quality programming code? - code correctness, readability, maintainability

20
What is High- Quality Programming Code? Code Correctness, Readability, Maintainability Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training http://www.nakov.com http://codecourse.telerik.com/

Upload: telerik-software-academy

Post on 07-Dec-2014

1.067 views

Category:

Education


3 download

DESCRIPTION

High-Quality Code @ Telerik Academy Telerik Software Academy: http://codecourse.telerik.com/ The website and all video materials are in Bulgarian Content: What is High-Quality Programming Code? Why Quality Is Important? Software Quality What is High-Quality Programming Code? Code Conventions Managing Complexity Key Characteristics of High-Quality Code

TRANSCRIPT

Page 1: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

What is High-Quality Programming Code?

Code Correctness, Readability, Maintainability

Svetlin Nakov

Telerik Software Academyacademy.telerik.com

Manager Technical Traininghttp://www.nakov.com

http://codecourse.telerik.com/

Page 2: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

What is High-Quality Programming Code?

Page 3: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

Why Quality Is Important?

What does this code do? Is it correct? 3

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!"); }}

Page 4: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

Why Quality Is Important? (2)

Now the code is formatted, but is still unclear.

4

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!");}

Page 5: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

Software Quality External quality

Does the software behave correctly?

Are the produced results correct? Does the software run fast? Is the software UI easy-to-use?

Internal quality Is the code easy to read and

understand? Is the code well structured? Is the code easy to modify?

5

Page 6: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

What is High-Quality Programming Code?

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 formatted6

Page 7: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

What is High-Quality Programming Code? (2)

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 style7

Page 8: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

Code Conventions 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.

8

Page 9: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

Code Conventions (2) Microsoft has official code

conventions called Design Guidelines for Developing Class

Libraries: http://msdn.microsoft.com/en-us/library/ms229042.aspx

Sun also have official code conventions called Code Conventions for the Java

Programming Language: http://java.sun.com/docs/codeconv/

Large organization follow strict conventions Code conventions can vary in different

teams High-quality code goes beyond code

conventions Software quality is a way of thinking!

9

Page 10: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

Managing Complexity 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.

10

Page 11: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

Managing Complexity (2)

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

11

Page 12: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

Key Characteristics of High-Quality

Code Correct behavior Conforming to the requirements Stable, no hangs, no crashes Bug free Correct response to incorrect usage

Easy to read Easy to understand Maintainable – easy to modify when required

12

Page 13: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

Key Characteristics of High-Quality

Code (2) 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

13

Page 14: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

Key Characteristics of High-Quality

Code (3) 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

14

Page 15: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

Key Characteristics of High-Quality

Code (4) 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.

15

Page 16: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

Key Characteristics of High-Quality

Code (5) 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

16

Page 17: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

Key Characteristics of High-Quality

Code (6) Following the corporate code conventions Formatting and style, naming, etc. Domain-specific best practices

Well tested and reviewed Well designed unit tests

High code coverage

High coverage with automated tests Passed code reviews and

inspections17

Page 18: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

форум програмиране, форум уеб дизайнкурсове и уроци по програмиране, уеб дизайн – безплатно

програмиране за деца – безплатни курсове и уроцибезплатен SEO курс - оптимизация за търсачки

уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop

уроци по програмиране и уеб дизайн за ученициASP.NET MVC курс – HTML, SQL, C#, .NET, ASP.NET MVC

безплатен курс "Разработка на софтуер в cloud среда"

BG Coder - онлайн състезателна система - online judge

курсове и уроци по програмиране, книги – безплатно от Наков

безплатен курс "Качествен програмен код"

алго академия – състезателно програмиране, състезания

ASP.NET курс - уеб програмиране, бази данни, C#, .NET, ASP.NETкурсове и уроци по програмиране – Телерик академия

курс мобилни приложения с iPhone, Android, WP7, PhoneGap

free C# book, безплатна книга C#, книга Java, книга C#Дончо Минков - сайт за програмиранеНиколай Костов - блог за програмиранеC# курс, програмиране, безплатно

?

? ? ??

?? ?

?

?

?

??

?

?

? ?

Questions?

?

What Is High-Quality Programming Code?

http://academy.telerik.com

Page 19: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

Homework Write a short essay (1-2 pages) on the topic:"What is a high-quality programming code?"Send us a Word file in ".doc" or ".docx" format

19

Page 20: 2. What Is High-Quality Programming Code? - Code Correctness, Readability, Maintainability

Free Trainings @ Telerik Academy

“High-Quality Programming Code" course @ Telerik Academy codecourse.telerik.com

Telerik Software Academy academy.telerik.com

Telerik Academy @ Facebook facebook.com/TelerikAcademy

Telerik Software Academy Forums forums.academy.telerik.com