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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Nicola Sanitate
October 24, 2018
Programming
41
0
Share
IF ... THEN ... ELSE
4 tips for write cleaner code
Nicola Sanitate
October 24, 2018
More Decks by Nicola Sanitate
See All by Nicola Sanitate
Angular - Introduction
nsanitate
0
57
Angular - Routing & Forms
nsanitate
0
70
Scratch: Programmare è un gioco da ragazzi
nsanitate
1
72
Principi SOLID - Le ricette dello zio Bob per un OOP da leccarsi i baffi
nsanitate
0
170
ApuliaSoft @ MathOnJob '18
nsanitate
0
40
ApuliaSoft @ Ingegneria del software '18
nsanitate
0
87
Modello ad attori - Da 700k a 40M e oltre di elaborazioni a settimana con il minimo sforzo
nsanitate
0
28
Angular - Routing & Forms
nsanitate
0
47
Angular - Introduction
nsanitate
0
63
Other Decks in Programming
See All in Programming
Structured Concurrency, Scoped Values and Joiners in the JDK 25 26 27
josepaumard
1
150
書き換えて学ぶTemporal #fukts
pirosikick
2
380
TSKaigi2026-静的解析への投資がAI時代のコード品質を支える ── カスタムESLintルールの設計と運用
hayatokudou
3
280
いつか誰かが、と思っていた フロントエンド刷新5年間の実践知
kiichisugihara
1
280
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
550
🦞OpenClaw works with AWS
licux
1
370
Are We Really Coding 10× Faster with AI?
kohzas
0
190
Sans tests, vos agents ne sont pas fiables
nabondance
0
140
20年以上続くプロダクトでも使い続けられる静的解析ツールを求めて
matsuo_atsushi
0
150
ビジネスモデルから紐解く、AI+型駆動開発
hirokiomote
0
330
継続的な負荷検証を目指して
pyama86
3
1.2k
Lightning-Fast Method Calls with Ruby 4.1 ZJIT / RubyKaigi 2026
k0kubun
3
3.2k
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
140
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
54k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
Leo the Paperboy
mayatellez
7
1.8k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Why Our Code Smells
bkeepers
PRO
340
58k
The Invisible Side of Design
smashingmag
302
52k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
300
Deep Space Network (abreviated)
tonyrice
0
150
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
700
Between Models and Reality
mayunak
4
290
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