Hacker News new | past | comments | ask | show | jobs | submit login

It's really not. It's the equivalent of adding "asserts" to your code.



No, in Dart it's not like that at all - almost the opposite. Type annotations have absolutely no effect at runtime. As the Dart documentation[1] says, "Adding types will not prevent your program from compiling and running—even if your annotations are incomplete or plain wrong. Your program will have exactly the same semantics no matter what type annotations you add."

[1] http://www.dartlang.org/articles/optional-types/


Dart can run in production mode where type annotations have no effect, or in checked checked mode where they will trigger a runtime error (i.e. behave like an assert). So you're both right ;)


Wait what? "Adding types will not prevent your program from compiling"

So even if you type-annotate everything, you will never get compile-type type errors? That makes the whole thing seem completely pointless.


You get warnings. I guess the aim is to allow people to run their code no matter how broken it is, while still giving a way to detect some errors.

Seems pretty odd to me.


There are two execution modes for Dart: checked mode and production mode. Check mode inserts type checks for assignments and parameters. This, together with the static analysis that the Editor/analyzer does, generally works as well as full static typing, in my experience.


Types do cause runtime errors in checked mode (which is basically the default mode for other systems with optional types, like Common Lisp and Dylan).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: