2 ms·
That’s not language, but ecosystem. And I much prefer this to randomly breaking previously working code.
by kaba0 3y ago
That’s not language, but ecosystem. And I much prefer this to randomly breaking previously working code.
- riku_iki 3y agoits standard library. core ecosystem, e.g. apache commons will add several more ways.
- kaba0 3y agoIO has so many usecases that frankly, it makes sense. In a way a language with only one way of doing it is missing out on some another use case.
- riku_iki 3y agopython and c++ both have the same API for 20-30 years I think, and they are both more robust than Java's APIs imo for 95% of cases.
- kaba0 3y agoAgree to disagree on that one. Java’s standard library is one of the best stdlibs out there.
- riku_iki 3y agoEvidence of opposite in that example: programmers in 95% cases want something like following to read lines from text file: for s in open('file.txt'): print(s) Java has 5 different io APIs and no one provides such construct, you need to stack various verbose abstractions to just read text file. How it is the best? Ergonomics and brain load is very bad.
- Gibbon1 3y agoI'm mostly write embedded code. But when I have to deal with files and associated API's I'm always like why does anyone tolerate this stuff. string[] lines = ReadFile("path", "filename"); Why is the above somehow hard?
- riku_iki 3y agoactually your code is not well designed too: - it will produce OOM if file is very large - iterating array is usually verbose in many of languages (at least in Java) - not sure why you would want to have path and filename as separate params In Java, it would be more ergonomical if they add something like following: Iterable<String> Files.readAllLines(String fileName);
- kaba0 3y agoHow is OOM not a concern in case of C++, python? Java’s List is much more ergonomic that arrays. Also, I really don’t understand your last example - that’s literally available in java returning a List of lines. If you add a .stream().collect(joining(“\n”)), you get the whole string in one go.
- riku_iki 3y ago> How is OOM not a concern in case of C++, python? I think in python it will lazely iterate through the file, and not load everything at once > Java’s List is much more ergonomic that arrays. right, but commenter above proposed array.. > that’s literally available in java returning a List of lines. current API has two issues: - OOM if file is large - it takes Path instance which you need to construct and not "String file" parameter, thus hit on ergonomics
- kaba0 3y agoPath.of(yourString)
- 3y ago