3 ms·
As he notes in the comments, you'd really just do this: IOUtils.copy(System.in, System.out); using the Apache Commons library. That's the most apples-to-appl
by abalone 13y ago
As he notes in the comments, you'd really just do this:
IOUtils.copy(System.in, System.out);
using the Apache Commons library.
That's the most apples-to-apples comparison to more "scripty" languages that have more stuff built in. With Java you pick the libraries/frameworks you want to use. Commons and Guava are extremely popular and robust libraries and really should be included in any comparison against "real world" Java.
I actually like how in Java you can get down closer to the metal and control the exact buffer size if you want to, or handle all the exception cases instead of just passing them up if you want to. If you're comparing intentionally lower-level more verbose Java code to higher-level Python or whatever, that's not really apples-to-apples. High-level Java involves frameworks.
- acqq 13y agoStill, Awk and Perl need no library, the semantics was the part of the language since the beginning, and is always available to every programmer, also for the bigger programs. Awk and Sed were obvious inspirations for Perl.
- bananas 13y agoAwk and Perl are tools built on another language that does stream copying i.e. read stdin and write stdout. You could build Awk and Perl in Java if you wanted and have the same result. System.out.println("hello world"); Is the same as: printf("hello world\n");
- kamaal 13y ago>>High-level Java How is file manipulation High level. That sort of stuff should work right next after your Hello, World program. If you are telling me Java intentionally makes easy things difficult. Its the last thing I want to use to solve difficult problems.
- abalone 13y agoFile manipulation, like any kind of computer programming, can be programmed in a high-level or low-level way. High-level is easier and reflects some assumptions and opinions. Low-level gives you more control. With Java, you can choose which way you want to go, and the easier route is only as "difficult" as choosing a high-level framework.
- levosmetalo 13y agoThat's right, but it seems like it's fashionable to bash Java inventing example code that noone uses in prodcution. If I would see the code like this, I would ask the one that has written it to justify why he didn't just use IOUtils.copyStream method. Is there some performance reason he wanted to specify buffer size manually? Maybe he wanted to handle exceptions properly instead of wiling silently? Or he was on extremely constrained device where he couldn't afford to include 40k library and just copied the only method he needs instead?
- pekk 13y agoIt's not just Java that is bashed with this tactic. For example, the TechEmpower benchmarks that keep getting reposted here do the same thing, except with languages other than Java, in order to make Java come out looking better.
- abalone 13y agoThat's getting a little off topic, but the TechEmpower benchmarks are open source and open to submissions. If you see a problem and you haven't submitted a pull request then you have no excuse for complaining.