News for hackers. Stuff that matters.
Re:Flutter desktop shells by Kiro on Thursday April 25, 2019 @11:57AM (#19749446)
What's wrong with null?
Re:Flutter desktop shells by coldtea on Thursday April 25, 2019 @12:01PM (#19749487)
Re:Flutter desktop shells by Kiro on Friday April 26, 2019 @08:49AM (#19756879)
Thanks. Stupid question but consider the following:

  entity = Entity.fetch(id)
  if (!entity) doSomething()
Entity.fetch returns null if it doesn't find anything. How would this work without null?
Re:Flutter desktop shells by ptx on Friday April 26, 2019 @02:10PM (#19760320)
You would still have null, but only when asked for and checked explicitly.

In Kotlin, for example, you mark something with a question mark to say that it can be null, which forces you to check for null before using it:

  val entityOrPossiblyNull: Entity? = Entity.fetch(id)

  if (entityOrPossiblyNull == null) {
      doSomething()
  }
  else {
      // The compiler knows that the variable is not null in this branch,
      // so this assignment is OK.
      val entityForSure: Entity = entityOrPossiblyNull

      doSomethingWithEntity(entityForSure)
  }
Re:Flutter desktop shells by wtetzner on Friday April 26, 2019 @01:44PM (#19760033)
The real problem isn't null itself, it's that in most languages that have it, null inhabits all types (or at least all reference types).

Different languages solve this problem in different ways. Many languages get rid of null entirely, and use option types in its place. Other languages, like Kotlin, fix it in the type system, by differentiating between e.g. String and nullable String (spelled String? in Kotlin) .

Re:Flutter desktop shells by coldtea on Friday April 26, 2019 @05:51PM (#19762080)
There are several ways. A popular one is an Optional type. Here's how Java does it: https://www.baeldung.com/java-optional