Best [ractice to describe complex type value that can be null

50 views
Skip to first unread message

Алексей Винокуров

unread,
Mar 30, 2016, 2:03:49 PM3/30/16
to Haxe
I wonder what's "officially" recommended for something like this

function getComplexType():ComplexType

in case that sometimes returned value can be null. Is Null<ComplexType> returned type preferable to describe that value can be null or it leads to some runtime issues and type inference drawbacks. For example static extension doesn't recognize such nullable type as "clean" first argument.

Gama11

unread,
Mar 31, 2016, 11:43:25 AM3/31/16
to Haxe
The standard library sometimes uses Null<T> as self-documentation in that way, that's probably as "official" as it gets. There are several instances of this in haxe.macro.Expr for example: https://github.com/HaxeFoundation/haxe/blob/3.2.1/std/haxe/macro/Expr.hx#L182

Stephane Le Dorze

unread,
Mar 31, 2016, 5:56:13 PM3/31/16
to Haxe
If you do not want to miss some 'null' values, then wrap that with an Option, it's safer at the cost of some (small?) overhead.

function getComplexType():Option<ComplexType>

Laurence Taylor

unread,
Apr 1, 2016, 1:27:38 AM4/1/16
to haxe...@googlegroups.com

You can also try stx_maybe, which is an abstract type over Null<T>

https://github.com/0b1kn00b/stx_maybe

haxelib install stx_maybe

using hx.Maybe;

regards,
Loz

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages