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
Designing JS APis
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Caio Gondim
May 17, 2014
Programming
3
260
Designing JS APis
The Good, The Bad, and the Ugly
Caio Gondim
May 17, 2014
Tweet
Share
More Decks by Caio Gondim
See All by Caio Gondim
256 shades of R, G and B
caiogondim
1
110
AB Test
caiogondim
9
690
CSS Layout: O ontem, o hoje e o depois
caiogondim
1
140
Git lightning talk
caiogondim
5
290
HTML5 Sensitivo
caiogondim
5
370
Sublime Text 2 pro tips
caiogondim
21
2.5k
Brazil
caiogondim
2
320
HTML5 - Seu navegador não é mais o mesmo
caiogondim
5
260
História dos Sistemas Operacionais de Videogames
caiogondim
3
890
Other Decks in Programming
See All in Programming
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
200
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
140
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.9k
それ、本当に安全? ファイルアップロードで見落としがちなセキュリティリスクと対策
penpeen
7
3.9k
AgentCoreとHuman in the Loop
har1101
5
240
Best-Practices-for-Cortex-Analyst-and-AI-Agent
ryotaroikeda
1
110
AIエージェント、”どう作るか”で差は出るか? / AI Agents: Does the "How" Make a Difference?
rkaga
4
2k
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
300
Raku Raku Notion 20260128
hareyakayuruyaka
0
310
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
140
Apache Iceberg V3 and migration to V3
tomtanaka
0
160
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
50
14k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Code Review Best Practice
trishagee
74
20k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.4k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.2k
WENDY [Excerpt]
tessaabrams
9
36k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
57
50k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
250
Paper Plane
katiecoart
PRO
0
46k
Transcript
DESIGNING JS APIs THE GOOD, THE BAD AND THE UGLY
GLOBO.COM
GLOBO.COM
BOOKING.COM
LOOP INFINITO
COLETANEA FRONT-END
DESIGN WHY
DEFINITION purpose, planning, or intention that exists or is thought
to exist behind an action, fact, or material object DESIGN WHY
APIs ARE DEVELOPERS UX DESIGN WHY
CODE IS WRITTEN ONCE, READ MANY TIMES DESIGN WHY
NOBODY READS API DOCs DESIGN WHY
BAD THE GOOD THE UGLY THE
BAD THE
BAD THE IMMUTABLE vs MUTABLE var foo = [3, 5,
8]; var bar = foo.slice(1, 2); console.log(foo); //=> [3, 5, 8] console.log(bar); //=> [5] http://ariya.ofilabs.com/2014/02/javascript-array-slice-vs-splice.html
BAD THE IMMUTABLE vs MUTABLE var foo = [3, 5,
8]; var bar = foo.splice(1, 2); console.log(foo); //=> [3] console.log(bar); //=> [5, 8] http://ariya.ofilabs.com/2014/02/javascript-array-slice-vs-splice.html
BAD THE IMMUTABLE vs MUTABLE var foo = [3, 5,
8]; var bar = foo.sliced(1, 2); console.log(foo); //=> [3, 5, 8] console.log(bar); //=> [5] http://ariya.ofilabs.com/2014/02/javascript-array-slice-vs-splice.html
BAD THE IMMUTABLE vs MUTABLE var foo = [3, 5,
8]; foo.slice(1, 2); console.log(foo); //=> [3] http://ariya.ofilabs.com/2014/02/javascript-array-slice-vs-splice.html
BAD THE DOUBLE NEGATIVE foo.disabled = false; bar.setHidden(false); kung.invisible =
false;
BAD THE DOUBLE NEGATIVE foo.enabled = false; bar.setVisible(false); kung.visible =
false;
BAD THE BOOLEAN TRAP var opacitySlider = new Slider(true); var
volumeSlider = new Slider(false); http://ariya.ofilabs.com/2011/08/hall-of-api-shame-boolean-trap.html
BAD THE BOOLEAN TRAP var opacitySlider = new Slider({ horizontal:
true }); var opacitySlider = new Slider({ horizontal: false }); http://ariya.ofilabs.com/2011/08/hall-of-api-shame-boolean-trap.html
BAD THE BOOLEAN TRAP var opacitySlider = new SliderHorizontal(); var
opacitySlider = new SliderVertical(); http://ariya.ofilabs.com/2011/08/hall-of-api-shame-boolean-trap.html
BAD THE INCONSISTENCE // inconsistence button.caption = “Lorem”; radioButton1.value =
“Easy”; radioButton2.value = “Medium”; radioButton3.value = “Hard”; checkbox1.option = “Ipsum”; checkbox2.option = “Dolor”;
BAD THE GOOD THE UGLY THE
GOOD THE
GOOD THE STATIC POLYMORPHISM POLYMORPSHISM IS WHEN MULTIPLE IMPLEMENTATIONS CAN
RESPOND TO THE SAME MESSAGE WITHOUT THE SENDER NEEDING TO KNOW ABOUT THE IMPLEMENTATION
GOOD THE STATIC POLYMORPHISM // inconsistence button.caption = “Lorem”; radioButton1.value
= “Easy”; radioButton2.value = “Medium”; radioButton3.value = “Hard”; checkbox1.option = “Ipsum”; checkbox2.option = “Dolor”;
GOOD THE STATIC POLYMORPHISM // static polymorphism // similar classes,
same API button.value = “Lorem”; radioButton1.value = “Easy”; radioButton2.value = “Medium”; radioButton3.value = “Hard”; checkbox1.value = “Ipsum”; checkbox2.value = “Dolor”;
GOOD THE NAMING BOOLEAN PROPs // getters of boolean props
should // start with *has*, *can* or *is* if (foo.isChecked()) { // ... }
GOOD THE NAMING BOOLEAN PROPs // getters of boolean props
should // start with *has*, *can* or *is* if (foo.hasChildren()) { // ... }
GOOD THE NAMING BOOLEAN PROPs // getters of boolean props
should // start with *has*, *can* or *is* if (foo.canBeClosed()) { // ... }
GOOD THE SPECIALIZED METHODS var car = new Vehicle(110, 2014,
true, false); var plane = new Vehicle(900, 2003, true, true);
GOOD THE SPECIALIZED METHODS var car = new Car(110, 2014);
var plane = new Vehicle(900, 2003);
GOOD THE var car = new Car({ speedMax: 110, fabricationYear:
2014 }); var plane = new Plane({ speedMax: 900, fabricationYear: 2003 }); SPECIALIZED METHODS
VERBAL ACTIONS status.message(“Lorem Ipsum”); page.forward(); page.backward(); GOOD THE
VERBAL ACTIONS status.showMessage(“Lorem Ipsum”); page.goForward(); page.goBackward(); GOOD THE
BAD THE GOOD THE UGLY THE
UGLY THE
UGLY THE var letters = [“a”, “b”, “c”]; $.each(letters, function(index,
val) {}); $.map(letters, function(val, index) {}); $(“li”).map(function(index, val) {}); Secrets of Awesome JS API Design — https://www.youtube.com/watch?v=QlQm786MClE INCONSISTENCE
UGLY THE jQuery(selector [, context]) // Select jQuery(element) // Wrap
jQuery(object) // Wrap jQuery() // Empty $ object jQuery(elementArray) // Wrap jQuery(jQuery object) // Clone jQuery(html [, ownerDocument]) // Create element jQuery(html, props) // Create element jQuery(callback) // Bind DOM loaded function Secrets of Awesome JS API Design — https://www.youtube.com/watch?v=QlQm786MClE NOT SPECIALIZED
UGLY THE var evento = “Front in Fortaleza”; evento.substring(6, 8);
// => "In" evento.substring(8, 6); // => "In" http://ariya.ofilabs.com/2014/02/javascript-string-substring-substr-slice.html INCONSISTENCE
UGLY THE http://ariya.ofilabs.com/2014/02/javascript-string-substring-substr-slice.html var evento = “Front in Fortaleza”; evento.substr(6,
8); // => "in Forta" evento.substr(8, 6); // => " Forta" INCONSISTENCE
var evento = “Front in Fortaleza”; evento.slice(6, 8); // =>
"in" evento.slice(8, 6); // => "" http://ariya.ofilabs.com/2014/02/javascript-string-substring-substr-slice.html UGLY THE INCONSISTENCE
UGLY THE http://bugs.jquery.com/ticket/13103 JQUERY BOOLEAN TRAP $("#hoverme-stop-2").mouseenter(function() { $(this) .find("img")
.stop(true, true) .fadeOut(); });
UGLY THE http://bugs.jquery.com/ticket/13103 JQUERY BOOLEAN TRAP $("#hoverme-stop-2").mouseenter(function() { $(this) .find("img")
.stop({ clearQueue: true, jumpToEnd: true }) .fadeOut(); });
UGLY THE http://bugs.jquery.com/ticket/13103 CASE CONSISTENCY var myRequest = new XMLHttpRequest();
UGLY THE BOOLEAN TRAP event.initKeyEvent( "keypress", true, true, null, null,
false, false, false, false, 9, 0 );
SEE YOU COWBOY
/caiogondim @caio_gondim
[email protected]