Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Optimizing Code for Humans

Optimizing Code for Humans

Felipe Ribeiro

May 11, 2017
Tweet

More Decks by Felipe Ribeiro

Other Decks in Programming

Transcript

  1. “Any fool can write code that a computer can understand.

    Good programmers write code that humans can understand.” Martin Fowler - @martinfowler @felipernb !
  2. “A C program with six 32-bit integers can have more

    states than the number of atoms on the planet” Joe Armstrong - @joeerl @felipernb !
  3. “Fancy algorithms are buggier than simple ones, and they're much

    harder to implement.” Rob Pike's Rule #4 - @rob_pike @felipernb !
  4. Searching // O(n) function linearSearch(arr, x) { for (let i

    = 0; i < arr.length; i++) { if (arr[i] === x) return true; } return false; } @felipernb !
  5. “Oh! But my array is always sorted, so I can

    make this faster. Let's get fancy!” Developer ! @felipernb !
  6. Fancy search // Sorted arrays only, O(lg n) function binarySearch(arr,

    x) { let low = 0; let high = arr.length - 1; while (low <= high) { const mid = ((high - low) >> 1) + low; if (arr[mid] === x) return true; if (a[mid] < element) low = mid + 1; else high = mid - 1; } return false; } @felipernb !
  7. “Fancy algorithms are slow when n is small, and n

    is usually small.” Rob Pike’s Rule #3 - @rob_pike @felipernb !
  8. “If it doesn’t work, it doesn’t matter how fast it

    doesn’t work.” Mich Ravera @felipernb !
  9. “The cleaner and nicer the program, the faster it's going

    to run. And if it doesn't, it'll be easy to make it fast.” Joshua Bloch - @joshbloch @felipernb !
  10. “Measure. Don't tune for speed until you've measured, and even

    then don't unless one part of the code overwhelms the rest.” Rob Pike’s Rule #2 - @rob_pike @felipernb !
  11. “Surprise is one of the most expensive things you can

    put into a software architecture.” Adam Tornhill - @adamtornhill @felipernb !
  12. “Are you quite sure that all those bells and whistles,

    all those wonderful facilities of your so called powerful programming languages, belong to the solution set rather than the problem set?” Edsger W. Dijkstra @felipernb !
  13. “There are two hard things in Computer Science: cache invalidation,

    naming things, and off-by- one errors.” Phil Karlton + the internet @felipernb !
  14. // Double negation is confusing ! if (!disabledFeature) { //

    it's enabled! } Avoid flag names with negative meanings such as disable and disallow @felipernb !
  15. Automation can put an end to lengthy and pointless discussions*

    . * Specially when we all know that tabs make much more sense than spaces. @felipernb !
  16. “Any organization that designs a system will produce a design

    whose structure is a copy of the organization's communication structure.” Conway's law @felipernb !
  17. “If you want to go fast you take some debt.

    But the misunderstanding was that people thought that you never have to pay it back.” Ward Cunningham - @wardcunningham @felipernb !
  18. “Technical debt is hard to explain, but a picture is

    worth a thousand words” Jedd Ahyoung - @Jedd_Ahyoung @felipernb !
  19. “Everyone knows that debugging is twice as hard as writing

    a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?” Brian Kernighan @felipernb !
  20. Design patterns are not about pigeonholing problems, but a tool

    to efficiently communicate solutions with a common vocabulary. @felipernb !
  21. “Software is messy because it reflects our evolving understanding of

    the problem as we wrote it.” Sarah Mei - @sarahmei @felipernb !
  22. Unlike the messed up Tetris game, you should be able

    to take the time to rearrange the pieces in your code. @felipernb !
  23. “My code isn't done until I've gone over it with

    a fellow developer.” Jeff Atwood - @codinghorror @felipernb !