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.
精彩评论