Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
45
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
61
Angular - Routing & Forms
nsanitate
0
76
Scratch: Programmare è un gioco da ragazzi
nsanitate
1
78
Principi SOLID - Le ricette dello zio Bob per un OOP da leccarsi i baffi
nsanitate
0
180
ApuliaSoft @ MathOnJob '18
nsanitate
0
49
ApuliaSoft @ Ingegneria del software '18
nsanitate
0
98
Modello ad attori - Da 700k a 40M e oltre di elaborazioni a settimana con il minimo sforzo
nsanitate
0
39
Angular - Routing & Forms
nsanitate
0
68
Angular - Introduction
nsanitate
0
68
Other Decks in Programming
See All in Programming
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
880
golang-bob.pdf
iwatsukayura
0
130
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1.1k
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
590
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.9k
パスワード再設定メールのURLについて知っておこう
uyuki234
0
160
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
1k
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
180
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
Kotlinの15年とServer-Side Kotlin
n_takehata
1
150
Featured
See All Featured
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
570
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
730
Mind Mapping
helmedeiros
1
400
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.2k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
My Coaching Mixtape
mlcsv
0
360
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
410
sira's awesome portfolio website redesign presentation
elsirapls
0
450
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
330
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
440
Fireside Chat
paigeccino
43
4.1k
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