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
42
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
58
Angular - Routing & Forms
nsanitate
0
72
Scratch: Programmare è un gioco da ragazzi
nsanitate
1
72
Principi SOLID - Le ricette dello zio Bob per un OOP da leccarsi i baffi
nsanitate
0
170
ApuliaSoft @ MathOnJob '18
nsanitate
0
41
ApuliaSoft @ Ingegneria del software '18
nsanitate
0
92
Modello ad attori - Da 700k a 40M e oltre di elaborazioni a settimana con il minimo sforzo
nsanitate
0
29
Angular - Routing & Forms
nsanitate
0
50
Angular - Introduction
nsanitate
0
65
Other Decks in Programming
See All in Programming
開発体験を左右するライブラリの API 設計 - GraphQL スキーマ構築ライブラリから考える #tskaigi
izumin5210
2
1.6k
Technical Debt: Understanding it Rightly, Engaging it Rightly #LaravelLiveJP
shogogg
0
190
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
12k
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
13
3.4k
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
150
3Dシーンの圧縮
fadis
1
650
TypeSpec で繋ぐ複数プロダクトの型安全
maroon8021
1
400
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.1k
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
150
LLM Plugin for Node-REDの利用方法と開発について
404background
0
160
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
1.3k
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
330
Featured
See All Featured
Game over? The fight for quality and originality in the time of robots
wayneb77
1
190
A better future with KSS
kneath
240
18k
Paper Plane
katiecoart
PRO
1
51k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Google's AI Overviews - The New Search
badams
0
1k
How GitHub (no longer) Works
holman
316
150k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
160
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Designing Powerful Visuals for Engaging Learning
tmiket
1
400
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
22k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
400
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