Originally posted by tildearrow
View Post
Announcement
Collapse
No announcement yet.
AMD Is Hiring To Work On New Radeon Driver Tooling Written In Rust
Collapse
X
-
Originally posted by oleid View PostThe point is : you have to handle both cases with option, for nullable types you don't have to. And if you forgot, then bad things may happen.
I don't know if there is any difference.
Originally posted by mmstick View Post
Sadly, all of these statements are not true.
- Async methods are supported
- String interpolation is supported, though I personally prefer fomat
- Not sure if you're actually serious about Option vs null.
Comment
-
Originally posted by uid313 View PostOh, I wasn't aware of these third-party crates. Rust still doesn't natively support that without use of third-party crates though.
- Likes 2
Comment
-
Originally posted by uid313 View PostBut in some languages (such as Kotlin) you cannot pass a variable of a nullable datatype as argument to a function that accepts a non-nullable datatype.
I don't know if there is any difference.
Comment
-
Originally posted by uid313 View Post
Oh, I wasn't aware of these third-party crates. Rust still doesn't natively support that without use of third-party crates though.
Originally posted by oleid View Post
It depends, I guess. I don't know any Kotlin, so I can't tell,especially how the conversion between nullable and non-nullable happens. Maybe it is sane, maybe not.
1. Non-nullable
2. Platform-nullable
3. Nullable
And the compiler knows with absolute certainty which type any variable is.
1. Non-nullable may be coerced to both platform-nullable and nullable.
2. Platform-nullable may be coerced to non-nullable, but will incur a runtime check to verify that it is not null.
3. Platform-nullable may be coerced to nullable.
4. Nullable may never be coerced to non-nullable.
5. Nullable may be coerced to platform-nullable.
Platform-nullable is not talked about a lot. And it is not possible to explicitly declare a type as being platform-nullable. This type is only used for interfacing with the Java API, which almost never returns null values, but theoretically can. As such, the Kotlin compiler allows developers to assume that a value returned from Java is not null. The compiler will still insert the aforementioned runtime check, which will throw an exception upon failure.
- Likes 2
Comment
-
Originally posted by wswartzendruber View PostThe compiler will still insert the aforementioned runtime check, which will throw an exception upon failure.
but I imagine it could be difficult to keep track of where exceptions are thrown, at least after the 1st bigger refactoring.
Comment
-
Originally posted by wswartzendruber View PostThere are three types of nullability in Kotlin:
1. Non-nullable
2. Platform-nullable
3. Nullable
And the compiler knows with absolute certainty which type any variable is.
1. Non-nullable may be coerced to both platform-nullable and nullable.
2. Platform-nullable may be coerced to non-nullable, but will incur a runtime check to verify that it is not null.
3. Platform-nullable may be coerced to nullable.
4. Nullable may never be coerced to non-nullable.
5. Nullable may be coerced to platform-nullable.
Platform-nullable is not talked about a lot. And it is not possible to explicitly declare a type as being platform-nullable. This type is only used for interfacing with the Java API, which almost never returns null values, but theoretically can. As such, the Kotlin compiler allows developers to assume that a value returned from Java is not null. The compiler will still insert the aforementioned runtime check, which will throw an exception upon failure.
Is the Kotlin way easier than the Rust way?
Comment
-
Originally posted by oleid View PostThanks for the explanation! These automatically inserted checks sound a lot like rust's unwrap() on options and results. It is a good thing, that those 'pointers' are checked automatically,
but I imagine it could be difficult to keep track of where exceptions are thrown, at least after the 1st bigger refactoring.
So your NullPointerException is almost always going to be thrown in the block that sets the platform-nullable value in the first place.
Originally posted by uid313 View PostSo is Rust and Kotlin equally safe in regards to nullability?
Is the Kotlin way easier than the Rust way?
- Likes 1
Comment
Comment