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
62
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
78
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
Claude Code + Container Use と Cursor で作る ローカル並列開発環境のススメ / ccc local dev
kaelaela
10
5.3k
20250704_教育事業におけるアジャイルなデータ基盤構築
hanon52_
5
790
脱Riverpod?fqueryで考える、TanStack Queryライクなアーキテクチャの可能性
ostk0069
0
150
ニーリーにおけるプロダクトエンジニア
nealle
0
840
#QiitaBash MCPのセキュリティ
ryosukedtomita
1
1.3k
Webの外へ飛び出せ NativePHPが切り拓くPHPの未来
takuyakatsusa
2
560
Quand Symfony, ApiPlatform, OpenAI et LangChain s'allient pour exploiter vos PDF : de la théorie à la production…
ahmedbhs123
0
190
Goで作る、開発・CI環境
sin392
0
230
Result型で“失敗”を型にするPHPコードの書き方
kajitack
5
880
RailsGirls IZUMO スポンサーLT
16bitidol
0
190
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
570
すべてのコンテキストを、 ユーザー価値に変える
applism118
3
1.3k
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
35
6.7k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Visualization
eitanlees
146
16k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
Fireside Chat
paigeccino
37
3.5k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Adopting Sorbet at Scale
ufuk
77
9.5k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
107
19k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
The Cost Of JavaScript in 2023
addyosmani
51
8.5k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
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