Comments (5)
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.
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.
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.
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.
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)
- Unified Condition Expressions HOT 1
- panic: enum value and `is` HOT 3
- Extending the reach of enums HOT 1
- `toStringHex` and `toStringBinary` strip off leading zeros HOT 1
- Consider turning asserts in @test annotated methods into soft asserts
- Allow defining and calling methods without parentheses
- `--emit-ast` doesn't do anything HOT 2
- The JIT implementation of dora is very cool HOT 1
- reinstate class syntax
- replace `fn` keyword with `fun` keyword
- reinstate `=` for function definition
- implement named parameters
- implement string hash caching
- implement definitional enums
- implement modules (singletons and holders of static functions)
- remove unary operators
- remove bitshift operators
- implement unified condition expressions
- replace procedure syntax with functions having return type `Unit` HOT 1
- How lazy compilation is protected in case of multiple threads? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dora.