Basic question on correct language format

Discuss the Firewing language

Basic question on correct language format

Postby Timbo » Mon Mar 23, 2015 8:21 pm

Hi,

Is there a best syntax for coding in Firewing?

For example you can dim your variables outside of a your main code loop, or in the middle of it. I did that in one section and included = 0 to initialize it to a starting value. But then found every time the code went past that line it set the var to 0, so it was not really initialising it, it was more a command.

I can code, (reasonably well) but I'm old school, from using Proton, all variables are up top (no local vars), initialise them in a initialize sub then all my subs and main loop at the bottom.

I'm finding now that I'm spending more time worrying about how it should be laid out and not actually writing code.

So can anyone point me to some resource that explains best practice how to layout my routines, where to place the var declarations, even when to make a routine a module and better still on how to properly cater for all the var types.

Many thanks in advance for any tips.

Thanks
Tim
Timbo
 
Posts: 93
Joined: Fri May 03, 2013 7:51 pm

Re: Basic question on correct language format

Postby Coccoliso » Mon Mar 23, 2015 10:55 pm

Firewing syntax takes all the advantages of structured programming and in particular very much like vb.net so in the case of the declaration and initialization of a variable must be taken at the scope.
A variable declared inside a loop or an if / endif is valid only in the cycle or if / endif.
If declared at the beginning of a sub is only valid within the same.
In a module if declared PRIVATE, even if it remains active for the duration of the module, is visible only within the same module while if PUBLIC is also visible from the caller module.
In this way they isolate the processes and especially the very limited memory allocation.
Take a look at http://www.firewing.info/pmwiki.php?n=Firewing.Reference for all.
User avatar
Coccoliso
 
Posts: 177
Joined: Sat Sep 27, 2014 10:02 am

Re: Basic question on correct language format

Postby David John Barker » Tue Mar 24, 2015 9:50 am

Just to add, try checking out

http://www.firewing.info/pmwiki.php?n=Reference.Scope

> I did that in one section and included = 0 to initialize it to a starting value. But then found every time the
> code went past that line it set the var to 0, so it was not really initialising it, it was more a command.

Without seeing a code example it's difficult to determine what you mean. However, I suspect something like
Code: Select all
while <something is true>
   dim x as byte = 0
   <some code>
end while


here, the variable is declared within the scope (block) of the while loop and visible only inside the while loop. Each time the loop is executed, it's value it set to zero. Because the variable is only visible inside the loop, you could have

Code: Select all
while <something is true>
   dim x as byte = 0
   <some code>
end while
dim x as byte = 10

the second "x" is declared outside the loop, so has different visibility.

If this is all too much for you, then keep it simple. Declare all the variables you are going to use at the top of your function or subroutine. For example,
Code: Select all
sub MySub(value as byte)
   dim a as byte = 0
   dim b as byte = 10
   dim c as byte = 30
   < now write your code>
end sub

In the above example, the variables are only initialised when the subroutine is called.

Has this cleared things up for you? Please just ask if you are still stuck or give an example piece of code that is giving you problems.
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: Basic question on correct language format

Postby Timbo » Tue Mar 24, 2015 12:28 pm

Thanks David and Coccoliso

That is just what I'm looking for. I really appreciate the effort to point me to what I should have already found.

I will read it all several times to make sure it sticks in my head.

Tim
Timbo
 
Posts: 93
Joined: Fri May 03, 2013 7:51 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 2 guests

cron

x