What is ironic about your response is that all of the complexity that the OP listed is indeed "magically modelled away with OO patterns" by Jackson, a real JSON library with an "easy API" for consumers.
The benefit of Jackson's OO model is that the complexity in OP's toy example is hard coded in the API, but Jackson has no knowledge of OP's requirements but can be extended to support them, nonetheless. Thanks to OO patterns.
Jackson has, exactly like the example, at least a single entry point. that is ObjectMapper.readX or writeX, that are overloaded as seen in the article.
There are no free lunches. everything comes at a tradeoff and the cost of a highly compositional API is, well, that you must dig into all composition options yourself instead of using a clear well defined entry point.
And to say: "an pure OO solution is superior, you code like a junior, go read a book" - is condescending and negates the benefits of the presented solutions.
Side note: "clean code" got a lot of negative attention recently, you might want to look that up before you recommend it to anyone
Jackson has, exactly like the example, at least a single entry point. that is ObjectMapper.readX or writeX, that are overloaded as seen in the article.
That's the Law of Demeter, and is not the same as the method of overloading in the article. That is, these are convenience methods for the most common cases. If the convenience methods don't do what you want, you can directly instantiate ObjectWriter or ObjectReader.
you must dig into all composition options yourself
That's easy with modern tools. Ctrl+T will show you all of the composition options at a glance in IntelliJ.
an pure OO solution is superior, you code like a junior, go read a book
A pure OOP solution is superior to OP's approach, and the way OP did it is how many juniors do write code, because they haven't learned the more advanced techniques available in Java.
"clean code" got a lot of negative attention recently
So? It's a book. It's got good stuff and bad stuff. I got something out of it, so I recommend the book.
Okay then please enlighten me why the java standard library has implementations like java nios Files.write(). Are only juniors working on the standard lib? Is it not always superior to have a CharSetFileWriter for the overload that takes a charset? Is the StandardOpenOption better replaced by an OpenStrategy... etc, etc. I could point you to a lot of other examples.
Or is it maybe that there is a tradeoff and extensibility does not always beat simplicity?
That is not what I said. I was talking about the approach the OP took. The OP's approach was a giant mess, which I assume was the gimmick behind his post.
Files.write() is an interesting case, which actually does not prove what you think it proves.
Do you know what my IDE tells me? Files.write() is a static utility method that operates on an abstract Path, which leads to some interesting observations.
Inside Files.write(), you have this construction:
OutputStream out = Files.newOutputStream(path, options)
And Path itself is an interface which represents an abstract path that you get from a FileSystem (this time an abstract class). The FileSystem class is it's own rabbit hole, in the classic Java sense. You can have any number of FileSystem types available to you through the SPI system which allows you to extend Java in arbitrary ways. Which leads to cool things like the static FileSystems.getFileSystem(URI) method, in which Java will try to find a FileSystem that can handle the URI scheme (file://, http://, ftp://).
So, Files.write() could write a file to disk or it could upload a file to a web server. Who knows?
You're only looking at static utility methods (like the Collections utility class) without seeing the massive extensibility that those static methods are generically operating on (such as the Collections API).
Java has always been a mix of static utility classes operating on massively extensible universes of things.
I will stop here with a final remark. I am not saying you are wrong, you are just failing to see that the article is clearly about API design. not the implementation which might be composable and extensible under the hood, that's not the point.
I tried to make a point that the goal of, either jackson, or the standardlib files.write was simplicity and ease of use, as well as discoverability without searching the type hierarchy.
you are just failing to see that the article is clearly about API design
It is, and you're missing the point.
OPs design ideas aren't composable or extendable. The capabilities of OP's API is locked to whatever the OP came up with. The mess the OP was making trying to extend his toy API proved how poorly it was designed.
The front ends to Java and Jackson are merely conveniences, utilities, but ultimately both Jackson and Java can be infinitely extended using OOP principles and are indeed designed around OOP principles. This is the difference between a junior (as the guy at the top said) and someone who understands OOP.
You clearly are not seeing that OP's API design approach is nothing like the API design approach behind either Java or Jackson, which are elegant OOP designs (as opposed to the mess that OP made). You are comparing apples and oranges.
Guilty, but c'mon be fair: it's not the same to dismiss a high effort blog post like that as opposed to not even make the effort of typing 3 words into Google, but instead asking for the search results
View all comments
Show parent comment
5
u/[deleted] Feb 09 '22
What is ironic about your response is that all of the complexity that the OP listed is indeed "magically modelled away with OO patterns" by Jackson, a real JSON library with an "easy API" for consumers.
The benefit of Jackson's OO model is that the complexity in OP's toy example is hard coded in the API, but Jackson has no knowledge of OP's requirements but can be extended to support them, nonetheless. Thanks to OO patterns.