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
Nicola Sanitate
October 24, 2018
Programming
0
29
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
51
Angular - Routing & Forms
nsanitate
0
56
Scratch: Programmare è un gioco da ragazzi
nsanitate
1
63
Principi SOLID - Le ricette dello zio Bob per un OOP da leccarsi i baffi
nsanitate
0
150
ApuliaSoft @ MathOnJob '18
nsanitate
0
34
ApuliaSoft @ Ingegneria del software '18
nsanitate
0
79
Modello ad attori - Da 700k a 40M e oltre di elaborazioni a settimana con il minimo sforzo
nsanitate
0
24
Angular - Routing & Forms
nsanitate
0
43
Angular - Introduction
nsanitate
0
58
Other Decks in Programming
See All in Programming
画像コンペでのベースラインモデルの育て方
tattaka
3
1.4k
変化を楽しむエンジニアリング ~ いままでとこれから ~
murajun1978
0
680
AIコーディングエージェント全社導入とセキュリティ対策
hikaruegashira
16
9.5k
バイブコーディング超えてバイブデプロイ〜CloudflareMCPで実現する、未来のアプリケーションデリバリー〜
azukiazusa1
3
800
Flutterと Vibe Coding で個人開発!
hyshu
1
230
#QiitaBash TDDで(自分の)開発がどう変わったか
ryosukedtomita
1
350
Comparing decimals in Swift Testing
417_72ki
0
160
React 使いじゃなくても知っておきたい教養としての React
oukayuka
18
5.4k
kiroでゲームを作ってみた
iriikeita
0
150
iOS開発スターターキットの作り方
akidon0000
0
240
Claude Code で Astro blog を Pages から Workers へ移行してみた
codehex
0
180
Strands Agents で実現する名刺解析アーキテクチャ
omiya0555
1
110
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
139
34k
A Tale of Four Properties
chriscoyier
160
23k
Visualization
eitanlees
146
16k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
8
430
GitHub's CSS Performance
jonrohan
1031
460k
The Invisible Side of Design
smashingmag
301
51k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
33
2.4k
Typedesign – Prime Four
hannesfritz
42
2.7k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.5k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
A designer walks into a library…
pauljervisheath
207
24k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.6k
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