开发者

Should a 'page' starts with 0 or 1?

I am writing an API where I am returning paged results. Users of the API could specify which page 开发者_如何转开发they want. Should I start the page number with 0 or 1?

I think 1 makes more sense. But then again the programmer in me still prefer 0, it makes everything more consistent with the way arrays are indexed.

The API will be exposed as web service, therefore it could be used by variety of languages, if that matters.


If the page number is exposed in some way to the final user (a human behind his web browser), then you should start numbering at page 1.

numbering schemes starting at 0 does not make any sense to people, except programmers.

note: some languages are smarter in the way they index arrays, letting the index start at any number (or anything that is enumerable). Ada was such a language. unfortunately, those languages are not widespread anymore. the bad habit of exposing low-level implementation details (like memory address offsets), coming from the prevalence of languages of the C family, is one of the worst thing that happened to computer science, leading to the emergence of concepts which are not natural.


It is in your choice. But I do prefer 1, just like a book there is no page 0 if I'm right.

About the index the presentation is different with the business/logic layer. I as a user/viewer 0 means no pages result or not a page.


I'm afraid there is no simple answer.

I wouldn't start at 0 for user visible pages but again, an API is used by programmers who are used to start at 0. Decide whether you want to stay consistent with your web page (if it has also pages) or programming norms.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜