3 ms·
The "python hides the hurt" example isn't great. First, he's missing the imports on the python side (which can be just as verbose as java imports). Second, he's
by flavor8 9y ago
The "python hides the hurt" example isn't great. First, he's missing the imports on the python side (which can be just as verbose as java imports). Second, he's talking 10 lines of code in java (plus closing braces) vs 6 in python, but with a little bit of tweaking you could easily drop 2 of those lines in Java. Third, if you were to import guava or some other library that makes handling files more streamlined, you could get to an equivalent number of lines in the Java example.
- jpeanuts 9y ago1. The Python in that example requires no imports. 2. I think the author (Vicki) is a she.
- notamy 9y ago> Third, if you were to import guava or some other library that makes handling files more streamlined, you could get to an equivalent number of lines in the Java example. You don't even need that. The Files[1] class - which has been in the standard library since at least Java 7 - makes this really easy to do. [1] https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html https://docs.oracle.com/javase/8/docs/api/java/nio/file/File...
- depressedpanda 9y agoWhy are you optimizing the LOC only for Java? With a little bit of tweaking, Python can do the whole thing in 2 lines -- no imports, libraries or closing braces needed: with open('alice.txt') as inp, open('new_alice.txt', 'w') as out: out.write('\n'.join([line.rstrip().replace('Alice', 'Dora the Explorer') for line in inp])) The author's point is that Java is verbose and requires a lot of boilerplate, which has benefits and drawbacks. I think her example does a decent job of illustrating that.