#2362 "" or Str.defVal?

SlimerDude Tue 14 Oct 2014

Hi, I was just wondering...

Is there any benefit, performance or otherwise, of using Str.defVal over "" in Fantom code?

brian Wed 22 Oct 2014

I don't think it really matters one way or the other in HotSpot since everything will get inlined. String literals are interned on a per pod basis and then inserted directly into bytecode as a constant. The Str.defVal will be a static field access which will get inlined by HotSpot.

SlimerDude Sun 26 Oct 2014

Cool. I find I'm using Str.defVal more and more, just to break up the hyrogliphics in the code!

func := |->Str| { "" }

vs.

func := |->Str| { Str.defVal }

Though I'm not really sure it reads any better!

LightDye Sun 26 Oct 2014

I prefer the "" form not only because is shorter but mainly because its value is obvious whereas with Str.defVal one need to check the documentation.

Login or Signup to reply.