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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Nicola Sanitate
October 24, 2018
Programming
43
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
74
Scratch: Programmare è un gioco da ragazzi
nsanitate
1
73
Principi SOLID - Le ricette dello zio Bob per un OOP da leccarsi i baffi
nsanitate
0
170
ApuliaSoft @ MathOnJob '18
nsanitate
0
43
ApuliaSoft @ Ingegneria del software '18
nsanitate
0
96
Modello ad attori - Da 700k a 40M e oltre di elaborazioni a settimana con il minimo sforzo
nsanitate
0
30
Angular - Routing & Forms
nsanitate
0
51
Angular - Introduction
nsanitate
0
66
Other Decks in Programming
See All in Programming
継続モナドとリアクティブプログラミング
yukikurage
3
690
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
160
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
300
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
4
1.6k
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
220
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
470
そこに3びきプロダクトがいるじゃろう——生成AI時代における“価値が届かない理由”の構造
kosuket
0
420
AWS DevOps AgentのAzure接続機能を検証して見えた活用法/Use Cases Verified for the AWS DevOps Agent's Azure Connectivity Feature
masakiokuda
1
220
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
440
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
150
変わらないものが、変わるものを決める — 意図駆動開発 × イベントソーシング × イミュータブル | What Doesn't Change Decides What Can — IDD × Event Sourcing × Immutability
tomohisa
0
1.3k
「人を評価する AI」の設計と実装
ryoyanara
0
180
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Everyday Curiosity
cassininazir
0
270
From π to Pie charts
rasagy
0
250
WENDY [Excerpt]
tessaabrams
11
39k
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.2k
Scaling GitHub
holman
464
140k
A Tale of Four Properties
chriscoyier
163
24k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
460
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
460
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