Jump to content

Initialisation of variables


Recommended Posts

Hello again!

 

When looking at the resulting JS it seems that SMS will initialize most / all variables implicitly. There's nothing wrong with that (apart from some performance considerations but i'm not sure they would apply here).

 

Anyway, i'm getting compiler warnings that does not 100% match when i let it implicitly initialize. In Delphi, for example, some (locals) variables are initialized and others are not (fields?). The warning are utterly important here because an uninitialized variable that happened to become 0 during development might not during deployment.

 

In Java the once changed the initialisation if integer. I think it was between version 5 and 6. I remember feeling sorry for my Java-coding colleagues. Not the best thing to do after a couple of years when code bases are around, methinks.

 

So to the point: Do we have a "chart" or an absolute definition on SMS behaviour regarding this now and in the future?

 

TIA,

 

/Dany

Link to post
Share on other sites

Regarding performance considerations:

 

Typically it is wise to pin a variable upon installation to a certain type. This generally helps the JS engines to JIT-compile better code.

 

Regarding pre-initialization, I'm not sure if there is a chart available. This said, the underlying DWScript only uses a few types such as Integer, Float, String, Variant and classes. From what I've seen the primitive types are always pre-initialized with zero. For the latter I don't know. There might be a few more like records, arrays, 'class of' types and such.

Link to post
Share on other sites

OK, i see. Thanks for the additional info.

Typically it is wise to pin a variable upon installation to a certain type.

Do you mean

var a = 0;

instead of

var a;
...
a = 0;

when you write "pin"?

 

 

IMO SMS should always try to generate as efficient JS code as possible.

 

 

That asked and said, do you agree that this should be formalised and documented? And do you agree with my sentiment regarding the warnings?

 

TIA,

 

/D

Link to post
Share on other sites

Sorry, I meant '...during instanciation...' where I was referring to JS code in particular.

 

The DWScript code gen does the pinning already itself, so it doesn't matter whether you write

var a: Integer;

or

var a := 0;

Both will add the variable to the start of your function and pre-initialize it.

 

 

 

 

IMO SMS should always try to generate as efficient JS code as possible.

 

The underlying DWScript compiler does this already. Sorry that my comment was misleading here. In fact you can't really alter what it does.

 

It would be nice to have this documented, but only so that people are aware of this.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...