SlideShare a Scribd company logo
1 of 49
Download to read offline
Good Code
@KevlinHenney
Four basic premises
of writing: clarity,
brevity, simplicity,
and humanity.
William Zinsser
Let us examine [software's]
difficulties. Following Aristotle, I
divide them into essence — the
difficulties inherent in the nature
of software — and accidents —
those difficulties that today
attend its production but that
are not inherent.
How much of what software
engineers now do is still
devoted to the accidental, as
opposed to the essential?
http://cacm.acm.org/magazines/2014/2/171689-mars-code
There are standard precautions that can
help reduce risk in complex software
systems. This includes the definition of a
good software architecture based on a
clean separation of concerns, data hiding,
modularity, well-defined interfaces, and
strong fault-protection mechanisms.
Gerard J Holzmann
"Mars Code", CACM 57(2)
http://cacm.acm.org/magazines/2014/2/171689-mars-code/fulltext
Firmitas
Utilitas
Venustas
Habitability is the characteristic of
source code that enables programmers,
coders, bug-fixers, and people coming
to the code later in its life to
understand its construction and
intentions and to change it comfortably
and confidently.
Habitability makes a place livable, like
home. And this is what we want in
software — that developers feel at
home, can place their hands on any
item without having to think deeply
about where it is.
Comments
A delicate matter, requiring taste and judgement. I tend to err on the side of
eliminating comments, for several reasons. First, if the code is clear, and uses
good type names and variable names, it should explain itself. Second, comments
aren't checked by the compiler, so there is no guarantee they're right, especially
after the code is modified. A misleading comment can be very confusing. Third,
the issue of typography: comments clutter code.
Rob Pike, "Notes on Programming in C"
There is a famously bad comment style:
i=i+1; /* Add one to i */
and there are worse ways to do it:
/**********************************
* *
* Add one to i *
* *
**********************************/
i=i+1;
Don't laugh now, wait until you see it in real life.
Rob Pike, "Notes on Programming in C"
A common fallacy is to assume authors
of incomprehensible code will somehow
be able to express themselves lucidly
and clearly in comments.
Kevlin Henney
https://twitter.com/KevlinHenney/status/381021802941906944
http://www.bonkersworld.net/object-world/
http://www.bonkersworld.net/object-world/
OBJECT-ORIENTED
VenetianBlind Door
Television
Picture
Glass
Sofa
TelevisionRemoteControl
Peephole
Naomi Epel
The Observation Deck
if (portfolioIdsByTraderId.get(trader.getId())
.containsKey(portfolio.getId()))
{
...
}
Dan North, "Code in the Language of the Domain"
97 Things Every Programmer Should Know
if (trader.canView(portfolio))
{
...
}
Dan North, "Code in the Language of the Domain"
97 Things Every Programmer Should Know
Details count.
Peter Weinberger
Architecture represents
the significant design
decisions that shape a
system, where
significant is measured
by cost of change.
Grady Booch
http://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/
function leftpad (str, len, ch) {
str = String(str);
var i = -1;
if (!ch && ch !== 0) ch = ' ';
len = len - str.length;
while (++i < len) {
str = ch + str;
}
return str;
}
function leftpad(content, length, pad) {
content = String(content)
pad = String(pad || pad === 0 ? pad : ' ')[0]
var left = Math.max(length - content.length, 0)
return pad.repeat(left) + content
}
var cache = [
'',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' '
];
function leftPad (str, len, ch) {
// convert `str` to `string`
str = str + '';
// `len` is the `pad`'s length now
len = len - str.length;
// doesn't need to pad
if (len <= 0) return str;
// `ch` defaults to `' '`
if (!ch && ch !== 0) ch = ' ';
// convert `ch` to `string`
ch = ch + '';
// cache common use cases
if (ch === ' ' && len < 10) return cache[len] + str;
// `pad` starts with an empty string
var pad = '';
// loop
while (true) {
// add `ch` to `pad` if `len` is odd
if (len & 1) pad += ch;
// divide `len` by 2, ditch the remainder
len >>= 1;
// "double" the `ch` so this operation count grows logarithmically on `len`
// each time `ch` is "doubled", the `len` would need to be "doubled" too
// similar to finding a value in binary search tree, hence O(log(n))
if (len) ch += ch;
// `len` is 0, exit the loop
else break;
}
// pad `str`!
return pad + str;
}
I have yet to see any problem,
however complicated, which,
when you looked at it in the
right way, did not become still
more complicated.
Anderson's Law
truths = {
"Padding an empty string to a length of 0 results in an empty string":
leftpad("", 0, "X") === "",
"Padding a non-empty string to a shorter length results in the same string":
leftpad("foobar", 3, "X") === "foobar",
"Padding a non-empty string to a negative length results in the same string":
leftpad("foobar", -3, "X") === "foobar",
"Padding a non-empty string to its length results in the same string":
leftpad("foobar", 6, "X") === "foobar",
"Padding to a longer length with a single character fills to the left":
leftpad("foobar", 8, "X") === "XXfoobar",
"Padding to a longer length with surplus characters fills using only first":
leftpad("foobar", 10, "XY") === "XXXXfoobar",
"Padding to a longer length with an empty string fills with space":
leftpad("foobar", 8, "") === " foobar",
"Padding to a longer length with no specified fill fills with space":
leftpad("foobar", 9) === " foobar",
"Padding to a longer length with integer 0 fills with 0":
leftpad("foobar", 7, 0) === "0foobar",
"Padding to a longer length with single-digit integer fills with digit":
leftpad("foobar", 10, 1) === "1111foobar",
"Padding to a longer length with multiple-digit integer fills with first digit":
leftpad("foobar", 10, 42) === "4444foobar",
"Padding to a longer length with negative integer fills with -":
leftpad("foobar", 8, -42) === "--foobar",
"Padding a non-string uses string representation":
leftpad(4.2, 5, 0) === "004.2",
}
truths = {
"Padding an empty string to a length of 0 results in an empty string":
leftpad("", 0, "X") === "",
"Padding a non-empty string to a shorter length results in the same string":
leftpad("foobar", 3, "X") === "foobar",
"Padding a non-empty string to a negative length results in the same string":
leftpad("foobar", -3, "X") === "foobar",
"Padding a non-empty string to its length results in the same string":
leftpad("foobar", 6, "X") === "foobar",
"Padding to a longer length with a single character fills to the left":
leftpad("foobar", 8, "X") === "XXfoobar",
"Padding to a longer length with surplus characters fills using only first":
leftpad("foobar", 10, "XY") === "XXXXfoobar",
"Padding to a longer length with an empty string fills with space":
leftpad("foobar", 8, "") === " foobar",
"Padding to a longer length with no specified fill fills with space":
leftpad("foobar", 9) === " foobar",
"Padding to a longer length with integer 0 fills with 0":
leftpad("foobar", 7, 0) === "0foobar",
"Padding to a longer length with single-digit integer fills with digit":
leftpad("foobar", 10, 1) === "1111foobar",
"Padding to a longer length with multiple-digit integer fills with first digit":
leftpad("foobar", 10, 42) === "4444foobar",
"Padding to a longer length with negative integer fills with -":
leftpad("foobar", 8, -42) === "--foobar",
"Padding a non-string uses string representation":
leftpad(4.2, 5, 0) === "004.2",
}
truths = {
"Padding an empty string to a length of 0 results in an empty string":
leftpad("", 0, "X") === "",
"Padding a non-empty string to a shorter length results in the same string":
leftpad("foobar", 3, "X") === "foobar",
"Padding a non-empty string to a negative length results in the same string":
leftpad("foobar", -3, "X") === "foobar",
"Padding a non-empty string to its length results in the same string":
leftpad("foobar", 6, "X") === "foobar",
"Padding to a longer length with a single character fills to the left":
leftpad("foobar", 8, "X") === "XXfoobar",
"Padding to a longer length with surplus characters fills using only first":
leftpad("foobar", 10, "XY") === "XXXXfoobar",
"Padding to a longer length with an empty string fills with space":
leftpad("foobar", 8, "") === " foobar",
"Padding to a longer length with no specified fill fills with space":
leftpad("foobar", 9) === " foobar",
"Padding to a longer length with integer 0 fills with 0":
leftpad("foobar", 7, 0) === "0foobar",
"Padding to a longer length with single-digit integer fills with digit":
leftpad("foobar", 10, 1) === "1111foobar",
"Padding to a longer length with multiple-digit integer fills with first digit":
leftpad("foobar", 10, 42) === "4444foobar",
"Padding to a longer length with negative integer fills with -":
leftpad("foobar", 8, -42) === "--foobar",
"Padding a non-string uses string representation":
leftpad(4.2, 5, 0) === "004.2",
}
toMap = object => new Map(Object.entries(object))
format = (proposition, ok) =>
proposition.fontcolor(ok ? "green" : "red") + "<br>"
present = truths =>
toMap(truths).forEach(
(ok, proposition) =>
write(format(proposition, ok)))
present(truths)
Padding an empty string to a length of 0 results in an empty string
Padding a non-empty string to a shorter length results in the same string
Padding a non-empty string to a negative length results in the same string
Padding a non-empty string to its length results in the same string
Padding to a longer length with a single character fills to the left
Padding to a longer length with surplus characters fills using only first
Padding to a longer length with an empty string fills with space
Padding to a longer length with no specified fill fills with space
Padding to a longer length with integer 0 fills with 0
Padding to a longer length with single-digit integer fills with digit
Padding to a longer length with multiple-digit integer fills with first digit
Padding to a longer length with negative integer fills with -
Padding a non-string uses string representation
Padding an empty string to a length of 0 results in an empty string
Padding a non-empty string to a shorter length results in the same string
Padding a non-empty string to a negative length results in the same string
Padding a non-empty string to its length results in the same string
Padding to a longer length with a single character fills to the left
Padding to a longer length with surplus characters fills using only first
Padding to a longer length with an empty string fills with space
Padding to a longer length with no specified fill fills with space
Padding to a longer length with integer 0 fills with 0
Padding to a longer length with single-digit integer fills with digit
Padding to a longer length with multiple-digit integer fills with first digit
Padding to a longer length with negative integer fills with -
Padding a non-string uses string representation
For every activity there is a
certain appropriate scale.
The Facebook iOS app has
over 18,000 Objective-C
classes, and in a single week
429 people contributing to it.
Facebook's code quality problem
Graham King
http://www.darkcoding.net/software/facebooks-code-quality-problem/
Your customers do
not buy your
software by the line.
David Evans
Quote from Kevlin Henney
Graphic by Sebastian Hermida
http://sbastn.com/2009/06/typing-is-not-the-bottleneck/

More Related Content

What's hot

Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smartlichtkind
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2Raghu nath
 
python chapter 1
python chapter 1python chapter 1
python chapter 1Raghu nath
 
F# delight
F# delightF# delight
F# delightpriort
 
Python basic
Python basic Python basic
Python basic sewoo lee
 
Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonSiddhi
 
Dns server clients (actual program)
Dns server clients (actual program)Dns server clients (actual program)
Dns server clients (actual program)Youssef Dirani
 
Implementing Software Machines in C and Go
Implementing Software Machines in C and GoImplementing Software Machines in C and Go
Implementing Software Machines in C and GoEleanor McHugh
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanWei-Yuan Chang
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and CEleanor McHugh
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In PythonMarwan Osman
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my dayTor Ivry
 
Python tutorial
Python tutorialPython tutorial
Python tutorialRajiv Risi
 
Introduction to advanced python
Introduction to advanced pythonIntroduction to advanced python
Introduction to advanced pythonCharles-Axel Dein
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6garux
 
Snakes for Camels
Snakes for CamelsSnakes for Camels
Snakes for Camelsmiquelruizm
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Qiangning Hong
 

What's hot (19)

Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smart
 
Python
PythonPython
Python
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
 
F# delight
F# delightF# delight
F# delight
 
Python basic
Python basic Python basic
Python basic
 
Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in Python
 
Dns server clients (actual program)
Dns server clients (actual program)Dns server clients (actual program)
Dns server clients (actual program)
 
Implementing Software Machines in C and Go
Implementing Software Machines in C and GoImplementing Software Machines in C and Go
Implementing Software Machines in C and Go
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and C
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Introduction to advanced python
Introduction to advanced pythonIntroduction to advanced python
Introduction to advanced python
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 
Snakes for Camels
Snakes for CamelsSnakes for Camels
Snakes for Camels
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
 

Viewers also liked

Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersKevlin Henney
 
The Marketer's Guide To Customer Interviews
The Marketer's Guide To Customer InterviewsThe Marketer's Guide To Customer Interviews
The Marketer's Guide To Customer InterviewsGood Funnel
 
Dr. Jimmy Schwarzkopf main tent trend presentation 2017
Dr. Jimmy Schwarzkopf main tent trend presentation 2017Dr. Jimmy Schwarzkopf main tent trend presentation 2017
Dr. Jimmy Schwarzkopf main tent trend presentation 2017Dr. Jimmy Schwarzkopf
 
Auténticos, Relevantes, Diferentes
Auténticos, Relevantes, DiferentesAuténticos, Relevantes, Diferentes
Auténticos, Relevantes, DiferentesSoymimarca
 
SECRETS OF WORKING WITH AN EDITOR
SECRETS OF WORKING WITH AN EDITORSECRETS OF WORKING WITH AN EDITOR
SECRETS OF WORKING WITH AN EDITORMark Gilroy
 
RISE OF THE BEAST Quick Quotes
RISE OF THE BEAST Quick QuotesRISE OF THE BEAST Quick Quotes
RISE OF THE BEAST Quick QuotesMark Gilroy
 
Actores y público en el teatro griego
Actores y público en el teatro griegoActores y público en el teatro griego
Actores y público en el teatro griegoRosa Mariño
 
kintoneの検索高速化への取り組み
kintoneの検索高速化への取り組みkintoneの検索高速化への取り組み
kintoneの検索高速化への取り組みRyo Mitoma
 
HAPPYWEEK 212 - 2017.03.27.
HAPPYWEEK 212 - 2017.03.27.HAPPYWEEK 212 - 2017.03.27.
HAPPYWEEK 212 - 2017.03.27.Jiří Černák
 
Designing in the Open
Designing in the OpenDesigning in the Open
Designing in the OpenMark Uraine
 
IoTeaTime #3 : Smart Home | De la maison connectée à la maison intelligente
IoTeaTime #3 : Smart Home | De la maison connectée à la maison intelligenteIoTeaTime #3 : Smart Home | De la maison connectée à la maison intelligente
IoTeaTime #3 : Smart Home | De la maison connectée à la maison intelligenteUSERADGENTS
 
Goをカンストさせる話
Goをカンストさせる話Goをカンストさせる話
Goをカンストさせる話Moriyoshi Koizumi
 
Vuls ローカルスキャンモードの活用方法
Vuls ローカルスキャンモードの活用方法Vuls ローカルスキャンモードの活用方法
Vuls ローカルスキャンモードの活用方法hogehuga
 
The State of UX: Industry Trends & Survey Results - IA Summit 2017
The State of UX: Industry Trends & Survey Results - IA Summit 2017The State of UX: Industry Trends & Survey Results - IA Summit 2017
The State of UX: Industry Trends & Survey Results - IA Summit 2017Lyle Kantrovich
 
HoloLens x Graphics 入門
HoloLens x Graphics 入門HoloLens x Graphics 入門
HoloLens x Graphics 入門hecomi
 
UYTTENDAELE, GÉRARD, KENNES ET ASSOCIÉS: les chiffres
UYTTENDAELE, GÉRARD, KENNES ET ASSOCIÉS: les chiffresUYTTENDAELE, GÉRARD, KENNES ET ASSOCIÉS: les chiffres
UYTTENDAELE, GÉRARD, KENNES ET ASSOCIÉS: les chiffresThierry Debels
 

Viewers also liked (20)

Game of Sprints
Game of SprintsGame of Sprints
Game of Sprints
 
Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many Programmers
 
The Marketer's Guide To Customer Interviews
The Marketer's Guide To Customer InterviewsThe Marketer's Guide To Customer Interviews
The Marketer's Guide To Customer Interviews
 
Dr. Jimmy Schwarzkopf main tent trend presentation 2017
Dr. Jimmy Schwarzkopf main tent trend presentation 2017Dr. Jimmy Schwarzkopf main tent trend presentation 2017
Dr. Jimmy Schwarzkopf main tent trend presentation 2017
 
Auténticos, Relevantes, Diferentes
Auténticos, Relevantes, DiferentesAuténticos, Relevantes, Diferentes
Auténticos, Relevantes, Diferentes
 
SECRETS OF WORKING WITH AN EDITOR
SECRETS OF WORKING WITH AN EDITORSECRETS OF WORKING WITH AN EDITOR
SECRETS OF WORKING WITH AN EDITOR
 
Identidad digital del doctorando
Identidad digital del doctorandoIdentidad digital del doctorando
Identidad digital del doctorando
 
RISE OF THE BEAST Quick Quotes
RISE OF THE BEAST Quick QuotesRISE OF THE BEAST Quick Quotes
RISE OF THE BEAST Quick Quotes
 
Actores y público en el teatro griego
Actores y público en el teatro griegoActores y público en el teatro griego
Actores y público en el teatro griego
 
kintoneの検索高速化への取り組み
kintoneの検索高速化への取り組みkintoneの検索高速化への取り組み
kintoneの検索高速化への取り組み
 
HAPPYWEEK 212 - 2017.03.27.
HAPPYWEEK 212 - 2017.03.27.HAPPYWEEK 212 - 2017.03.27.
HAPPYWEEK 212 - 2017.03.27.
 
Designing in the Open
Designing in the OpenDesigning in the Open
Designing in the Open
 
IoTeaTime #3 : Smart Home | De la maison connectée à la maison intelligente
IoTeaTime #3 : Smart Home | De la maison connectée à la maison intelligenteIoTeaTime #3 : Smart Home | De la maison connectée à la maison intelligente
IoTeaTime #3 : Smart Home | De la maison connectée à la maison intelligente
 
Digital Marketing Project, e-marketing Project, Internet Marketing Project
Digital Marketing Project, e-marketing Project, Internet Marketing ProjectDigital Marketing Project, e-marketing Project, Internet Marketing Project
Digital Marketing Project, e-marketing Project, Internet Marketing Project
 
Goをカンストさせる話
Goをカンストさせる話Goをカンストさせる話
Goをカンストさせる話
 
Startup Pitch Decks
Startup Pitch DecksStartup Pitch Decks
Startup Pitch Decks
 
Vuls ローカルスキャンモードの活用方法
Vuls ローカルスキャンモードの活用方法Vuls ローカルスキャンモードの活用方法
Vuls ローカルスキャンモードの活用方法
 
The State of UX: Industry Trends & Survey Results - IA Summit 2017
The State of UX: Industry Trends & Survey Results - IA Summit 2017The State of UX: Industry Trends & Survey Results - IA Summit 2017
The State of UX: Industry Trends & Survey Results - IA Summit 2017
 
HoloLens x Graphics 入門
HoloLens x Graphics 入門HoloLens x Graphics 入門
HoloLens x Graphics 入門
 
UYTTENDAELE, GÉRARD, KENNES ET ASSOCIÉS: les chiffres
UYTTENDAELE, GÉRARD, KENNES ET ASSOCIÉS: les chiffresUYTTENDAELE, GÉRARD, KENNES ET ASSOCIÉS: les chiffres
UYTTENDAELE, GÉRARD, KENNES ET ASSOCIÉS: les chiffres
 

Similar to Good Code

Nullcon HackIM 2012 Solutions
Nullcon HackIM 2012 SolutionsNullcon HackIM 2012 Solutions
Nullcon HackIM 2012 SolutionsNilanjan De
 
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016Codemotion
 
DEF CON 27 - SMEA - adventures in smart buttplug penetration testing
DEF CON 27 - SMEA - adventures in smart buttplug penetration testingDEF CON 27 - SMEA - adventures in smart buttplug penetration testing
DEF CON 27 - SMEA - adventures in smart buttplug penetration testingFelipe Prado
 
Ur Domain Haz Monoids DDDx NYC 2014
Ur Domain Haz Monoids DDDx NYC 2014Ur Domain Haz Monoids DDDx NYC 2014
Ur Domain Haz Monoids DDDx NYC 2014Cyrille Martraire
 
Maze solving app listing
Maze solving app listingMaze solving app listing
Maze solving app listingChris Worledge
 
Class 4: For and while
Class 4: For and whileClass 4: For and while
Class 4: For and whileMarc Gouw
 
Automatically Tolerating And Correcting Memory Errors
Automatically Tolerating And Correcting Memory ErrorsAutomatically Tolerating And Correcting Memory Errors
Automatically Tolerating And Correcting Memory ErrorsEmery Berger
 
js+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdfjs+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdfNuttavutThongjor1
 
fullstack typescript with react and express.pdf
fullstack typescript with react and express.pdffullstack typescript with react and express.pdf
fullstack typescript with react and express.pdfNuttavutThongjor1
 
The Many Facets of Apache Solr - Yonik Seeley
The Many Facets of Apache Solr - Yonik SeeleyThe Many Facets of Apache Solr - Yonik Seeley
The Many Facets of Apache Solr - Yonik Seeleylucenerevolution
 
CoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseCoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseAlexander Galkin
 
Joshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages TodayJoshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages TodayRefresh Events
 
Five Things you Need to Know About Scaling
Five Things you Need to Know About ScalingFive Things you Need to Know About Scaling
Five Things you Need to Know About ScalingMongoDB
 
Learn Python 3 for absolute beginners
Learn Python 3 for absolute beginnersLearn Python 3 for absolute beginners
Learn Python 3 for absolute beginnersKingsleyAmankwa
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!Fariz Darari
 

Similar to Good Code (20)

Nullcon HackIM 2012 Solutions
Nullcon HackIM 2012 SolutionsNullcon HackIM 2012 Solutions
Nullcon HackIM 2012 Solutions
 
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016
 
DEF CON 27 - SMEA - adventures in smart buttplug penetration testing
DEF CON 27 - SMEA - adventures in smart buttplug penetration testingDEF CON 27 - SMEA - adventures in smart buttplug penetration testing
DEF CON 27 - SMEA - adventures in smart buttplug penetration testing
 
Ur Domain Haz Monoids DDDx NYC 2014
Ur Domain Haz Monoids DDDx NYC 2014Ur Domain Haz Monoids DDDx NYC 2014
Ur Domain Haz Monoids DDDx NYC 2014
 
Python slide
Python slidePython slide
Python slide
 
Maze solving app listing
Maze solving app listingMaze solving app listing
Maze solving app listing
 
Practical File Grade 12.pdf
Practical File Grade 12.pdfPractical File Grade 12.pdf
Practical File Grade 12.pdf
 
Class 4: For and while
Class 4: For and whileClass 4: For and while
Class 4: For and while
 
Automatically Tolerating And Correcting Memory Errors
Automatically Tolerating And Correcting Memory ErrorsAutomatically Tolerating And Correcting Memory Errors
Automatically Tolerating And Correcting Memory Errors
 
ts+js
ts+jsts+js
ts+js
 
js+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdfjs+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdf
 
fullstack typescript with react and express.pdf
fullstack typescript with react and express.pdffullstack typescript with react and express.pdf
fullstack typescript with react and express.pdf
 
The Many Facets of Apache Solr - Yonik Seeley
The Many Facets of Apache Solr - Yonik SeeleyThe Many Facets of Apache Solr - Yonik Seeley
The Many Facets of Apache Solr - Yonik Seeley
 
CoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseCoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming course
 
Python Puzzlers
Python PuzzlersPython Puzzlers
Python Puzzlers
 
P2 2017 python_strings
P2 2017 python_stringsP2 2017 python_strings
P2 2017 python_strings
 
Joshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages TodayJoshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages Today
 
Five Things you Need to Know About Scaling
Five Things you Need to Know About ScalingFive Things you Need to Know About Scaling
Five Things you Need to Know About Scaling
 
Learn Python 3 for absolute beginners
Learn Python 3 for absolute beginnersLearn Python 3 for absolute beginners
Learn Python 3 for absolute beginners
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!
 

More from Kevlin Henney

The Case for Technical Excellence
The Case for Technical ExcellenceThe Case for Technical Excellence
The Case for Technical ExcellenceKevlin Henney
 
Empirical Development
Empirical DevelopmentEmpirical Development
Empirical DevelopmentKevlin Henney
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that LetterKevlin Henney
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that LetterKevlin Henney
 
Solid Deconstruction
Solid DeconstructionSolid Deconstruction
Solid DeconstructionKevlin Henney
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayKevlin Henney
 
Structure and Interpretation of Test Cases
Structure and Interpretation of Test CasesStructure and Interpretation of Test Cases
Structure and Interpretation of Test CasesKevlin Henney
 
Refactoring to Immutability
Refactoring to ImmutabilityRefactoring to Immutability
Refactoring to ImmutabilityKevlin Henney
 
Turning Development Outside-In
Turning Development Outside-InTurning Development Outside-In
Turning Development Outside-InKevlin Henney
 
Giving Code a Good Name
Giving Code a Good NameGiving Code a Good Name
Giving Code a Good NameKevlin Henney
 
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Kevlin Henney
 
Thinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantThinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantKevlin Henney
 
SOLID Deconstruction
SOLID DeconstructionSOLID Deconstruction
SOLID DeconstructionKevlin Henney
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeKevlin Henney
 

More from Kevlin Henney (20)

Program with GUTs
Program with GUTsProgram with GUTs
Program with GUTs
 
The Case for Technical Excellence
The Case for Technical ExcellenceThe Case for Technical Excellence
The Case for Technical Excellence
 
Empirical Development
Empirical DevelopmentEmpirical Development
Empirical Development
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Solid Deconstruction
Solid DeconstructionSolid Deconstruction
Solid Deconstruction
 
Get Kata
Get KataGet Kata
Get Kata
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went Away
 
Structure and Interpretation of Test Cases
Structure and Interpretation of Test CasesStructure and Interpretation of Test Cases
Structure and Interpretation of Test Cases
 
Agility ≠ Speed
Agility ≠ SpeedAgility ≠ Speed
Agility ≠ Speed
 
Refactoring to Immutability
Refactoring to ImmutabilityRefactoring to Immutability
Refactoring to Immutability
 
Old Is the New New
Old Is the New NewOld Is the New New
Old Is the New New
 
Turning Development Outside-In
Turning Development Outside-InTurning Development Outside-In
Turning Development Outside-In
 
Giving Code a Good Name
Giving Code a Good NameGiving Code a Good Name
Giving Code a Good Name
 
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
 
Thinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantThinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation Quadrant
 
Code as Risk
Code as RiskCode as Risk
Code as Risk
 
Software Is Details
Software Is DetailsSoftware Is Details
Software Is Details
 
SOLID Deconstruction
SOLID DeconstructionSOLID Deconstruction
SOLID Deconstruction
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
 

Recently uploaded

Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 

Good Code

  • 2.
  • 3.
  • 4.
  • 5. Four basic premises of writing: clarity, brevity, simplicity, and humanity. William Zinsser
  • 6.
  • 7.
  • 8. Let us examine [software's] difficulties. Following Aristotle, I divide them into essence — the difficulties inherent in the nature of software — and accidents — those difficulties that today attend its production but that are not inherent.
  • 9. How much of what software engineers now do is still devoted to the accidental, as opposed to the essential?
  • 11. There are standard precautions that can help reduce risk in complex software systems. This includes the definition of a good software architecture based on a clean separation of concerns, data hiding, modularity, well-defined interfaces, and strong fault-protection mechanisms. Gerard J Holzmann "Mars Code", CACM 57(2) http://cacm.acm.org/magazines/2014/2/171689-mars-code/fulltext
  • 13.
  • 14.
  • 15.
  • 16. Habitability is the characteristic of source code that enables programmers, coders, bug-fixers, and people coming to the code later in its life to understand its construction and intentions and to change it comfortably and confidently.
  • 17. Habitability makes a place livable, like home. And this is what we want in software — that developers feel at home, can place their hands on any item without having to think deeply about where it is.
  • 18.
  • 19.
  • 20.
  • 21. Comments A delicate matter, requiring taste and judgement. I tend to err on the side of eliminating comments, for several reasons. First, if the code is clear, and uses good type names and variable names, it should explain itself. Second, comments aren't checked by the compiler, so there is no guarantee they're right, especially after the code is modified. A misleading comment can be very confusing. Third, the issue of typography: comments clutter code. Rob Pike, "Notes on Programming in C"
  • 22. There is a famously bad comment style: i=i+1; /* Add one to i */ and there are worse ways to do it: /********************************** * * * Add one to i * * * **********************************/ i=i+1; Don't laugh now, wait until you see it in real life. Rob Pike, "Notes on Programming in C"
  • 23. A common fallacy is to assume authors of incomprehensible code will somehow be able to express themselves lucidly and clearly in comments. Kevlin Henney https://twitter.com/KevlinHenney/status/381021802941906944
  • 27. if (portfolioIdsByTraderId.get(trader.getId()) .containsKey(portfolio.getId())) { ... } Dan North, "Code in the Language of the Domain" 97 Things Every Programmer Should Know
  • 28. if (trader.canView(portfolio)) { ... } Dan North, "Code in the Language of the Domain" 97 Things Every Programmer Should Know
  • 29.
  • 31.
  • 32. Architecture represents the significant design decisions that shape a system, where significant is measured by cost of change. Grady Booch
  • 34. function leftpad (str, len, ch) { str = String(str); var i = -1; if (!ch && ch !== 0) ch = ' '; len = len - str.length; while (++i < len) { str = ch + str; } return str; }
  • 35. function leftpad(content, length, pad) { content = String(content) pad = String(pad || pad === 0 ? pad : ' ')[0] var left = Math.max(length - content.length, 0) return pad.repeat(left) + content }
  • 36.
  • 37. var cache = [ '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' ]; function leftPad (str, len, ch) { // convert `str` to `string` str = str + ''; // `len` is the `pad`'s length now len = len - str.length; // doesn't need to pad if (len <= 0) return str; // `ch` defaults to `' '` if (!ch && ch !== 0) ch = ' '; // convert `ch` to `string` ch = ch + ''; // cache common use cases if (ch === ' ' && len < 10) return cache[len] + str; // `pad` starts with an empty string var pad = ''; // loop while (true) { // add `ch` to `pad` if `len` is odd if (len & 1) pad += ch; // divide `len` by 2, ditch the remainder len >>= 1; // "double" the `ch` so this operation count grows logarithmically on `len` // each time `ch` is "doubled", the `len` would need to be "doubled" too // similar to finding a value in binary search tree, hence O(log(n)) if (len) ch += ch; // `len` is 0, exit the loop else break; } // pad `str`! return pad + str; }
  • 38. I have yet to see any problem, however complicated, which, when you looked at it in the right way, did not become still more complicated. Anderson's Law
  • 39. truths = { "Padding an empty string to a length of 0 results in an empty string": leftpad("", 0, "X") === "", "Padding a non-empty string to a shorter length results in the same string": leftpad("foobar", 3, "X") === "foobar", "Padding a non-empty string to a negative length results in the same string": leftpad("foobar", -3, "X") === "foobar", "Padding a non-empty string to its length results in the same string": leftpad("foobar", 6, "X") === "foobar", "Padding to a longer length with a single character fills to the left": leftpad("foobar", 8, "X") === "XXfoobar", "Padding to a longer length with surplus characters fills using only first": leftpad("foobar", 10, "XY") === "XXXXfoobar", "Padding to a longer length with an empty string fills with space": leftpad("foobar", 8, "") === " foobar", "Padding to a longer length with no specified fill fills with space": leftpad("foobar", 9) === " foobar", "Padding to a longer length with integer 0 fills with 0": leftpad("foobar", 7, 0) === "0foobar", "Padding to a longer length with single-digit integer fills with digit": leftpad("foobar", 10, 1) === "1111foobar", "Padding to a longer length with multiple-digit integer fills with first digit": leftpad("foobar", 10, 42) === "4444foobar", "Padding to a longer length with negative integer fills with -": leftpad("foobar", 8, -42) === "--foobar", "Padding a non-string uses string representation": leftpad(4.2, 5, 0) === "004.2", }
  • 40. truths = { "Padding an empty string to a length of 0 results in an empty string": leftpad("", 0, "X") === "", "Padding a non-empty string to a shorter length results in the same string": leftpad("foobar", 3, "X") === "foobar", "Padding a non-empty string to a negative length results in the same string": leftpad("foobar", -3, "X") === "foobar", "Padding a non-empty string to its length results in the same string": leftpad("foobar", 6, "X") === "foobar", "Padding to a longer length with a single character fills to the left": leftpad("foobar", 8, "X") === "XXfoobar", "Padding to a longer length with surplus characters fills using only first": leftpad("foobar", 10, "XY") === "XXXXfoobar", "Padding to a longer length with an empty string fills with space": leftpad("foobar", 8, "") === " foobar", "Padding to a longer length with no specified fill fills with space": leftpad("foobar", 9) === " foobar", "Padding to a longer length with integer 0 fills with 0": leftpad("foobar", 7, 0) === "0foobar", "Padding to a longer length with single-digit integer fills with digit": leftpad("foobar", 10, 1) === "1111foobar", "Padding to a longer length with multiple-digit integer fills with first digit": leftpad("foobar", 10, 42) === "4444foobar", "Padding to a longer length with negative integer fills with -": leftpad("foobar", 8, -42) === "--foobar", "Padding a non-string uses string representation": leftpad(4.2, 5, 0) === "004.2", }
  • 41. truths = { "Padding an empty string to a length of 0 results in an empty string": leftpad("", 0, "X") === "", "Padding a non-empty string to a shorter length results in the same string": leftpad("foobar", 3, "X") === "foobar", "Padding a non-empty string to a negative length results in the same string": leftpad("foobar", -3, "X") === "foobar", "Padding a non-empty string to its length results in the same string": leftpad("foobar", 6, "X") === "foobar", "Padding to a longer length with a single character fills to the left": leftpad("foobar", 8, "X") === "XXfoobar", "Padding to a longer length with surplus characters fills using only first": leftpad("foobar", 10, "XY") === "XXXXfoobar", "Padding to a longer length with an empty string fills with space": leftpad("foobar", 8, "") === " foobar", "Padding to a longer length with no specified fill fills with space": leftpad("foobar", 9) === " foobar", "Padding to a longer length with integer 0 fills with 0": leftpad("foobar", 7, 0) === "0foobar", "Padding to a longer length with single-digit integer fills with digit": leftpad("foobar", 10, 1) === "1111foobar", "Padding to a longer length with multiple-digit integer fills with first digit": leftpad("foobar", 10, 42) === "4444foobar", "Padding to a longer length with negative integer fills with -": leftpad("foobar", 8, -42) === "--foobar", "Padding a non-string uses string representation": leftpad(4.2, 5, 0) === "004.2", }
  • 42. toMap = object => new Map(Object.entries(object)) format = (proposition, ok) => proposition.fontcolor(ok ? "green" : "red") + "<br>" present = truths => toMap(truths).forEach( (ok, proposition) => write(format(proposition, ok))) present(truths)
  • 43. Padding an empty string to a length of 0 results in an empty string Padding a non-empty string to a shorter length results in the same string Padding a non-empty string to a negative length results in the same string Padding a non-empty string to its length results in the same string Padding to a longer length with a single character fills to the left Padding to a longer length with surplus characters fills using only first Padding to a longer length with an empty string fills with space Padding to a longer length with no specified fill fills with space Padding to a longer length with integer 0 fills with 0 Padding to a longer length with single-digit integer fills with digit Padding to a longer length with multiple-digit integer fills with first digit Padding to a longer length with negative integer fills with - Padding a non-string uses string representation
  • 44. Padding an empty string to a length of 0 results in an empty string Padding a non-empty string to a shorter length results in the same string Padding a non-empty string to a negative length results in the same string Padding a non-empty string to its length results in the same string Padding to a longer length with a single character fills to the left Padding to a longer length with surplus characters fills using only first Padding to a longer length with an empty string fills with space Padding to a longer length with no specified fill fills with space Padding to a longer length with integer 0 fills with 0 Padding to a longer length with single-digit integer fills with digit Padding to a longer length with multiple-digit integer fills with first digit Padding to a longer length with negative integer fills with - Padding a non-string uses string representation
  • 45.
  • 46. For every activity there is a certain appropriate scale.
  • 47. The Facebook iOS app has over 18,000 Objective-C classes, and in a single week 429 people contributing to it. Facebook's code quality problem Graham King http://www.darkcoding.net/software/facebooks-code-quality-problem/
  • 48. Your customers do not buy your software by the line. David Evans
  • 49. Quote from Kevlin Henney Graphic by Sebastian Hermida http://sbastn.com/2009/06/typing-is-not-the-bottleneck/