2 ms·
Yes, this is exactly what Java doesn't get. Reading a file with only the standard libraries is 5 lines of code. Hello world is 6. The main problem is that th
by jrockway 17y ago
Yes, this is exactly what Java doesn't get. Reading a file with only the standard libraries is 5 lines of code. Hello world is 6.
The main problem is that this encourages cargo-culting. Once someone has something working, they will just cut-n-paste-n-modify it in similar situations. Better to cargo-cult 10 lines of code than to write 5 of your own, right? The moving parts won't cut off your fingers as long as your fingers don't get too close.
(Normally I would rant about how "proper abstraction is not possible with Java", but it actually is. It just seems that the majority of libraries and programmers would rather cargo-cult than to design proper abstractions. And no, "proper abstraction" is not always "cut-n-paste from GoF".)
- TeHCrAzY 17y agoThis is why I love .Net. Want a quick and dirty file read? string fileContent = System.IO.File.ReadAllText(); Want to read it into lines? string[] fileLines = System.IO.File.ReadAllLines(); Want fine tuned byte by byte access? var fs = new System.IO.FileStream(path); They certainly looked long and hard at Java before writing .net, and covered many of the sore points carefully.
- cubicle67 17y agoI think you've missed specifying the filename, but otherwise cool. Here's Ruby for comparison: file_content = IO.read(filename) file_lines = IO.read(filename).split("\n")
- deleted 17y ago[deleted]
- regularfry 17y agofile_lines = File.readlines(filename) Not that it matters hugely :-)
- mmastrac 17y agoNot all of those methods were in .Net 1.0. I worked through the painful years of .Net 0.9 to .Net 2.0 and it wasn't always roses. The core libraries were really terrible and sparse in the early versions. Microsoft was a lot more aggressive in how they extended the core libraries post-2.0. There was an amazing amount of baggage in the language by the time 2.0 came out. FWIW, you can do the first two items you mention using the Apache Commons IOUtils class in Java. The latter is part of Java: http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileInputStream.html http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileInputStr...