Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Always default to false - Paul Grayson
Search
Las Vegas Ruby Group
January 29, 2014
0
69
Always default to false - Paul Grayson
Las Vegas Ruby Group
January 29, 2014
Tweet
Share
More Decks by Las Vegas Ruby Group
See All by Las Vegas Ruby Group
Ruby ISO Standard - David Grayson
lvrug
0
130
Windows Automation - Howard Feldman
lvrug
0
68
Separating Your Application from Rails - Brian Hughes
lvrug
0
120
SWIG and Ruby - David Grayson
lvrug
0
75
Practical Object-Oriented Design in Ruby - Charles Jackson
lvrug
3
130
The Hamster Gem - Ryan Mulligan
lvrug
1
90
Varnish+Redis - Russ Smith
lvrug
1
100
Lambdas and Pops - Jan Hettich
lvrug
0
79
Making Good Use of Fonts - Russ Smith
lvrug
1
88
Featured
See All Featured
A better future with KSS
kneath
239
18k
Java REST API Framework Comparison - PWX 2021
mraible
33
8.9k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
Code Review Best Practice
trishagee
72
19k
The Power of CSS Pseudo Elements
geoffreycrofte
79
6k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.6k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
Transcript
Always default to false Paul Grayson Las Vegas Ruby User
Group 2014-01-29
Be opinionated! • There is a right way • Consistency
aids memory true false 1 exception 0 default
The default is already false or null in many contexts
Ruby: @var, if x, methods, [], etc. -> nil SQL: NULL Javascript: undefined C#/Java: bool/boolean defaults false Originates in digital circuits? - default is OFF
Options should be opt in ☐ YES, please add me
to your mailing list ✓
Fields, variables, conditionals # DO THIS: if on_mailing_list send_email end
# NOT THIS: if !on_mailing_list withhold_email end How would you even write that method? Body does not run by default
Be careful with true default <% if !out_of_stock %> <div
id="order_form"> ... </div> <% end %> Must remember to not put anything essential in here.
Emphasize connections def f if x exceptional_stuff else default_stuff end
more_stuff end The normal path Condition and code to handle it
true default complicates connections def f if !x default_stuff else
exceptional_stuff end more_stuff end The normal path Condition and code to handle it
The “guard clause” pattern def f return y if x
normal_stuff ... end The normal path Condition and code to handle it
Summary • Default false for all fields • Test for
unusual conditions (when possible) • Beware of conditionals with true default true false 1 exception 0 default