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
IF ... THEN ... ELSE
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Nicola Sanitate
October 24, 2018
Programming
0
39
IF ... THEN ... ELSE
4 tips for write cleaner code
Nicola Sanitate
October 24, 2018
Tweet
Share
More Decks by Nicola Sanitate
See All by Nicola Sanitate
Angular - Introduction
nsanitate
0
53
Angular - Routing & Forms
nsanitate
0
67
Scratch: Programmare è un gioco da ragazzi
nsanitate
1
69
Principi SOLID - Le ricette dello zio Bob per un OOP da leccarsi i baffi
nsanitate
0
160
ApuliaSoft @ MathOnJob '18
nsanitate
0
37
ApuliaSoft @ Ingegneria del software '18
nsanitate
0
84
Modello ad attori - Da 700k a 40M e oltre di elaborazioni a settimana con il minimo sforzo
nsanitate
0
27
Angular - Routing & Forms
nsanitate
0
46
Angular - Introduction
nsanitate
0
61
Other Decks in Programming
See All in Programming
朝日新聞のデジタル版を支えるGoバックエンド ー価値ある情報をいち早く確実にお届けするために
junkiishida
1
390
Claude Codeセッション現状確認 2026福岡 / fukuoka-aicoding-00-beacon
monochromegane
4
400
Rubyと楽しいをつくる / Creating joy with Ruby
chobishiba
0
210
New in Go 1.26 Implementing go fix in product development
sunecosuri
0
370
Unity6.3 AudioUpdate
cova8bitdots
0
110
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
260
AIに任せる範囲を安全に広げるためにやっていること
fukucheee
0
110
猫の手も借りたい!ので AIエージェント猫を作って社内に放した話 Claude Code × Container Lambda の Slack Bot "DevNeko"
naramomi7
0
250
The Ralph Wiggum Loop: First Principles of Autonomous Development
sembayui
0
3.7k
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
450
Fundamentals of Software Engineering In the Age of AI
therealdanvega
1
220
今、アーキテクトとして 品質保証にどう関わるか
nealle
0
200
Featured
See All Featured
Heart Work Chapter 1 - Part 1
lfama
PRO
5
35k
My Coaching Mixtape
mlcsv
0
67
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.3k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
170
Design in an AI World
tapps
0
160
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.9k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.4k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
240
Music & Morning Musume
bryan
47
7.1k
Abbi's Birthday
coloredviolet
2
5.2k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Done Done
chrislema
186
16k
Transcript
IF … THEN … ELSE Come sopravvivere alle avverse condizioni
e vivere una vita più felice
4 consigli per scrivere codice più pulito
100% Utile anche per linguaggi che non siano JavaScript
1. Multiple criteria
function test(fruit) { if (fruit == 'apple' || fruit ==
'strawberry') console.log('red'); }
Array.includes
function test(fruit) { const redFruits = ['apple', 'strawberry', 'cherry', 'cranberries'];
if (redFruits.includes(fruit)) console.log('red'); }
2. Nesting
function test(fruit, quantity) { const redFruits = ['apple', 'strawberry', 'cherry',
'cranberries']; if (fruit) { if (redFruits.includes(fruit)) { console.log('red'); if (quantity > 10) console.log('big quantity'); } } else { throw new Error('No fruit!'); } }
Return Early
function test(fruit, quantity) { const redFruits = ['apple', 'strawberry', 'cherry',
'cranberries']; if (!fruit) throw new Error('No fruit!'); if (!redFruits.includes(fruit)) return; console.log('red'); if (quantity > 10) console.log('big quantity'); }
3. Switch
function test(color) { switch (color) { case 'red': return ['apple',
'strawberry']; case 'yellow': return ['banana', 'pineapple']; case 'purple': return ['grape', 'plum']; default: return []; } }
Object Literal (Map)
const fruitColor = { red: ['apple', 'strawberry'], yellow: ['banana', 'pineapple'],
purple: ['grape', 'plum'] }; function test(color) { return fruitColor[color] || []; }
4. Partial criteria
const fruits = [ { name: 'apple', color: 'red' },
{ name: 'banana', color: 'yellow' } ]; function test() { let isAllRed = true; for (let f of fruits) { if (f.color == 'red') { isAllRed = false; break; } } console.log(isAllRed); }
Array.every (Array.some)
const fruits = [ { name: 'apple', color: 'red' },
{ name: 'banana', color: 'yellow' } ]; function test() { const isAllRed = fruits.every(f => f.color == 'red'); console.log(isAllRed); }
I linguaggi offrono più di quello che pensiamo
Studiamo Grazie per l’attenzione