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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Nicola Sanitate
October 24, 2018
Programming
0
40
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
55
Angular - Routing & Forms
nsanitate
0
68
Scratch: Programmare è un gioco da ragazzi
nsanitate
1
70
Principi SOLID - Le ricette dello zio Bob per un OOP da leccarsi i baffi
nsanitate
0
160
ApuliaSoft @ MathOnJob '18
nsanitate
0
38
ApuliaSoft @ Ingegneria del software '18
nsanitate
0
85
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
47
Angular - Introduction
nsanitate
0
61
Other Decks in Programming
See All in Programming
AWS×クラウドネイティブソフトウェア設計 / AWS x Cloud-Native Software Design
nrslib
16
3.4k
Geminiをパートナーに神社DXシステムを個人開発した話(いなめぐDX 開発振り返り)
fujiba
0
120
Codex CLI でつくる、Issue から merge までの開発フロー
amata1219
0
190
Reactive ❤️ Loom: A Forbidden Love Story
franz1981
2
180
Nuxt Server Components
wattanx
0
140
Agentic AI: Evolution oder Revolution
mobilelarson
PRO
0
200
へんな働き方
yusukebe
6
2.8k
Feature Toggle は捨てやすく使おう
gennei
0
370
Codex CLIのSubagentsによる並列API実装 / Parallel API Implementation with Codex CLI Subagents
takatty
2
630
Codex の「自走力」を高める
yorifuji
0
1.3k
Linux Kernelの1文字のミスで 権限昇格ができた話
rqda
0
2.2k
Redox OS でのネームスペース管理と chroot の実現
isanethen
0
460
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
[SF Ruby Conf 2025] Rails X
palkan
2
860
Information Architects: The Missing Link in Design Systems
soysaucechin
0
850
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.2k
Bash Introduction
62gerente
615
210k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
190
Believing is Seeing
oripsolob
1
97
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
160
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
330
Thoughts on Productivity
jonyablonski
75
5.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
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