Git Product home page Git Product logo

Comments (8)

mikera avatar mikera commented on September 26, 2024

On a similar vein, I don't think Printer should extend Closeable either.....

from edn-java.

bpsm avatar bpsm commented on September 26, 2024

The question is a more general one: do we want to expose checked exceptions, or not? I'm not a great fan of them, actually. Initially Parser did not throw checked exceptions. This changed, when I eliminated my home-grown Input abstraction and just had Scanner work directly on instances of Reader (which throws checked exceptions).

As currently designd, Parser and Printer are like the rest of the IO classes: they throw checked IOExceptions and they are Closeable. This is ugly, but it is idiomatic (Java).

I'll give the alternative of wrapping IOExceptions in a (subclass of) EdnException a try on a private branch and see if I like it better.

from edn-java.

mikera avatar mikera commented on September 26, 2024

I'm so-so about checked exceptions themselves: they are annoying sometimes but in other cases can be useful when you want to really ensure that users handle important error cases.

I think the underlying issue here is that Parser and Printer shouldn't be depending on IO: this is "complecting" the concept of a parser / printer with an implementation detail (i.e. the use of readers / writers than may perform IO)

My view is that the API design would be better if we could abstract the interface away from the concrete implementation details. You could still have a Parser backed by a Reader as the default concrete implementation (perhaps this would any IOException in an EdnException), but the door would be open to other implementations.

from edn-java.

bpsm avatar bpsm commented on September 26, 2024

Yes your previous comment hits on exactly what's wrong with checked exceptions: they leak implementation details into the public interface. I'll see what can be done by returning to my original idea (of exposing only unchecked exceptions at the public APIs).

from edn-java.

bpsm avatar bpsm commented on September 26, 2024

One advantage of going the idiomatic route (IOException, Closeable) does occur to me: Parser and Printer should play nicely with Java-7's try-with-resources.

from edn-java.

mikera avatar mikera commented on September 26, 2024

Sure we want to work nicely with try-with-resources, but that doesn't mean that Parser and Printer need to expose that detail: it should be the caller's job to use try-with-resources on whatever Reader / Writer is passed to the factory function to initialise the Parser / Printer.

from edn-java.

bpsm avatar bpsm commented on September 26, 2024

I've pushed the branch topic/issue-11 which removes checked exceptions from the public APIs of Parser and Printer.

from edn-java.

bpsm avatar bpsm commented on September 26, 2024

see also follow up issues:
#14
#15

from edn-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.