19
PRINCIPLES OF GOOD PROGRAMMING Presentation By Angelin @ardentlearner

The principles of good programming

Embed Size (px)

DESCRIPTION

The Principles of Good Programming

Citation preview

Page 1: The principles of good programming

PRINCIPLES

OF

GOOD

PROGRAMMINGPresentation By

Angelin

@ardentlearner

Page 2: The principles of good programming

As soon as you start repeating yourself (e.g. a long expression, a series of statements, same concept) create a new abstraction.

DRY

I will not repeat myself

I will not repeat myself

I will not repeat myself

I will not repeat myself

I will not repeat myself

I will not repeat myselfREPETITION IS THE ROOT OF ALL SOFTWARE EVIL

DON’T REPEAT YOURSELF

@ardentlearner 1

Page 3: The principles of good programming

Each significant piece of functionality in a program should be implemented in just one place in the source code.

ABSTRACT

Main Problem

1st layer abstraction

2nd layer abstraction

3rd layer abstraction

@ardentlearner 2

Page 4: The principles of good programming

KISS

Simplicity (and avoiding complexity) should always be a key goal.

Simple code takes less time to write, has fewer bugs and is easier to modify.

@ardentlearner 3

Always remember to…

K I S SKEEP IT SIMPLE STUPID

Page 5: The principles of good programming

YAGNI

Avoid Creating a YAGNI (You aren’t going to need it)

You should try not to add functionality until you need it.

@ardentlearner 4

YAGNI“Hey,

we could …”

The simplest thing that could possibly work

No Pain

Pain

Page 6: The principles of good programming

SIMPLE

Do the simplest thing that could possibly work.A good question to ask one’s self when programming is, “What is the simplest thing that could possibly work?”

This helps keep us on the path towards simplicity in the design.@ardentlearner 5

IT’S THE

THINGS

THAT MAKE A

Page 7: The principles of good programming

The code should be easily read and understood with a minimum of effort required.

If code requires too much thinking from an observer to understand, then it can probably stand to be simplified.

DON’T MAKE ME THINK

@ardentlearner 6

Page 8: The principles of good programming

OPEN / CLOSED

Software entities (classes, modules, functions, etc.) should be open for extension,

but closed for modification.

In other words, do not write classes that people can modify. Write classes that people can extend.

@ardentlearner 7

FOR EXTENSION

MODIFICATION

OPEN

CLOSED

Page 9: The principles of good programming

MAINTAINABLEWrite Code for the Maintainer

Almost any code that is worth writing is worth maintaining in

the future.

@ardentlearner 8

WRITE YOUR

AS IF THE PERSON

MAINTAINING IT

IS A

HOMICIDAL MANIAC

WHO KNOWS

WHERE YOU LIVE

Page 10: The principles of good programming

LEAST ASTONISHMENT

Code should surprise the reader as little as possible.

This means following standard coding conventions and the code should do what the comments and name suggest and any

potentially surprising side effects should be avoided as much as possible.

@ardentlearner 9

Page 11: The principles of good programming

SINGLE RESPONSIBILITY

A component of code (e.g. class or function) should perform a single well defined task.

@ardentlearner 10

Page 12: The principles of good programming

MINIMIZE COUPLING

@ardentlearner 11

“All modules should be independent as far as possible”

Improves maintainability

Page 13: The principles of good programming

MAXIMIZE COHESION

@ardentlearner 12

“Things that belong together should be kept together”

Makes code easier to understand, debug and test.

Page 14: The principles of good programming

THE LAW OF DEMETERis also known as

Principle of Least Knowledge

THE LAW OF DEMETER

Talk only to your closest friends

@ardentlearner 13

Page 15: The principles of good programming

AVOID PREMATURE OPTIMIZATION

Don’t even think about optimization unless your code is working but slower than you want. Only then should you start thinking

about optimizing and only with the aid of empirical data.

"We should forget about small efficiencies, say about 97% of the time: Premature Optimization is the root of all evil" - Donald Knuth.

@ardentlearner 14

Page 16: The principles of good programming

REUSE CODE

Reusing code improves code reliability

and decreases development time.

@ardentlearner 15

Page 17: The principles of good programming

SEPARATION OF CONCERNS

Different areas of functionality should be managed by distinct and minimally overlapping modules of code.

@ardentlearner 16

Page 18: The principles of good programming

EMBRACE CHANGE

@ardentlearner 17

Page 19: The principles of good programming

HAPPY

PROGRAMMING !

@ardentlearner