Quick scripting variable question

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
ivan
Posts: 577
Joined: 02 Apr 2008 12:52
Contact:

Quick scripting variable question

Post by ivan »

Before my variables in scripting were identified like this

Code: Select all

%variable_name%
with the recent changes in 7.60 should I know rename them to this

Code: Select all

$variable_name
for scripts to work?
Windows Vista Business SP1 32-bit, Logitech MX400 mouse, SetPoint 4.60.122
Image

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Quick scripting variable question

Post by TheQwerty »

Yep, the new rules for variables are:
1) They must start with a $.
2) The rest of their name may only contain letters, numbers, and underscores.
3) They are case-sensitive.

ivan
Posts: 577
Joined: 02 Apr 2008 12:52
Contact:

Re: Quick scripting variable question

Post by ivan »

TheQwerty wrote:Yep, the new rules for variables are: 1) They must start with a $.
Thank you for the confirm. Would have been nice to have XY auto-convert the %variable_name% parts in auto mode, but I'm guessing something like that would have brought up headaches that I can't think of straight away.
Windows Vista Business SP1 32-bit, Logitech MX400 mouse, SetPoint 4.60.122
Image

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: Quick scripting variable question

Post by jacky »

TheQwerty wrote:Yep, the new rules for variables are:
1) They must start with a $.
2) The rest of their name may only contain letters, numbers, and underscores.
3) They are case-sensitive.
Almost! ;) Actually the first character (after $) must be a letter or underscore, no numbers allowed there. Only then can you use letters, numbers & underscores.
Proud XYplorer Fanatic

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Quick scripting variable question

Post by PeterH »

jacky wrote:Almost! ;) Actually the first character (after $) must be a letter or underscore, no numbers allowed there. Only then can you use letters, numbers & underscores.
Sorry, Don: if the first char is a $, this restriction for the following, that is for the second char should not be needed? Or am I wrong?

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: Quick scripting variable question

Post by jacky »

PeterH wrote:
jacky wrote:Almost! ;) Actually the first character (after $) must be a letter or underscore, no numbers allowed there. Only then can you use letters, numbers & underscores.
Sorry, Don: if the first char is a $, this restriction for the following, that is for the second char should not be needed? Or am I wrong?
Nothing is needed per-se, Don makes the rules. And here he choose to mimic PHP (more or less), where, and it's a common thing, numbers as first chars of the variable name are not allowed.
Proud XYplorer Fanatic

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Quick scripting variable question

Post by PeterH »

jacky wrote:Nothing is needed per-se, Don makes the rules. And here he choose to mimic PHP (more or less), where, and it's a common thing, numbers as first chars of the variable name are not allowed.
You are right with respect to the first char - but I've talked about the second. (The first is "$".)

As I understand, the restrictions are for recognition of the beginning of a variable name. (So in a special sense "per-se"? That is: for a logical need, not just for the wish of the author?) But if that "beginning of name" is recognized by the $, I'd expect a shifted-to-second-char convention should not be needed? Or am I wrong for some other technical detail?

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: Quick scripting variable question

Post by jacky »

PeterH wrote:
jacky wrote:Nothing is needed per-se, Don makes the rules. And here he choose to mimic PHP (more or less), where, and it's a common thing, numbers as first chars of the variable name are not allowed.
You are right with respect to the first char - but I've talked about the second. (The first is "$".)

As I understand, the restrictions are for recognition of the beginning of a variable name. (So in a special sense "per-se"? That is: for a logical need, not just for the wish of the author?) But if that "beginning of name" is recognized by the $, I'd expect a shifted-to-second-char convention should not be needed? Or am I wrong for some other technical detail?
Well, I said "variable name" because how it works/the way I see it, is we have the prefix "$" as variable identifier, followed by the variable name. Which is why when I said the first char of the variable name, I was actually referring to the first one after the "$" sign.

And yes, Don could technically allow for numbers to be used as first char in variable names, just like he could allow for other special chars in their names (e.g. dots, etc), it's just a common convention that variable names should begin with letters (& underscores) only, no numbers, so it makes sense to use the same rules in XYS as well. Usually you want your variable names to be meaningful, and it's hardly the case when beginning with a number I guess...
Proud XYplorer Fanatic

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Quick scripting variable question

Post by PeterH »

jacky wrote:
PeterH wrote:
jacky wrote:Nothing is needed per-se, Don makes the rules. And here he choose to mimic PHP (more or less), where, and it's a common thing, numbers as first chars of the variable name are not allowed.
You are right with respect to the first char - but I've talked about the second. (The first is "$".)

As I understand, the restrictions are for recognition of the beginning of a variable name. (So in a special sense "per-se"? That is: for a logical need, not just for the wish of the author?) But if that "beginning of name" is recognized by the $, I'd expect a shifted-to-second-char convention should not be needed? Or am I wrong for some other technical detail?
Well, I said "variable name" because how it works/the way I see it, is we have the prefix "$" as variable identifier, followed by the variable name. Which is why when I said the first char of the variable name, I was actually referring to the first one after the "$" sign.

And yes, Don could technically allow for numbers to be used as first char in variable names, just like he could allow for other special chars in their names (e.g. dots, etc), it's just a common convention that variable names should begin with letters (& underscores) only, no numbers, so it makes sense to use the same rules in XYS as well. Usually you want your variable names to be meaningful, and it's hardly the case when beginning with a number I guess...
Sorry: what do you want to tell me?

I think it's possible, that Don, when changing var-names from almost "no rules" to $-prefixed, he maybe missed to see that the special rule for the first character after the $ ("not to be numeric") was not necessary. Maybe I'm right, maybe he has a reason I didn't see. He even could say he just loves this extra-rule, I don't know.
If he missed it, he could change it, else he could simply tell me, why.

But if I understand it correct, it seems you ask me not to ask him? I don't understand that.

admin
Site Admin
Posts: 66515
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Quick scripting variable question

Post by admin »

PeterH wrote:
jacky wrote:
PeterH wrote:
jacky wrote:Nothing is needed per-se, Don makes the rules. And here he choose to mimic PHP (more or less), where, and it's a common thing, numbers as first chars of the variable name are not allowed.
You are right with respect to the first char - but I've talked about the second. (The first is "$".)

As I understand, the restrictions are for recognition of the beginning of a variable name. (So in a special sense "per-se"? That is: for a logical need, not just for the wish of the author?) But if that "beginning of name" is recognized by the $, I'd expect a shifted-to-second-char convention should not be needed? Or am I wrong for some other technical detail?
Well, I said "variable name" because how it works/the way I see it, is we have the prefix "$" as variable identifier, followed by the variable name. Which is why when I said the first char of the variable name, I was actually referring to the first one after the "$" sign.

And yes, Don could technically allow for numbers to be used as first char in variable names, just like he could allow for other special chars in their names (e.g. dots, etc), it's just a common convention that variable names should begin with letters (& underscores) only, no numbers, so it makes sense to use the same rules in XYS as well. Usually you want your variable names to be meaningful, and it's hardly the case when beginning with a number I guess...
Sorry: what do you want to tell me?

I think it's possible, that Don, when changing var-names from almost "no rules" to $-prefixed, he maybe missed to see that the special rule for the first character after the $ ("not to be numeric") was not necessary. Maybe I'm right, maybe he has a reason I didn't see. He even could say he just loves this extra-rule, I don't know.
If he missed it, he could change it, else he could simply tell me, why.

But if I understand it correct, it seems you ask me not to ask him? I don't understand that.
Indeed the only reason for this is that PHP has it, too! I guess PHP has it because it's a long and widespread tradition that variables do not begin with numbers. You are right, having a $-prefix this seems unnecessary, at least I don't see any reason for it. But maybe there is one... I have no problem in this case with sticking to the tradition.

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: Quick scripting variable question

Post by jacky »

PeterH: Sorry, was a bit tired I guess and I didn't see you wanted to ask Don directly :oops:, I was just trying to help, using what Don said before (here & on changelog) when he implemented those changes, that's all.

As for why variable names don't begin with numbers, I'd say it's probably because it's common to say they should be meaningful and that usually means begin with a "word" of some kind, or at least letters. Just look at your folders, how many of them do begin with numbers? Probably not that much... (Plus, don't $42, $3rd_path or $2 + 3 look odd? :roll:)
(Plus, you got (consistency with) those languages without prefix, how else would they tell apart variable and actual numbers?)
Proud XYplorer Fanatic

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Quick scripting variable question

Post by PeterH »

admin wrote:Indeed the only reason for this is that PHP has it, too! I guess PHP has it because it's a long and widespread tradition that variables do not begin with numbers. You are right, having a $-prefix this seems unnecessary, at least I don't see any reason for it. But maybe there is one... I have no problem in this case with sticking to the tradition.
Just for my understanding: PHP does not use the $-prefix? (Should I learn a bit of PHP?)
You say, you don't have a problem with sticking to this tradition: that's understandable - for you. But look at your users: you must tell them, that there is a special rule for the "first" char: no number allowed, for all others it is! You could save a rule here - as you said: without a problem. That's all I wanted to say: I started writing my idea, when I read the "extra"-post just describing this "extra" rule...
jacky wrote:PeterH: Sorry, was a bit tired I guess and I didn't see you wanted to ask Don directly :oops:, I was just trying to help, using what Don said before (here & on changelog) when he implemented those changes, that's all.

As for why variable names don't begin with numbers, I'd say it's probably because it's common to say they should be meaningful and that usually means begin with a "word" of some kind, or at least letters. Just look at your folders, how many of them do begin with numbers? Probably not that much... (Plus, don't $42, $3rd_path or $2 + 3 look odd? :roll:)
(Plus, you got (consistency with) those languages without prefix, how else would they tell apart variable and actual numbers?)
No problem with it - just wanted to stop this and go to bed...
Just to you samples - and some extension: in a syntax with varnames not needing a prefix, I would interpret 7 as a (numeric) constant, not as a varname. But in some situation I would not be afraid to use a variable $7 - this is very different for me.
Nobody would have to use such names, but it wouldn't be necessary to explain, that it's not allowed. I think, that would be an advantage, isn't it? (And Don said, that it would be no problem - as I expected.)

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: Quick scripting variable question

Post by jacky »

PeterH wrote:Just for my understanding: PHP does not use the $-prefix? (Should I learn a bit of PHP?)
Yes it does. Just to add a quick thing about allowing numbers as first char of a variable name : allowing vars such as $2 would also create a big mess dealing with regexp, obviously.
Proud XYplorer Fanatic

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Quick scripting variable question

Post by PeterH »

jacky wrote:
PeterH wrote:Just for my understanding: PHP does not use the $-prefix? (Should I learn a bit of PHP?)
Yes it does. Just to add a quick thing about allowing numbers as first char of a variable name : allowing vars such as $2 would also create a big mess dealing with regexp, obviously.
Just did it: read some hours about PHP...
...very bad. :roll:
Bad for me - as I'm used to work with quite a different syntax. :evil:
But to tell the truth: both PHP and REXX are good, and have some different advantages. For example I think REXX is a bit better "readable", (usage of {}, where REXX uses do/end, ...) while PHP has some fine (but a bit dangerous?) abbreviations ($var++, ...) So I think selection here is just a matter of "taste", and what you are used to.
A bit of problem with PHP could be, that it's main usage seems to be generating (html-) code - not calling functions of some "external system" like XY. But I can be wrong here...
Bigger problem, from my point of view: I looked at PHP in very general way, that is, to a lot of functionality, and think it's good. But how long will it take, till Don brought all this into XY? If he can do that at all? (Not because of his skills - just because of his time...) That's why I still think of the advantage of including an "external" scripting system - it seems that would be like scripting level 12...

So much to PHP. And if Don uses it as a model, I think it's ok to use it's naming conventions, as they are. Including, for vars, the $ and first char non-numeric...
So I may get involved with some PHP-syntax. But sorry: no regular expressions :oops: For these it seems you need a special kind of thinking, and/or must use them very much to get familiar with. And it's something I want to miss :wink: And as I'm still thinking REXX, where a string (like '$7') is a string, and as such can be given to any external function "just as it is", I don't understand the problem. But I think that doesn't matte in the moment.

admin
Site Admin
Posts: 66515
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Quick scripting variable question

Post by admin »

PeterH wrote:
jacky wrote:
PeterH wrote:Just for my understanding: PHP does not use the $-prefix? (Should I learn a bit of PHP?)
Yes it does. Just to add a quick thing about allowing numbers as first char of a variable name : allowing vars such as $2 would also create a big mess dealing with regexp, obviously.
Just did it: read some hours about PHP...
...very bad. :roll:
Bad for me - as I'm used to work with quite a different syntax. :evil:
But to tell the truth: both PHP and REXX are good, and have some different advantages. For example I think REXX is a bit better "readable", (usage of {}, where REXX uses do/end, ...) while PHP has some fine (but a bit dangerous?) abbreviations ($var++, ...) So I think selection here is just a matter of "taste", and what you are used to.
A bit of problem with PHP could be, that it's main usage seems to be generating (html-) code - not calling functions of some "external system" like XY. But I can be wrong here...
Bigger problem, from my point of view: I looked at PHP in very general way, that is, to a lot of functionality, and think it's good. But how long will it take, till Don brought all this into XY? If he can do that at all? (Not because of his skills - just because of his time...) That's why I still think of the advantage of including an "external" scripting system - it seems that would be like scripting level 12...

So much to PHP. And if Don uses it as a model, I think it's ok to use it's naming conventions, as they are. Including, for vars, the $ and first char non-numeric...
So I may get involved with some PHP-syntax. But sorry: no regular expressions :oops: For these it seems you need a special kind of thinking, and/or must use them very much to get familiar with. And it's something I want to miss :wink: And as I'm still thinking REXX, where a string (like '$7') is a string, and as such can be given to any external function "just as it is", I don't understand the problem. But I think that doesn't matte in the moment.
PHP syntax is nothing special. Quoting Wikipedia: "In terms of keywords and language syntax, PHP is similar to most high level languages that follow the C style syntax."

Post Reply