Page 1 of 3

Disallow use of '$' when it isn't part of a variable name

Posted: Tue Nov 06, 2012 5:24 am
by Demivec
I noticed that it is possible to use '$' as the 'type' specification with various keywords.

Code: Select all

Procedure$ test()
  ProcedureReturn "second"
EndProcedure

Define$ a

a = "first"

Debug a
Debug test()
Even though '$' and '.s' are the same type it seems strange that they can be used interchangeably in these instances. This is due in part to the fact that '$' would normally be a required part of a variable name but isn't in these instances.

It would make more sense to disallow the use of '$' in these instances to declare the type when it is not directly associated with a variable name.

Re: Disallow use of '$' when it isn't part of a variable nam

Posted: Tue Nov 06, 2012 9:44 am
by IdeasVacuum
.... I think it would make sense to discontinue the use of $ completely. Using .s is more consistent.

Re: Disallow use of '$' when it isn't part of a variable nam

Posted: Tue Nov 06, 2012 10:16 am
by ts-soft
IdeasVacuum wrote:.... I think it would make sense to discontinue the use of $ completely. Using .s is more consistent.
+ 1

Re: Disallow use of '$' when it isn't part of a variable nam

Posted: Tue Nov 06, 2012 12:53 pm
by luis
IdeasVacuum wrote:.... I think it would make sense to discontinue the use of $ completely. Using .s is more consistent.
I disagree. I use $ everywhere for example and I like it over .s because I can see immediately where I'm using a string without using the usual notations or prefixes. It's so different from the other types (all numbers in the end) that's a plus for me any time I look through my code. I use it even in lists and maps names for the same reason.

Change it now would be criminal anyway. Simply don't use it and hate me when you read some of my code.


I don't have any problem with the original request though (even if it seem coherent to me... and maybe other people is using that form), as long I can still use $ in variables names.

Re: Disallow use of '$' when it isn't part of a variable nam

Posted: Tue Nov 06, 2012 1:11 pm
by MachineCode
Luis is right. There are two data types: numeric and string. There has to be a quick way to see which is which when reading code.

Re: Disallow use of '$' when it isn't part of a variable nam

Posted: Tue Nov 06, 2012 1:41 pm
by Fred
Don't worry, it's not going to change :)

Re: Disallow use of '$' when it isn't part of a variable nam

Posted: Tue Nov 06, 2012 1:49 pm
by IdeasVacuum
There has to be a quick way to see which is which when reading code.
Are you seriously suggesting that you can't see ".s" amongst ".i", ".d", ".f" ? I think there is sufficient difference between those letters to differentiate :mrgreen: In any event, it is good practice to prefix your vars with the type letter - if you don't, then it's actually the numerical values that could cause confusion, given MyVar.i, MyVar.d and MyVar.f. With a prefix, there is no doubt about type later in the code when the type specifier is dropped: sMyVar, iMyVar, dMyVar, fMyVar.

Hey ho, each to his own, I just see MyVar$ as ugly - it's not clear if it's a new var or a predefined one.

Re: Disallow use of '$' when it isn't part of a variable nam

Posted: Tue Nov 06, 2012 2:07 pm
by MachineCode
IdeasVacuum wrote:Are you seriously suggesting that you can't see ".s" amongst ".i", ".d", ".f" ?
No, I mean after the initial declaration. You only need to have "value.s" once, and then refer to it as "value" everywhere after. So if you read code later in a procedure that says "value", it doesn't indicate if it's a string or numeric. But as you said, you can prefix it with "s" for "sValue" to indicate... or do as I prefer, and append "$" at the end for "value$".

Re: Disallow use of '$' when it isn't part of a variable nam

Posted: Tue Nov 06, 2012 4:49 pm
by Golfy
MachineCode wrote:
IdeasVacuum wrote:Are you seriously suggesting that you can't see ".s" amongst ".i", ".d", ".f" ?
No, I mean after the initial declaration. You only need to have "value.s" once, and then refer to it as "value" everywhere after. So if you read code later in a procedure that says "value", it doesn't indicate if it's a string or numeric. But as you said, you can prefix it with "s" for "sValue" to indicate... or do as I prefer, and append "$" at the end for "value$".
+1
and any basic language should have $ for string, else it would be Pascal, dot.Net, C, C#... :mrgreen:

Re: Disallow use of '$' when it isn't part of a variable nam

Posted: Tue Nov 06, 2012 6:21 pm
by skywalk
I also prefer the '$' in my string variable names.
And I'd like to go a step further...
Enable simultaneous use of Ascii and Unicode Strings!

Code: Select all

Define.s myAscii$    = "1byte/char"
Define.s myUnicode$$ = "2bytes/char"
If I want to use Unicode strings in a listviewgadget or stringgadget, but not in my entire app, I am forced to compile with Unicode and do lots of Unicode to Ascii conversions with the majority of my code. Or can I compile in Ascii and somehow pass Unicode formed memory to the listviewgadgets or stringgadgets?

Apologize if this is off topic?

Re: Disallow use of '$' when it isn't part of a variable nam

Posted: Tue Nov 06, 2012 6:30 pm
by Guimauve
Hello everyone,

When the syntax of a programming language that allows something we do not like, it is our responsibility to discipline themselves and write code in a way that seems right.
Personally this is the list of element I don't like in PureBasic because I consider them as an extremely bad practices :
  • The use of "$" for string variable and constants definition
    The use of "With/EndWith" on structures and interfaces
    The use of ":" to put many instructions on the same line
    The use of "Global" variables, arrays, linked lists and maps (I use them only when I really have no alternative, it's extremely rare !)
    The use of "EnableExplicit"
So I don't use them but when I take a code given by someone in the forum and I see the elements from the black list, I take time to completely review the code in question.

Best regards
Guimauve

Re: Disallow use of '$' when it isn't part of a variable nam

Posted: Tue Nov 06, 2012 7:05 pm
by netmaestro
I like it just as it is.

Re: Disallow use of '$' when it isn't part of a variable nam

Posted: Tue Nov 06, 2012 7:46 pm
by rsts
Fred wrote:Don't worry, it's not going to change :)
Thank you.

Re: Disallow use of '$' when it isn't part of a variable nam

Posted: Tue Nov 06, 2012 8:02 pm
by Guimauve
netmaestro wrote:I like it just as it is.
As I do ! Because the only important thing is the final compiled programs.

Best regards
Guimauve

Re: Disallow use of '$' when it isn't part of a variable nam

Posted: Tue Nov 06, 2012 11:18 pm
by Regenduft
Disallow use of '$' when it isn't part of a variable name
Why should such things be disallowed, if it is simply possible to just not use it (like I also do)? :? I guess there are no circumstances where this will lead to a hard to find bug, but it gives PureBasic some sweet flavor for some people.
(But it would be nice, if this possibility would be mentioned in PureBasics documentation!)

Concerning the '$' in variable names: Same goes here, if you don't like it, then just don't use it! I would get a step futher and allow '$' as the part of a procedure names, if it's returning a Strings! But I guess this is not going to come. (This would trigger much to many flame wars... :wink:)