Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DIM - AS - VARIABLE TYPE likely bug
#12
(05-03-2024, 07:15 PM)Kernelpanic Wrote: @bartok - I don't want to offend you, but are you sure that programming is right for you?
I have now looked at your questions and comments, and in my opinion, since 2022 until today, you haven't understood that programming has nothing to do with philosophical considerations.
Quote:Sometimes to chose a solution rather then an other could be a philosofical issue, but sometimes is not.
https://qb64phoenix.com/forum/showthread...ght=bartok
My humble recommendation: Buy a book about what programming means, such as: Code Complete, Version 1

The standard work on programming

Thank's you for answering here to an other topic written elsewhere, with an aswer that would have been OT even if answered there. Programming is not my work. However, its your opinion that programming has nothing to do with philosophical considerations.

(05-03-2024, 07:48 PM)SMcNeill Wrote:
(05-03-2024, 02:00 PM)bartok Wrote:
(05-03-2024, 12:59 PM)bplus Wrote: ah, there is no suffix for qb64 to tell the differenece between the 2 a's
this lets you define everything as a type unless you explicitly say something different
DefInt A-Z
Dim A As String
I have understood. 
IMO, QB could have been programmed in a way in which the suffix of the varible "A" definied with "DIM A AS INTEGER" was "%", as it is in the case of "DIM A%", considered that in both the ways we define exactly the same variabile. But QB is conceived so that we can have:
DIM A%
DIM A!
DIM A$
DIM A&
etc,
but we cannot have
DIM A AS INTEGER
DIM A AS SINGLE
DIM A AS STRING
DIM A AS LONG
etc.
The only reason I found for this, is that if we use "AS" instead of the suffixes, then in the code is possible to use variable name without having to add the suffix each time and, in order to be able to do that, only one "A" must be allowed.
But finally, even if at first this could seem a simplification, actually I prefer to use suffixes for 2 reasons:
1. We could have variables that actually are exactly the same thing and therefore should have the same name. For example a coordinate X, that it is integer(%) or single(!) depending if we are on a view port coordinate or in physical screen coordinate. So, using (AS) it will be compulsory to use different variable name, but I don't find anything clearer than the possibility of using X% and X!;
2. I find that presence of the suffixes actually makes the code more readable.
So, I think is preferable to DIM variables and arrays with suffixes, avoiding the use of AS.
QB is conveieved so that you can have a shortcut and reduce repetitive typing injuries to yourself.
There is absolutely nothing stopping you from doing the following:
DIM A AS INTEGER
DIM A!, A#, A%%
Now, there is absolutely nothing stopping you from using A, A%, A!, A#, and A%% all in your program.
Code: (Select All)
Dim a As Integer
Dim a!, a#, a%%
a% = 1
a! = 2
a# = 3
a%% = 4
Print a%
Print a!
Print a#
Print a%%
Print
Print
Print a
No issues whatsoever with the above.  All are DIMMED.  All are usable.
The only thing that DIM A AS INTEGER is, is telling the compiler that A -- without any suffix -- is going to be an integer and thus represent the same thing as A%, saving you the need to type that % symbol everytime you use A alone.
And A, with no suffix, can't be INTEGER, SINGLE, DOUBLE, BYTE all at the same time!!  It can only be one of them.  By default, it's SINGLE.  By using a DIM, you make it whatever you want.
That's all there is to it!
ok, but in this way I will have a code with variables with both suffixes like $, %, &, etc and variables names without suffixes: IMO this make the code less clear, because who reads the code could find an "A" and an "A%" and it is intuitive to think that they are not the same variable. In the way you said, I could also have a code with only variables with suffixes. But IMO, this is "philosophically" inelegant: to me, variables have to be DIMmed using OR the suffixes, OR using "AS". Of course, everybody is free to do what he wants to, but IMO, there are no reasons to DIM variables with "AS" if the programmer has not the intention to use the consequent faculty of writing the code without using suffexes each time, considered that in this way is not possible to have more then one "A". So, I prefer to DIM variebles with suffexes and to have a code with variables where the suffix is speciefied each time, because I think that in this way is much clearer to be read. What these considerations are, if not philosophical one? I write the code thinking about that does exist in the world someone crazy enough to read it, so I try to improuve the clarity and to avoid redundancies, waste of memory, etc. This bring to some questions about HOW to do things that could be done in much than one way. A banal example: if in a program the user can exit in many parts, then it is possible to the go to SYSTEM in many parts of the code. To me, it is forbidden: I admit ONLY one SYSTEM and the program must ends only there, after having exited ALL subroutines, routines and SELECTs, FORs, DO LOOPs cycles, etc. I must chose a way and then use only that way. These are philosophical "issues" and they affect my own decisions, but my original post was about a thing that I didn't know, considered that I thought that writing DIM A AS INTEGER was the same thing then writing DIM A% and it is not true, because if I use (only) "AS" I can't have more then one "A".
Reply


Messages In This Thread
DIM - AS - VARIABLE TYPE likely bug - by bartok - 05-03-2024, 06:59 AM
RE: DIM - AS - VARIABLE TYPE likely bug - by bartok - 05-04-2024, 02:04 PM



Users browsing this thread: 2 Guest(s)