buglet (nitpick/oldman) compiling with enableexplicit

Just starting out? Need help? Post your questions and find answers here.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

buglet (nitpick/oldman) compiling with enableexplicit

Post by jassing »

Code: Select all

EnableExplicit

x+1
"robot mode" reads "you must declare this variable"
so I dutifully issue:

Code: Select all

declare x
I think the error should be "Must be defined" not declared
User avatar
Demivec
Addict
Addict
Posts: 4281
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: buglet (nitpick/oldman) compiling with enableexplicit

Post by Demivec »

For reference, Declaration vs. Definition: https://en.m.wikipedia.org/wiki/Declaration_(computer_programming)

In PureBasic you formally declare a variable when you use a keyword for declaration and specify the variable's name and type. The keywords that can be used are Define, Global, Protected, Threaded, Static, and in some respects Shared. Collections of variables of the same type can be declared using Dim, NewList and NewMap. Variables can also have an initial value defined or assigned, i.e. Global notDone = #True.

In PureBasic the terms 'declare' and 'define' are used kind of interchangeably. This is similar to how the terms 'procedure' and 'function' are also used interchangeably. There is a more distinctive use of the terms 'declare' and 'define' with respect to other items such as procedures. I think because of this stronger relationship with procedures there is the direct use of the keyword 'Declare' associated with procedures.

When 'EnableExplicit' is not used then every use of a variable name is treated as a self declaration, whether intentional or not. Because each use of a variable is only checked against its first informal use it can allow in additional and separate undesired variables to be created simply by typographical errors.

IMHO, since 'Define' is only one of the possible keywords that may be used to address the error I think it should be left using the word 'declare'. Perhaps the error would be clearer as "you must formally declare this variable" or "you must explicitly declare this variable".
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: buglet (nitpick/oldman) compiling with enableexplicit

Post by jassing »

I think it's bad form referencing 3rd party sites for definitions, when documentation doesn't use those definitions.
In purebasic, you define a variable, declare a procedure
Demivec wrote: Wed May 22, 2024 3:23 amIn PureBasic the terms 'declare' and 'define' are used kind of interchangeably.
Interesting. For me, if I try:

Code: Select all

declare x
;    or 
define myProcedure()
I get errors. So not so interchangeable...

I guess I'm just old... No worries. Just when the ide says "declare <something>" using "declare" doesn't work.
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: buglet (nitpick/oldman) compiling with enableexplicit

Post by BarryG »

I agree with Jassing. You can't use "Declare varname" in PureBasic, so the error message should say "You must use Define with new variables" or such.
User avatar
Demivec
Addict
Addict
Posts: 4281
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: buglet (nitpick/oldman) compiling with enableexplicit

Post by Demivec »

As a preface, I do not have any worries about this issue. Fred will do what Fred will do. I am just supporting the things I originally stated with documentation to better illustrate that what I said was not merely an opinion but was supported by the help file documentation.



jassing wrote: Wed May 22, 2024 3:49 am
I think it's bad form referencing 3rd party sites for definitions, when documentation doesn't use those definitions.
As stated it was for reference and to save some time and make for brevity (which I'll abandon at this point). It's also bad form to poo poo my references without making any of your own to documentation. I agree to play by your groundrules and will demonstrate what I said using only PureBasisc's help manual. :mrgreen:

Here are the 5 + 1 relevant portions of the manual dealing with variables where I've bolded the words 'declare', 'declared', 'declaring' and 'declaration' in green, bolded the word 'defined' in purple, and underlined any keywords such as 'Define' in red.
In purebasic, you define a variable, declare a procedure
Reference #1: https://www.purebasic.com/documentation/reference/variables.html
Variables declaration

To declare a variable in PureBasic, simply type its name. You can also specify the type you want this variable to be. By default, when a data type is not indicated, the data is an integer. Variables do not need to be explicitly declared, as they can be used as "variables on-the-fly". The Define keyword can be used to declare multiple variables in one statement. If you don't assign an initial value to the variable, their value will be 0.
Reference #2:
https://www.purebasic.com/documentation/reference/define.html
PureBasic help entry for 'Define' wrote:Alternative possibility for the variable declaration using Define.
Reference #3:
https://www.purebasic.com/documentation/reference/protected.html
PureBasic help entry for 'Protected' wrote:Protected allows a variable to be accessed only in a Procedure even if the same variable has been declared as Global in the main program. Protected in its function is often known as 'Local' from other BASIC dialects. Each variable can have a default value directly assigned to it. If a type is specified after Protected, the default type is changed for this declaration. Protected can also be used with arrays, lists and maps.
Reference #4:
https://www.purebasic.com/documentation/reference/static.html
PureBasic help entry for 'Static' wrote:Static allows to create a local persistent variable in a Procedure even if the same variable has been declared as Global in the main program. If a type is specified after Static, the default type is changed for this declaration. Static can also be used with arrays, lists and maps. When declaring a static array, the dimension parameter has to be a constant value.
Reference #5:
https://www.purebasic.com/documentation/reference/threaded.html
PureBasic help entry for 'Threaded' wrote:Threaded allows to create a thread based persistent variable, arrays (except multi-dimensional arrays), lists or maps. This means every thread will have its own version of the object. This is only useful when writing multithreaded programs. If a type is specified after Threaded, the default type is changed for this declaration.

Each variable can have a default value directly assigned to it, but it has to be a constant value. Threaded initialization is done at thread first start. That implies when declaring and assigning a threaded variable in the same time, the variable is assigned for all threads. See example 2. When declaring a threaded array, the dimension parameter has to be a constant value.

A Threaded object can't be declared in a procedure, its scope is always global.

Demivec wrote: Wed May 22, 2024 3:23 amIn PureBasic the terms 'declare' and 'define' are used kind of interchangeably.
Interesting. For me, if I try:

Code: Select all

declare x
;    or 
define myProcedure()
I get errors. So not so interchangeable...
I would point out I said 'terms' not keywords.
Here is a reference to illustrate the point I was making. I actually have just this one entry where define and declare are intermingled. It is the exception as all of the previous references only described declaring variables not defining variables.
Reference #6:
https://www.purebasic.com/documentation/reference/global.html
PureBasic help entry for 'Global' wrote:Global provides the ability for variables to be defined as global, i.e., variables defined as such may then be accessed within a Procedure. In this case the command Global must be called for the according variables, before the declaration of the procedure. This rule is true everywhere except in a single case: The modules do not have access to the global declared variables outside this module. Each variable may have a default value directly assigned to it. If a type is specified for a variable after Global, the default type is changed through the use of this declaration. Global may also be used with arrays, lists and maps.
The error text actually reads: "With 'EnableExplicit', variables have to be declared: x."
All of the above manual references clearly state what declaring means and the various keywords that are used to do so. None of the first five define a variable but instead delcare a variable. The last reference uses both of the terms define and declare interchangeably.
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: buglet (nitpick/oldman) compiling with enableexplicit

Post by BarryG »

:shock: Wow, I didn't intend for you to make such a colorful reply. Sorry man!
User avatar
Demivec
Addict
Addict
Posts: 4281
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: buglet (nitpick/oldman) compiling with enableexplicit

Post by Demivec »

BarryG wrote: Wed May 22, 2024 8:20 am :shock: Wow, I didn't intend for you to make such a colorful reply. Sorry man!
It's just easier to scan. I know people don't have the time to read too many things. It also makes for an easy reference if anyone is also bugged by similar things. Everyone comes from a different background before using PureBasic for the first time. Why and why not are common questions. :)
Post Reply