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

Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
Raghu nath
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
Raghu nath
 
Dns server clients (actual program)
Dns server clients (actual program)Dns server clients (actual program)
Dns server clients (actual program)
Youssef Dirani
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
Rajiv Risi
 

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

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

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
NuttavutThongjor1
 
Joshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages TodayJoshua Wehner - Tomorrows Programming Languages Today
Joshua Wehner - Tomorrows Programming Languages Today
Refresh 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 Scaling
MongoDB
 

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

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

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 

Recently uploaded (20)

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

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/