Git Product home page Git Product logo

Comments (5)

soc avatar soc commented on May 5, 2024

One additional reason is that it prevents building pure library-defined resource handling:

Consider

fun use[R : Closeable, T](resource: R, function: T -> Unit) {
    function();
    resource.close();
}
while ... {
  use(someFile, |x| { printFile(someFile); if someFile.isEmpty() { break; } } );
}

"Use do ... finally ... in the use function" would be the obvious answer, but in the long term I'd like to adopt a Rust-like approach where exceptions are only used for fatal errors that require aborting the program.

Not having break, continue and exceptions for control flow would allow us to replace finally by a pure library implementation.

from dora.

dinfuehr avatar dinfuehr commented on May 5, 2024

Haven't looked at the PR so far.

Don't get your argument here though and would be curious what I am missing here: break/continue/return only work inside the current function or closure. So the example above would fail to compile (is there missing something?). How would you implement resource handling "as a library" in Dora?

from dora.

soc avatar soc commented on May 5, 2024

Feel free to substitute break with throw; but I agree with you that it is the least compelling point listed here. Feel free to disregard it.

from dora.

dinfuehr avatar dinfuehr commented on May 5, 2024

I don't get why break/continue are different in this regard. It seems that even return would break resource handling already. How would you otherwise ensure that the close-function is run (without finally or defer)?

from dora.

soc avatar soc commented on May 5, 2024

If the intended language semantics are that break/continue/return only work inside the current closure, then they can't cause this issue; then only throw remains. As mentioned, I withdraw the point, because it detracts from the three better ones.

from dora.

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.