News for hackers. Stuff that matters.
Re:Scala One Liners by paulitex on Thursday June 02, 2011 @01:23AM (#2610831)
> On the other hand, what is this io.Source.fromFile mess? I don't understand the alternating capitalization, or the need for deep namespacing of an incredibly common type

Not at all necessary, just convenient for demos since it saves you an import.

"io" : The package is scala.io (the scala part is already imported by default). Following java, package names are always lower case.

"Source": There is a singleton object in the io package called 'Source'. Again, like java, classes and constants (including singleton objects) are capitalized.

"fromFile": A method on the Source singleton. Methods are camelCase.

In 'real' scala code the line would look like:

		import io.Source
		(...)
		val fileText = Source.fromFile("data.txt").mkString
or, even more concisely

		import io.Source.fromFile
		(...)
		val fileText = fromFile("data.txt").mkString
Since methods are just functions (a first class data type), there's no problem importing methods directly.

(edit: I also note that you didn't include all your imports, such as nokogiri, so it's not entirely a level playing filed)

There are no comments on this comment yet.