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
Contemporary Test Cases
maaretp
0
140
受け取る人から提供する人になるということ
little_rubyist
0
250
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2k
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
CSC509 Lecture 12
javiergs
PRO
0
160
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
960
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
230
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
250
Arm移行タイムアタック
qnighy
0
330
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
693
190k
Building Applications with DynamoDB
mza
90
6.1k
A better future with KSS
kneath
238
17k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
The Cult of Friendly URLs
andyhume
78
6k
Designing the Hi-DPI Web
ddemaree
280
34k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Building Your Own Lightsaber
phodgson
103
6.1k
What's in a price? How to price your products and services
michaelherold
243
12k
Become a Pro
speakerdeck
PRO
25
5k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
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 !