BBC BASIC for Windows
« Richards response variables-one size fits all »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:53pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Richards response variables-one size fits all  (Read 522 times)
michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Richards response variables-one size fits all
« Thread started on: Apr 15th, 2016, 10:42pm »

Out of curiosity, I asked Richard about how he made LBB and what variables he used for the variables.
And as I suspected.. he used variables like
a
b
c
d
and so on.
His word on the differences between the one size fits all (memory wise) a and a% is that a, will use twice the memory of a%..
And so if you wish to use variables in the ways that other basics use, its totally fine.. ( the program will just be a memory hog)
Richard would be aware of what I was trying to point out.
I may use the flexible variable to lure other programmers from other dialects, so as to make them think its the same.

My suspicions were verified with an email I received from a user. So I think I will make my posted programs in my forum using this inefficient variable. (and state that its just not efficient, but is totally fine)
To an advanced user, they don't see it and a general true beginner would have difficulty explaining to an advanced programmer that they are confused.
Hence, they just simply wont ask... (look at the code and run away before they even try to understand it, which is what I did back in 2010-2011)

Which I suspect a certain emailer may have done.

So my approach is correct, and introducing the politically correct method later is better.

As for arrays I will need more research, as 1 program I made had raised question on the use of the array as a virtual file
( of a sort to explain that all the data was stored in an array and the array would be treated like a file)
Richard did give me some information on them. So I am studying them now.
So that I can keep my programs stable.
I have decided to keep making modules for windows and also focus on the alternative replacement windows functions for platforms that don't have windows..
I also plan to make some fully functional programs that serve purpose in business and personal data management.
I think I have an idea on how to monitor individual buttons, and still keeping them customizable for each program dialog or function use within a non windows platform and also keep the active sweep area code simple.

I do plan to use the morally correct method for my programs that are meant to be showcased as a product though, to keep them fast and efficient.
« Last Edit: Apr 15th, 2016, 11:03pm by michael » User IP Logged

I like making program generators and like reinventing the wheel
Zaphod
Guest
xx Re: Richards response variables-one size fits all
« Reply #1 on: Apr 16th, 2016, 02:48am »

Interesting!

I was trying to think what question would illicit that reply from Richard.
LBB has many times more explicitly typed integers than variants.
User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Re: Richards response variables-one size fits all
« Reply #2 on: Apr 16th, 2016, 03:16am »

I asked Richard:

It seems like in LBB, variables are one type fits all. There seems to be no restrictions. If I was working in the same generic way as in LBB for variables,how would a person do that in BBC?

Perhaps initially I was doing that, but it was probably inefficient and frowned upon. (although I still, after studying BBC variables, and understanding their storage
uses, do not quite understand why its so important to not use the most flexible variables for a program.)

Why is it so important for a type of variable you declare?

Does using a variable like

a

use more resources than

a%

Is there something that can be compromised if say a programmer decided to use just the most flexible variable style for everything?

******************************************
And that was the end of the main question to Richard.

Reflecting on this, he stated that if anyone needed clearity on the subject of this subject, that they ask him.

He did go into a lot more depth as to the details on other variables too, but in short, it just was ok if a person decided to use variables like this, and didn't lesson the value of the other variable types...

I am not trying to lessen the value of other variable types. I am just trying to clear this up.
It can be extremely simple.
« Last Edit: Apr 16th, 2016, 03:39am by michael » User IP Logged

I like making program generators and like reinventing the wheel
Zaphod
Guest
xx Re: Richards response variables-one size fits all
« Reply #3 on: Apr 16th, 2016, 4:28pm »

OK, to keep it simple, strict typing allows for ease of maintenance of a program and the ability to use Windows API structures since we don't have the AS keyword in BB4W. This latter point is important since that is the way that BBC BASIC for Windows interfaces with Windows. Take a look at the supplied libraries.

For simple programs variants are fine. You just have to be a little more careful with comparisons of variants and implied conversions. That is to say that you get integer results when you want one and not a near integer floating point result. But you already know how to deal with that from LB so if the warnings are given to the beginner and the right precautions taken in the code, use variants by all means.

For larger programs it might be useful to consider using the strict data types for clarity of the code. With a% you can be 100% certain it contains an integer. With a variant type you cannot be sure just by observation. It tends to lead the programmer to make incorrect assumptions sometimes, that then bite you in the rear. You would never write IF a=b unless you can be sure neither a or b has had any chance of becoming an floating point by some previous operation. You might write IF a%=b%.

The aim should be code that is clear, concise and bug free. If you can get that we are all happy.




User IP Logged

DDRM
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 321
xx Re: Richards response variables-one size fits all
« Reply #4 on: Apr 16th, 2016, 4:36pm »

Hi Michael,

If you (or anyone else interested) wants to know more about the variable types and how they are used in memory, it's all in the manual.

The variables without a suffix (like a) are called variants - which means they can behave in various ways. BB4W is relatively unusual in that if they are integers, calculations with them will use integer arithmetic, which is much faster.
As you have noted, the price you pay is that they are much bigger: in BB4W 6 and beyond, they take up 10 bytes of memory, while an integer (a%) only takes up 4.

You may not care about that, but if you are implementing a Seive of Eratosthenes for finding prime numbers up to 1000 million, suddenly it starts to look significant (and indeed I chose to use byte variables (a&) which only use one byte - though even a single bit is enough for that purpose).

Another place where it may be important is if you are setting up a data structure to pass to a SYS call: for example, for the Windows colour picker Zaphod recently put up. In these cases it is CRUCIAL that the right types of variables are used, since the Windows functions will take the next 4 bytes (or whatever), regardless of what you put in there - so things can quickly get out of position if you give it a variant instead of an integer.

The bottom line is that for "straightforward" BB4W uses, it doesn't make much difference whether you use a variant or an integer for things where you want an integer, but there are times when making more sophisticated choices may be useful.

Hope that's useful, and not too inaccurate! Zaphod may want to tear it to bits...

Best wishes,

D
User IP Logged

Zaphod
Guest
xx Re: Richards response variables-one size fits all
« Reply #5 on: Apr 16th, 2016, 5:40pm »

Quote:
Zaphod may want to tear it to bits..

Not at all.
From a Best Practices Tutorial I came across recently I saw this:
Quote:
If you want to become a novelist, can you just start writing novels? I would say 100% no!!, you definitely need to read hundreds of novels before you start writing GOOD novels. If you want to become a movie script writer, can you start writing good movie scripts until you have gone through various good movie scripts?, again my answer would be no!!
Reading Source Code
So, if you want to write a good software code, then how it will be possible for you to write a good source code without reading tons of source codes? Even if you will write something, then how would you and know which the best is?

Reading source code written by others gives you opportunity to criticize the mistakes done in writing that code. You will be able to identify the mistakes other software developers have done in their source code which you should not repeat.

For BB4W Richard, and others have written some outstanding code, read and learn.
In the context of this thread see how they use variants.


User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls