TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Designing Javascript APIs

71 点作者 ananddass超过 12 年前

5 条评论

simonsarris超过 12 年前
This is kinda thin, it reads more like an ad than anything else :/<p>I mean <i>of course</i> you shouldn't make breaking changes to your API unless you must. <i>Of course</i> if its hard to use its not good enough. These are universal truths that apply to most anything that other people build upon or merely use.<p>I've spent the last two years making a JavaScript API and I feel like there's so much more real substance they could talk about here. Writing an API is a very interesting process, and its <i>hard</i>, harder than writing a general program or even a language.<p>You don't just have to consider users needs or a grammar. Instead you have to consider all the things your clients (other programmers) might want to do, <i>and</i> all of the things their users might want to do.<p>This means you have to be extremely forward thinking, considering all the ways programmers might err while building with your library. When making general programs you have to worry about shooting yourself in the foot. With an API, you have to put forth <i>U.N. Peacekeeping</i> levels of effort to make sure nobody is going to shoot anybody or themselves. (Hopefully with better than U.N. Peacekeeping levels of success!)<p>&#62; If it’s hard to use, it’s not good enough (meaning you have to use it first)<p>This can't be stressed enough though. One of the lessons I learned here is that making a large number of sample applications (I'm at 44 little apps and counting for my lib) exposes a vast amount of untold hangups, issues, and <i>wishes.</i> It's incredible the things you demand from your API once you start using it compared to the things you thought you'd want. And they've exposed far more kinks than testing alone could have shown me.<p>Ah I've rambled a bit. Maybe I should write my own experiences later tonight.
评论 #4728892 未加载
EzGraphs超过 12 年前
Nice systematic approach:<p><i>Draw a grid, with the models/nouns/objects on the one axis and the verbs/actions on the other. Fill in a square if you can perform the given action on the given object...If you can fill in every square, consider that a complete “block”, a good candidate for an API design.</i>
评论 #4729424 未加载
d0m超过 12 年前
Thanks for sharing. Something you touched on but didn't explicitly stated is to have a standard and uniform interface everywhere.<p>My go-to example would be JQuery.. It feels like once you understand $('a.test').click(function() {..});, you understand and, most importantly, <i>feel</i> how everything else behave.<p>For instance, what if I don't want a click but a mouse hover? I don't have to read the doc or google.. I can just try .hover() and 9 times out of 10 it will work.<p>A bad API forces you to spend hours reading the doc because the 10 most obvious tries failed. Most of the time, these ugly APIs come also with bad or lack of documentation and backward-breaking changes without notifications. Yes, I'm talking about Facebook' API.
评论 #4731756 未加载
potkor超过 12 年前
&#62; Developers should never have to use a try-catch.<p>Is the "no exceptions" rule common in Javascript? Are exceptions trouble in JS for some technical reason compared to eg Python?
评论 #4739737 未加载
c4n4rd超过 12 年前
&#62; Never, make breaking changes to your API. Unless you must.<p>remove the comma from the sentence.
评论 #4731180 未加载