[Vala] Heads-up on upcoming non-null support
- From: Jürg Billeter <j bitron ch>
- To: vala-list gnome org
- Subject: [Vala] Heads-up on upcoming non-null support
- Date: Tue, 08 Apr 2008 19:07:21 +0200
Vala differentiates between non-null and possibly-null types by means of
the type suffix `?` since version 0.1.6. The advantages of
distinguishing between non-null and possibly-null types are
* Interface documentation for method parameters and return values
* Automatic generation of runtime checks for method parameters
* Metadata for language bindings
* Compile-time warnings when using null references to avoid
crashes
So far, Vala doesn't use the non-null type information by default, i.e.
your application will work fine even if you don't specify the `?` type
suffix for possibly-null types. That's about to change in the upcoming
0.3.x releases. Automatic generation of runtime checks for method
parameters will be enabled by default, which means that if you pass null
to a method and forget to add the `?` to the parameter type, you'll get
a critical runtime warning.
Local variables are not affected by this. Future Vala versions will be
able to infer non-null types for local variables from the code, so you
don't need to annotate types of local variables. This should keep the
amount of changes limited.
It's not decided yet which Vala release will require the `?` type suffix
for possibly-null parameter types. However, I'd recommend you to already
use it where appropriate to make it a non-issue to migrate to future
Vala versions. The syntax is already supported in Vala 0.1.6, 0.1.7, and
0.2.0, which means that your code doesn't require a more recent version
due to `?` annotations.
Short example:
public void foo (Bar bar) {
// bar is expected to be non-null
// will be enforced at run-time in future Vala versions
}
public void foo (Bar? bar) {
// bar is allowed to be null
}
Any questions or comments about this?
Jürg
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]