Slide 1

Slide 1 text

by @fernando_cejas The art of coding disasters and failures

Slide 2

Slide 2 text

I am here because I love to share experiences and disasters I have made in my professional life. Hello! I’m Fernando Cejas You can find me: ● Twitter: @fernando_cejas ● Github: android10 ● Blog: www.fernandocejas.com

Slide 3

Slide 3 text

Your first lines of code...

Slide 4

Slide 4 text

Your first mistakes...

Slide 5

Slide 5 text

“A person who never made a mistake never tried anything new” “

Slide 6

Slide 6 text

Screwing things up...

Slide 7

Slide 7 text

Release Failure Prod Dev

Slide 8

Slide 8 text

Mom to the rescue...

Slide 9

Slide 9 text

May the force of FAILURE be with you...

Slide 10

Slide 10 text

Fact: Our Software is terrible!!! And that doesn’t make it special. All software is terrible, and yes, we know it is definitely TRUE

Slide 11

Slide 11 text

Code Product Process Types of mistakes

Slide 12

Slide 12 text

Product Mistakes Products which have failed or made mistakes related to design and ideas.

Slide 13

Slide 13 text

FitSpoon

Slide 14

Slide 14 text

Throne Master

Slide 15

Slide 15 text

Process Mistakes This includes any process related in the cycle of software development: Releasing, hiring, management, etc.

Slide 16

Slide 16 text

Coding Mistakes Main bad practices we make as engineers and hints on how to solve them.

Slide 17

Slide 17 text

Code must be self-explanatory READABLE CODE 1

Slide 18

Slide 18 text

Comments do not work They are always outdated. Rename and refactor. /** * Dear maintainer: * * Once you are done trying to 'optimize' this routine, * and have realized what a terrible mistake that was, * please increment the following counter as a warning * to the next guy: * * total_hours_wasted_here = 42 */

Slide 19

Slide 19 text

Comments do not work They are always outdated. Rename and refactor. /** * When I wrote this, only God and I understood what I was doing * Now, God only knows */ /** * Before modifying this code, please call me: [email protected] */

Slide 20

Slide 20 text

public void path(Node myNode, Key k) { Node h = myNode.find(key) if (k.compareTo(h.key) < 0) { if (!isRed(h.left) && !isRed(h.left.left)) { h = moveRedLeft(h); h.left = delete(h.left, k); } } else { if (isRed(h.left)) h = rotateRight(h); if (k.compareTo(h.key) == 0 && (h.right == null)) h = null; if (!isRed(h.right) && !isRed(h.right.left)) h = moveRedRight(h); if (k.compareTo(h.key) == 0) { Node x = min(h.right); h.key = x.key; h.val = x.val; h.right = deleteMin(h.right); } else { h.right = delete(h.right, k); } } balance(h); }

Slide 21

Slide 21 text

Hide complexity public void findPath(Node fromNode, Key key) { Node node = myNode.find(key) //some logic deleteNode(node) } private Node deleteNode(Node node, Key key) { if (key.compareTo(node.key) < 0) { if (!isRed(node.left) && !isRed(node.left.left)) node = moveRedLeft(node); node.left = delete(node.left, key); } ... return balance(node); } Refactoring is our friend.

Slide 22

Slide 22 text

Code written in ... interface ElokuvaArkisto { fun elokuvat(): Either> class Verkko @Inject constructor(private val verkkoKäsittelijä: VerkkoKäsittelijä, private val palvelu: ElokuvaPalvelu) : ElokuvaArkisto { override fun elokuvat(): Either> { return when (verkkoKäsittelijä.onYhdistetty) { true -> request(palvelu.elokuvat(), { it.map { it.elokuvaan() } }, emptyList()) false -> Left(Verkkoyhteys()) } } fun pyyntö() { ... } } }

Slide 23

Slide 23 text

Code written in english interface MoviesRepository { fun movies(): Either> class Network @Inject constructor(private val networkHandler: NetworkHandler, private val service: MoviesService) : MoviesRepository { override fun movies(): Either> { return when (networkHandler.isConnected) { true -> request(service.movies(), { it.map { it.toMovie() } }, emptyList()) false -> Left(NetworkConnection()) } } fun request() { ... } } }

Slide 24

Slide 24 text

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.” “

Slide 25

Slide 25 text

Please only for learning purpose REINVENTING THE WHEEL 2

Slide 26

Slide 26 text

Reinventing the wheel Only for learning purpose. Once I worked on a chat built in assembler... WinZip WinRAR UltraZip 180 files total size 2387 Kb 2387 Kb 2387 Kb File compressed size 1241 Kb 1169 Kb 2362 Kb Total Compression ratio 48% 51% 1% Time elapsed 32 seconds 37 seconds 199 seconds

Slide 27

Slide 27 text

Naming is always complicated NAMING THINGS 3

Slide 28

Slide 28 text

Naming is complicated Please refactor. @Deprecated Annotation.

Slide 29

Slide 29 text

Naming is complicated Please refactor. @Deprecated Annotation. @Deprecated("Use JsonParser") class LegacyJsonParser { ... }

Slide 30

Slide 30 text

Detecting anti patterns is key in any codebase ANTI PATTERNS 4

Slide 31

Slide 31 text

Anti patterns detection OOP God classes and Singletons. Lava antipattern, many more...

Slide 32

Slide 32 text

OOP and FP principles Design principles intended to make software designs more understandable, flexible and maintainable.

Slide 33

Slide 33 text

Most FP still have structs. Specifying the smallest set of data required by a function is still good practice. Requiring the least specific interface to the data is also a good practice. Abiding by some interface contract is just as good in functional programming as in object oriented. If a sort function takes a comparator, then you would expect the '0 is equals, less than provides negative results, greater than positive results' behavior. 'Only do one thing' was taken from imperative programming in the first place. Having small, focused functions is good. Specifying parameters to a function (or a higher order function to retrieve them) rather than hard coding the function to go get some value is just as good in FP as in object oriented. Allowing you to change behaviors without modifying code is good. FP uses higher order functions more than inheritance, but the principle holds. Programming principles SRP OCP LSP ISP DIP OOP and FP https://softwareengineering.stackexchange.com/questions/165356/equivalent-of-solid-principles-for-functional-programming

Slide 34

Slide 34 text

Patterns and code consistency

Slide 35

Slide 35 text

The boy scout rule

Slide 36

Slide 36 text

CODE is communication between people (that incidentally runs on a computer)

Slide 37

Slide 37 text

Extra Ball Good practices at PROCESS level which can help you to detect and avoid failures and mistakes in order to write higher quality software.

Slide 38

Slide 38 text

Always use the best tool for the right job. Best Tool A couple of extra eyes always add quality to the code. Pair Programming You do not have to do 100% TDD but is one more tool in your toolbox. TDD Communication and knowledge sharing are keys in any project. Work as a team It is key to count on an mature CI automated and easier releasing and building. CI Pipeline Techniques like refactoring help to have a healthy codebase. Continuous Improvement Good practices

Slide 39

Slide 39 text

Zero Bugs Application

Slide 40

Slide 40 text

“Zero-Bug does not mean bug-free code production, it means striving to eradicate all known bugs”

Slide 41

Slide 41 text

Screwing it up... ...and recovery

Slide 42

Slide 42 text

Learn out of mistakes!!! Have a Hero!!! TEST YOUR SOFTWARE!

Slide 43

Slide 43 text

Share your experiences!

Slide 44

Slide 44 text

May the force of FAILURE be with you...

Slide 45

Slide 45 text

You can find me at: Twitter: @fernando_cejas Github: @android10 Blog: https://www.fernandocejas.com Any questions? Thanks!

Slide 46

Slide 46 text

Vector Icons by Matthew Skiles Presentation template designed by Slidesmash Photographs by pexels.com Special thanks to all people who made and share these awesome resources for free: Credits

Slide 47

Slide 47 text

This presentation uses the following typographies and colors: Colors used Free Fonts used: https://www.fontsquirrel.com/fonts/montserrat https://www.fontsquirrel.com/fonts/open-sans Presentation Design