Accepting a numerical range in a function call

Posted by dekpos on Programmers See other posts from Programmers or by dekpos
Published on 2014-03-01T16:30:12Z Indexed on 2014/06/12 21:38 UTC
Read the original article Hit count: 155

Filed under:
|

I have encountered two ways of doing it:

void foo(int from, int to); /* 'from' inclusive, 'to' exclusive */

void foo(int startIndex, int rangelength);

Has one style historically been preferred over the other? If so, was it just a matter of convention or was it due to some deeper underlying reason?

I'm currently programming in Java and noticed that the Arrays class uses the former style. The exclusivity of the to argument felt somewhat unintuitive to me, which led me to ask this question.

© Programmers or respective owner

Related posts about coding-style

Related posts about api-design