The principles of good programming
-
Upload
angelin-r -
Category
Technology
-
view
435 -
download
6
description
Transcript of The principles of good programming
![Page 1: The principles of good programming](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/1.jpg)
PRINCIPLES
OF
GOOD
PROGRAMMINGPresentation By
Angelin
@ardentlearner
![Page 2: The principles of good programming](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/2.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/3.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/4.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/5.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/6.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/7.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/8.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/9.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/10.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/11.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/12.jpg)
MINIMIZE COUPLING
@ardentlearner 11
“All modules should be independent as far as possible”
Improves maintainability
![Page 13: The principles of good programming](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/13.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/14.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/15.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/16.jpg)
REUSE CODE
Reusing code improves code reliability
and decreases development time.
@ardentlearner 15
![Page 17: The principles of good programming](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/17.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/18.jpg)
EMBRACE CHANGE
@ardentlearner 17
![Page 19: The principles of good programming](https://reader033.fdocuments.us/reader033/viewer/2022052223/5588f5c4d8b42a53138b470d/html5/thumbnails/19.jpg)
HAPPY
PROGRAMMING !
@ardentlearner