QB64 Phoenix Edition
Defsng etc versus _Define - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: Defsng etc versus _Define (/showthread.php?tid=811)



Defsng etc versus _Define - PhilOfPerth - 08-25-2022

I'm trying to come to grips with the _Define keyword in QB64, as against the "traditional" DefStr, DefInt etc. They appear to do the same thing, but I'm sure I'm missing something, otherwise it wouldn't be there. Can someone elucidate please?   Huh


RE: Defsng etc versus _Define - James D Jarvis - 08-25-2022

Maybe because _define supports some of the newer data types and DefStr and the like don't?


RE: Defsng etc versus _Define - mnrvovrfc - 08-25-2022

"_DEFINE" is just less typing. Just saying "_DEFINE A-Z AS LONG" at the top of the program is an assumption, then declare with "DIM" whatever else you need which is string, floating point, UDT or whatever. Of course replace "LONG" with type of your choice.

But remember that if you do "_DEFINE A-Z AS LONG", or something more specific like "_DEFINE I AS LONG", then especially in the last case must make sure all variables starting with "i" are of type LONG. Only using "DIM" or using type sigil with variable name could do anything about it.

There is nothing like "DEFLNG" for 64-bit integers in QB64, must use "_DEFINE" in this case, for example "_DEFINE U AS _UNSIGNED _INTEGER64" to have all variables starting with "u" not need type sigil ~&&.

If it causes too much confusion, then avoid "_DEFINE" or the other older ones. Be glad for "_DEFINE" because other BASIC dialects don't have such a thing.


RE: Defsng etc versus _Define - PhilOfPerth - 08-25-2022

Thanks mnrvovrfc.
The _Define as LONG seems to be the only place it could be useful, but since LONG is only needed for numbers up in the trillions, I guess I'll stick with the old Def's.


RE: Defsng etc versus _Define - SMcNeill - 08-25-2022

The difference here is inclusion/exclusion of any of the new data types.

Quickly answer these few questions:

1) What's the command to change the default type to LONG?
2) What's the command to change the default type to SINGLE?
3) What's the command to change the default type to _UNSIGNED LONG?
4) What's the command to change the default type to _BYTE? or _INTEGER64?

The first two, you can do with DEFstatements (DEFLNG and DEFSNG), but with _DEFINE you can do all four commands.

Personally, I find _DEFINE to just be a little more grammatical and easier to read. _DEFINE A-Z AS LONG is a little more typing than DEFLNG A-Z, but it's also fairly well self-documenting. Let someone who has never seen the language before pick up your program and look t as a sort of pseudocode template, and ask them if they understand what each of those two lines is doing. Abbreviations only make sense to the people who understand those abbreviations. (Good example is the LOL -- laugh out loud. For the longest time, my wife would always go "AWWWWWW You're so sweet..." everytime I sent her a message with LOL attached. I found out later she thought I was calling her my Love Of Life.)

But functionally speaking, there's no more difference in DEFLNG and _DEFINE AS LONG than there is in calling a& or DIM a AS LONG. Programming has several ways to end up doing the same thing. It's generally up to the programmer to decide which method they prefer for themselves. Wink


RE: Defsng etc versus _Define - PhilOfPerth - 08-25-2022

Thanks Steve
I guess there's something to it being a bit more intuitive, and clearer to others who read your code later, but again, I don't get to share my code with others very often so it doesn't really seem that important. I s'pose I should go for clarity though, in the interest of good coding.