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
Vue.jsでiOSアプリを作る方法
hal_spidernight
0
120
Spring gRPC について / About Spring gRPC
mackey0225
0
180
DevFest - Serverless 101 with Google Cloud Functions
tunmise
0
140
オニオンアーキテクチャを使って、 Unityと.NETでコードを共有する
soi013
0
390
CNCF Project の作者が考えている OSS の運営
utam0k
5
620
Immutable ActiveRecord
megane42
0
120
rails newと同時に型を書く
aki19035vc
6
750
SwiftUIで単方向アーキテクチャを導入して得られた成果
takuyaosawa
0
140
『改訂新版 良いコード/悪いコードで学ぶ設計入門』活用方法−爆速でスキルアップする!効果的な学習アプローチ / effective-learning-of-good-code
minodriven
29
4.8k
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
450
法律の脱レガシーに学ぶフロントエンド刷新
oguemon
4
630
Swiftコンパイラ超入門+async関数の仕組み
shiz
0
190
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
It's Worth the Effort
3n
184
28k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
A Tale of Four Properties
chriscoyier
157
23k
Building Adaptive Systems
keathley
39
2.4k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
Speed Design
sergeychernyshev
25
760
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
How to train your dragon (web standard)
notwaldorf
89
5.8k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
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 !