Re: Pakistan Earthquake - September 25, 2013
Posted by Skywise on September 28, 2013 at 19:58:40:

Yes. I recall you having apprehensions about strongly typed variables before.

It's not that hard to work around. The default type is 32 bit signed integer, which does not require you to do any type assignment or use a type suffix on the variable names. You can just use "x = y * z" as always. ("LET" does not exist)

If you want floating point, it's just a simple matter to add the floating point suffix to those variables. There's both single and double precision. I default to using double precision, so the code now becomes "x# = y# * z#". ("#" being the type suffix for double precision)

95% of my programs use just these two types. Strings are also another type but that's no different than you are already used to, (a$ = "hello world"). You can predefine the types at the beginning of the program, but this gets very confusing, so it's best to always use the suffix to know what is what.

The most common mistake will be remembering the type suffix. XB will perform type coercion automatically when you mix data types.

Some examples:

y = 31
z = 15
x = y * z
PRINT x ("465" - all integers)

y# = 4.2
z# = 8.7
x# = y# * z#
PRINT x# ("36.54" - all floating)

x = y# * z#
PRINT x ("37" - x is an integer, so the result of 36.54 is rounded off to an integer)

x# = x * y#
PRINT x# ("155.4" - although x is an integer, it is coerced to a floating point for the calculation)

The other thing to remember is that "x" and "x#" are two different variables.

I think if you follow this practice like I do, limiting myself to always using a limited set of data types, you'll be ok. Only for specific circumstances, mainly user defined data types and binary data files, do I get into the other data types.

I'll admit I got messed up a lot because of this at first, and it took me a little while to get used to. But in the end, it opened up a lot of powerful control over my programs. (integer math is much faster than floating point, so if it's not needed, why use it?)

Oh, "PRINT", like all commands, is required to be all caps. That's the other thing to get used to. Function calls can be mixed case. Variables can be mixed case or even all caps so long as it's not a reserved word (like a command).

I think the next thing that would confuse you is something called "scope". Is a variable local, or global? That's defined with variable prefixes. But depending on the complexity of the program, you may not even have to worry about it at all. Many times I don't.

Even if you went to something else like C, you're going to run into these issues. TB, like most all BASICS, are exactly that... basic - simplified. They're good for what they are, though. It's always a trade off - simple easy to use vs. powerful and complex. Just a matter of where you want to be on the spectrum. (ever try machine language? wheeeee!!!)

Brian


Follow Ups:
     ● Re: Pakistan Earthquake - September 25, 2013 - EQF  22:06:31 - 9/29/2013  (100932)  (1)
        ● Re: Pakistan Earthquake - September 25, 2013 - Skywise  00:28:00 - 10/1/2013  (100936)  (1)
           ● Re: Pakistan Earthquake - September 25, 2013 - EQF  18:05:54 - 10/1/2013  (100945)  (1)
              ● Re: Pakistan Earthquake - September 25, 2013 - Roger Hunter  18:50:16 - 10/1/2013  (100946)  (0)