News for hackers. Stuff that matters.
Re:Crystal 1.0 – What to expect by benbristow on Monday March 22, 2021 @03:57PM (#26545993)
> No Nulls

Does it not? It has 'nil', just like Ruby. Basically the same thing, the docs literally say it's 'similar to null in other languages'.

https://crystal-lang.org/reference/syntax_and_semantics/lite...

Re:Crystal 1.0 – What to expect by TylerE on Monday March 22, 2021 @03:59PM (#26546027)
It has a Nil type, not a Nil Value.

So a function might return an Int or a Nil, but if you then try to, say, invoke a function expecting an Int on a Nil, it predictably blows up. An Int cannot be Nil itself.

Re:Crystal 1.0 – What to expect by mumblemumble on Monday March 22, 2021 @04:16PM (#26546303)
To expand on that, Crystal's Nil goes hand-in-hand with its union types. So, if you want to allow a function's argument to be either an integer or nil, then the parameter type is "Int | Nil".

It's not entirely unlike how algebraic data types with a "None" case work in the ML family of languages.

Re:Crystal 1.0 – What to expect by KMag on Tuesday March 23, 2021 @03:02AM (#26551908)
In other words, it avoids "Tony Hoare's billion dollar mistake" in conflating reference types and optional types. Tony Hoare had a gut feeling that it was going to cause code messiness when he made all references reference nullable in Algol W (instead of going through and adding extra type rules and tracking for nulls), but it was a very simple change to the compiler's type checker. It was too hard to resist such a simple change that made the language more flexible, even if it introduced footguns.

In most languages without ML-like type systems, null is treated as a "bottom type", as if it were a subclass of all classes. This violates the Liskov substitution principle and results in an unsound type system.

When I was working on Google's indexing system, I was very excited to hear rumors that Ken Thompson and Rob Pike were working on a new language. When it was unveiled, I was pretty disappointed to learn that it repeated Tony Hoare's billion dollar mistake.

Re:Crystal 1.0 – What to expect by eyelidlessness on Monday March 22, 2021 @11:12PM (#26550596)
I think it would be more straightforward to say expressions (/bindings/return types etc) can be null, but not implicitly so, and must be checked for a value before attempting to use the value. Or as a sibling comment said, in TypeScript terms, `strictNullChecks`.
Re:Crystal 1.0 – What to expect by brundolf on Monday March 22, 2021 @09:02PM (#26549670)
Or TypeScript, for a more well-known example
Re:Crystal 1.0 – What to expect by nielsbot on Tuesday March 23, 2021 @01:40AM (#26551490)
I think ad-hoc union types is one of TypeScript's best features.
Re:Crystal 1.0 – What to expect by straight-shoota on Monday March 22, 2021 @04:00PM (#26546044)
More accurately would be "no surprising nulls at runtime". If a value can be `nil`, the compiler forces to treat it as nilable. It doesn't throw random null pointer exceptions.
Re:Crystal 1.0 – What to expect by Shoop on Monday March 22, 2021 @04:00PM (#26546043)
It looks like it has nullable (nilable) types [0]. So a variable cannot be nil unless it is explicitly marked as having a nilable type.

[0] https://crystal-lang.org/reference/syntax_and_semantics/type...