Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Optimizing Code for Humans
Search
Felipe Ribeiro
May 11, 2017
Programming
6
390
Optimizing Code for Humans
Felipe Ribeiro
May 11, 2017
Tweet
Share
More Decks by Felipe Ribeiro
See All by Felipe Ribeiro
[Draft] My tech career abroad
felipernb
0
24
JavaScript @ Spotify - JSConf Iceland 2016
felipernb
4
390
Other Decks in Programming
See All in Programming
快速入門可觀測性
blueswen
0
460
iOS開発におけるCopilot For XcodeとCode Completion / copilot for xcode
fuyan777
1
810
KubeCon NA 2024の全DB関連セッションを紹介
nnaka2992
0
100
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
190
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
370
命名をリントする
chiroruxx
1
500
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
170
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
350
CloudflareStack でRAGに入門
asahiiwm
0
140
Beyond ORM
77web
10
1.4k
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
310
週次リリースを実現するための グローバルアプリ開発
tera_ny
1
120
Featured
See All Featured
How to Ace a Technical Interview
jacobian
276
23k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Why Our Code Smells
bkeepers
PRO
335
57k
Docker and Python
trallard
43
3.2k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
470
For a Future-Friendly Web
brad_frost
176
9.5k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
230
52k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
It's Worth the Effort
3n
183
28k
Building Applications with DynamoDB
mza
92
6.1k
BBQ
matthewcrist
85
9.4k
Transcript
Optimizing code for humans @felipernb !
“Any fool can write code that a computer can understand.
Good programmers write code that humans can understand.” Martin Fowler - @martinfowler @felipernb !
Simplicity is subjective (?) ! @felipernb !
“The purpose of software engineering is to control complexity, not
to create it.” Pamela Zave @felipernb !
“A C program with six 32-bit integers can have more
states than the number of atoms on the planet” Joe Armstrong - @joeerl @felipernb !
Programming is hard ! @felipernb !
Where does complexity creep in? ! @felipernb !
Algorithms ! @felipernb !
“Fancy algorithms are buggier than simple ones, and they're much
harder to implement.” Rob Pike's Rule #4 - @rob_pike @felipernb !
Searching // O(n) function linearSearch(arr, x) { for (let i
= 0; i < arr.length; i++) { if (arr[i] === x) return true; } return false; } @felipernb !
“Oh! But my array is always sorted, so I can
make this faster. Let's get fancy!” Developer ! @felipernb !
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 !
“Fancy algorithms are slow when n is small, and n
is usually small.” Rob Pike’s Rule #3 - @rob_pike @felipernb !
Don't get fancy! ! @felipernb !
“Data structures, not algorithms, are central to programming.” Rob Pike’s
Rule #5 - @rob_pike @felipernb !
Performance ! @felipernb !
“Premature optimization is the root of all evil” Donald Knuth
@felipernb !
“If it doesn’t work, it doesn’t matter how fast it
doesn’t work.” Mich Ravera @felipernb !
“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 !
“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 !
Novelty ✨ @felipernb !
“Surprise is one of the most expensive things you can
put into a software architecture.” Adam Tornhill - @adamtornhill @felipernb !
Boring is fine ! @felipernb !
“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 !
Naming things ! @felipernb !
“There are two hard things in Computer Science: cache invalidation,
naming things, and off-by- one errors.” Phil Karlton + the internet @felipernb !
Descriptive names can replace //comments @felipernb !
doThisAndThatAndReturnThisOtherThing(); If it's hard to name it, it's probably doing
too much @felipernb !
// Double negation is confusing ! if (!disabledFeature) { //
it's enabled! } Avoid flag names with negative meanings such as disable and disallow @felipernb !
Personal taste ❤ @felipernb !
“I do not like semicolons.” Some guy closing a perfectly
valid pull request ! @felipernb !
“You can't always get what you want.” The Rolling Stones
@felipernb !
Strict style guides are good ! @felipernb !
The code should be consistent regardless of who wrote it.
@felipernb !
Automation can put an end to lengthy and pointless discussions*
. * Specially when we all know that tabs make much more sense than spaces. @felipernb !
When consistency is a given, you can focus on what
really matters. @felipernb !
The ! Enterprise @felipernb !
“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 !
Cargo Cult ✈ @felipernb !
“A significant amount of programming is done by superstition” Chris
Siebenmann @felipernb !
Be ! skeptical @felipernb !
Tech Debt ! @felipernb !
“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 !
“Technical debt is hard to explain, but a picture is
worth a thousand words” Jedd Ahyoung - @Jedd_Ahyoung @felipernb !
How to keep things sane? ! @felipernb !
KISS ! Keep it simple, stupid @felipernb !
“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 !
Design patterns ⛩ @felipernb !
Design patterns are not about pigeonholing problems, but a tool
to efficiently communicate solutions with a common vocabulary. @felipernb !
Refactoring ! @felipernb !
“Software is messy because it reflects our evolving understanding of
the problem as we wrote it.” Sarah Mei - @sarahmei @felipernb !
Unlike the messed up Tetris game, you should be able
to take the time to rearrange the pieces in your code. @felipernb !
Code reviews ! @felipernb !
“My code isn't done until I've gone over it with
a fellow developer.” Jeff Atwood - @codinghorror @felipernb !
Peer review ≠ Pair programming @felipernb !
@felipernb !
Pragmatism ! @felipernb !
“Engineers are hired to say no.” Uncle Bob Martin -
@unclebobmartin @felipernb !
@felipernb !
Sometimes you have to say no to fun @felipernb !
Thank you! @felipernb !