Slide 1

Slide 1 text

Generic Programming Principles @arturparkhisenko 2016

Slide 2

Slide 2 text

How do you write a code? Architecture? Patterns? Principles?

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

He knows everything about it Alexander Solovyov, YT video CTO modnakasta.ua. I do Python, Clojure, React and more. Kyiv, Ukraine http://solovyov.net https://twitter.com/asolovyov

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Have you heard something about: KISS? YAGNI? DRY?

Slide 7

Slide 7 text

?

Slide 8

Slide 8 text

Keep It Simple Stupid (KISS) Most systems work better if they are kept simple rather than made complex. Why ● Less code takes less time to write, has less bugs, and is easier to modify. ● Simplicity is the ultimate sophistication. ● It seems that perfection is reached not when there is nothing left to add, but when there is nothing left to take away.

Slide 9

Slide 9 text

You Aren’t Gonna Need It (YAGNI) YAGNI stands for “you aren’t gonna need it”: don’t implement something until it is necessary. Why ● Any work that’s only used for a feature that’s needed tomorrow, means losing effort from features that need to be done for the current iteration. ● It leads to code bloat; the software becomes larger and more complicated. How - Always implement things when you actually need them, never when you just foresee that you need them.

Slide 10

Slide 10 text

Do The Simplest Thing That Could Possibly Work Why - Real progress against the real problem is maximized if we just work on what the problem really is. How - Ask yourself: “What is the simplest thing that could possibly work?” MVP - Minimum Viable Product

Slide 11

Slide 11 text

Separation of Concerns Why ● Simplify development and maintenance of software applications. ● When concerns are well-separated, individual sections can be reused, as well as developed and updated independently. How - Break program functionality into separate modules that overlap as little as possible.

Slide 12

Slide 12 text

Keep things DRY Each significant piece of functionality in a program should be implemented in just one place in the source code. Where similar functions are carried out by distinct pieces of code, it is generally beneficial to combine them into one by abstracting out the varying parts. Why ● Duplication (inadvertent or purposeful duplication) can lead to maintenance nightmares, poor factoring, and logical contradictions. ● A modification of any single element of a system does not require a change in other logically unrelated elements. ● Additionally, elements that are logically connected to all change predictably and uniformly, and are thus kept in sync. How ● Put business rules, long expressions, if statements, math formulas, metadata, etc. in only one place. ● Identify the single, definitive source of every piece of knowledge used in your system, and then use that source to generate applicable instances of that knowledge (code, documentation, tests, etc). ● Apply the Rule of three.

Slide 13

Slide 13 text

Code For The Maintainer Why - Maintenance is by far the most expensive phase of any project. How ● Be the maintainer. ● Always code as if the person who ends up maintaining your code is a violent psychopath who knows where you live. ● Always code and comment in such a way that if juniors pick up the code, they will take pleasure in reading and learning from it. ● Don’t make me think. ● Use the Principle of Least Astonishment.

Slide 14

Slide 14 text

Avoid Premature Optimization Understanding what is and isn’t “premature” is critical of course. Why ● It is unknown upfront where the bottlenecks will be. ● After optimization, it might be harder to read and thus maintain. How ● Make It Work Make It Right Make It Fast ● Don’t optimize until you need to, optimize a bottleneck only after you have discovered it

Slide 15

Slide 15 text

Open/Closed Principle Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. In other words, don't write classes that people can modify, write classes that people can extend. source

Slide 16

Slide 16 text

Boy-Scout Rule The Boy Scouts of America have a simple rule that we can apply to our profession: “Leave the campground cleaner than you found it”. The boy-scout rule states that we should always leave the code cleaner than we found it. Why - When making changes to an existing codebase the code quality tends to degrade, accumulating technical debt. Following the boy-scout rule, we should mind the quality with each commit. Technical debt is resisted by continuous refactoring, no matter how small it is. How ● With each commit make sure it does not degrade the codebase quality. ● Any time someone sees some code that isn’t as clear as it should be, they should take the opportunity to fix it straight away.

Slide 17

Slide 17 text

First Law of Software Quality errors = (more code)*2

Slide 18

Slide 18 text

Quoting Lars Kappert (@webpro) source Every programmer benefits from understanding programming principles and patterns. This overview is a reference for myself, and I’ve just put it here. Maybe it is of help to you during design, discussion, or review. Please note that it’s far from complete, and that you often need to make trade-offs between conflicting principles.

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

ALWAYS SHARE YOUR EXPERIENCE! Be open Be kind Be polite Be .. just be, and teach everybody how to!

Slide 21

Slide 21 text

Thanks! https://arturparkhisenko.github.io/ 2016 source of text