Var f:FooBar = new FooBar();

I sometimes see

var f:FooBar = new FooBar();

rather than

var f = new FooBar();

Given that Haxe can infer the type of f, is there any practical purpose for doing the former?

So that people can make pull requests to remove the type hint, and earn hacktoberfest gifts?

3 Likes

I mostly see the first version from people who can’t let go of their coding habits from languages without type inference, such as AS3. :wink: (myself being one of them in the beginning)

2 Likes

I personally also do this sometimes, that’s because it is more consistent sometimes:

var value:Float = 5;
var thing = new Thing();

vs

var value:Float = 5;
var thing:Thing = new Thing();

(and I notice I also do this sometimes, because HaxeDevelop gives faster completion if you use this. That’s because it also keeps track of own types)

I like this consistency more:

var value = 5.;
var thing = new Thing();
1 Like