开发者

Source.getLine - the line index, first line is 1

Why index starts from 1开发者_StackOverflow中文版 not from 0? http://www.scala-lang.org/docu/files/api/scala/io/Source.html


Line numbers traditionally start at 1. Wikipedia says:

The most common method of assigning numbers to lines is to assign every line a unique number, starting at 1 for the first line, and incrementing by 1 for each successive line.

The first high level programming language (Fortran) uses 1 for the index of the first element of an array. It was the C programming language that popularised using 0 for the first index.


Because humans normally start counting at 1. Class Source in Scala is a representation of a source (text) file, and it's natural to start counting with the first line as number 1.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜