Defsng etc versus _Define
#1
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
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Reply
#2
Maybe because _define supports some of the newer data types and DefStr and the like don't?
Reply
#3
"_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.
Reply
#4
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.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Reply
#5
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
Reply
#6
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.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Reply




Users browsing this thread: 2 Guest(s)