Jump to content

Initial values for list?


primerib1
 Share

You are about to reply to a thread that has been inactive for 465 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

If I declare a list variable like this:

list $Alloweds;

Shouldn't it default to empty list [] ?

The reason I ask this is because LSL PyOptimizer doesn't even try to optimize lines like this:

list EMPL = [];

So I wonder if not specifying an initial value for list variables have some dark side ...

Link to comment
Share on other sites

23 minutes ago, Wulfie Reanimator said:

All variable types are initialized to sane "zero/empty" values.

We don't have to worry about random values or real nulls.

Ah, thanks!

23 minutes ago, Wulfie Reanimator said:

P.S. Don't prefix your variables with dollar signs since it doesn't become a part of the name.

Oh I know. I just like adding that symbol to prefix my globals 😉

Link to comment
Share on other sites

5 hours ago, Love Zhaoying said:
8 hours ago, primerib1 said:

Ah, thanks!

Oh I know. I just like adding that symbol to prefix my globals 😉

I add a lower-case "g" most often.

I follow the widespread but far from universal practice of prefixing global variable with a type identifier, so vMy_Vector is a vector, strMy_String is a string, iMy_Integer is an integer, and so on.  That also helps me distinguish them from local variables, which do not have a character prefix.  I think I started using that convention during my early LSL days by emulating Void Singer (who had other, quirkier conventions that I have not adopted).   In the land of non-standard standards, that one has served me well.

  • Like 1
Link to comment
Share on other sites

10 minutes ago, Rolig Loon said:

I follow the widespread but far from universal practice of prefixing global variable with a type identifier, so vMy_Vector is a vector, strMy_String is a string, iMy_Integer is an integer, and so on.  That also helps me distinguish them from local variables, which do not have a character prefix.  I think I started using that convention during my early LSL days by emulating Void Singer (who had other, quirkier conventions that I have not adopted).   In the land of non-standard standards, that one has served me well.

For string, I also add "s".

So for "global string MyValue", it would be "gsMyValue".

The "new kids" in programming have all their fancy "camel-case", etc. etc.!

Phooey! When I was a cub, we only had upper-case!

*EDIT* And don't get me started on what these fancy Microsoft IDE's do to your class members, changing the case internally, adding underscores..it's just wrong!

Edited by Love Zhaoying
Link to comment
Share on other sites

54 minutes ago, Love Zhaoying said:

So for "global string MyValue", it would be "gsMyValue".

In which case, the "g" is superfluous.  Still, whatever helps you keep your variable straight is fair game.  This is not a company shop with a style manual.

  • Thanks 1
Link to comment
Share on other sites

3 minutes ago, Rolig Loon said:
59 minutes ago, Love Zhaoying said:

So for "global string MyValue", it would be "gsMyValue".

In which case, the "g" is superfluous.  Still, whatever helps you keep your variable straight is fair game.  This is not a company shop with a style manual.

Not at all, the "g" tells me it is global. All "local" (non-global) string variables would still get the "s". 

In this case, no reason I couldn't have a "sMyValue" locally in addition to the global "gsMyValue".

  • Like 1
Link to comment
Share on other sites

Heh I never prefixed my variables with type.

I let the linter catch type errors for me 😋

I used to prefix global vars with "g" as well, then I find out that I can prefix vars with "$" (which gets turned into whitespace) and I just do that now 😁

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 465 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...