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
RailsGirls IZUMO スポンサーLT
16bitidol
0
200
AIエージェントはこう育てる - GitHub Copilot Agentとチームの共進化サイクル
koboriakira
0
760
The Niche of CDK Grant オブジェクトって何者?/the-niche-of-cdk-what-isgrant-object
hassaku63
1
620
イベントストーミング図からコードへの変換手順 / Procedure for Converting Event Storming Diagrams to Code
nrslib
2
1.1k
PHP 8.4の新機能「プロパティフック」から学ぶオブジェクト指向設計とリスコフの置換原則
kentaroutakeda
2
1k
AI時代の『改訂新版 良いコード/悪いコードで学ぶ設計入門』 / ai-good-code-bad-code
minodriven
24
9.6k
商品比較サービス「マイベスト」における パーソナライズレコメンドの第一歩
ucchiii43
0
180
20250708_JAWS_opscdk
takuyay0ne
2
130
dbt民主化とLLMによる開発ブースト ~ AI Readyな分析サイクルを目指して ~
yoshyum
3
1.1k
Modern Angular with Signals and Signal Store:New Rules for Your Architecture @enterJS Advanced Angular Day 2025
manfredsteyer
PRO
0
270
20250704_教育事業におけるアジャイルなデータ基盤構築
hanon52_
5
1.1k
新メンバーも今日から大活躍!SREが支えるスケールし続ける組織のオンボーディング
honmarkhunt
5
8.7k
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
Scaling GitHub
holman
460
140k
Faster Mobile Websites
deanohume
308
31k
Optimising Largest Contentful Paint
csswizardry
37
3.3k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
KATA
mclloyd
30
14k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
"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
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