Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Here's another....file I/O difficulties.
#17
Let me quote myself: "For scoped variables, yes" Wink

Note that FB is not a OO language. When it is, maybe it's good. But now, it can be puzzling. Imagine that you, by mistake, declare the same variable twice in two distant points in the same "visible zone". The compiler will complain on the second, and you'll have to examine your code line by line to find out where the first was.

Note that declaring a static variable and giving it a value is not a waste, no matter where it is declared/initialized. It is allocated on a static data "segment" (to call it somehow) at compile time, so that means that:

Code:
DIM a AS INTEGER

IF foo THEN
   INPUT a
   a = a + 7
END IF

Code:
IF foo THEN
   DIM a AS INTEGER
   INPUT a
   a = a + 7
END IF

Will take the same space and be as fast. A different thing is dynamic structures, but I'd rather declare them on top, then initialize them when needed. That way you, at a sight, have all the stuff controlled. No need to fetch every variable declaration accross thousands of lines of code.

A very different thing is the scoped usage of variables in OO languages, or even pseudo OO ones. For example, a loop index variable is really handy to be declared in the very loop, for example in Java:

Code:
for (int i = 0; i < 100; i ++)
{ ... }

In that case, you know that "i" will be int just inside the brackets. But in fB, if you do:

Code:
DIM i AS INTEGER
FOR i = 0 TO 99
   ...
NEXT i

After the loop, i keeps being defined as integer. Unless I am missing something Big Grin
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Messages In This Thread
Here's another....file I/O difficulties. - by Anonymous - 01-10-2006, 01:26 PM
Here's another....file I/O difficulties. - by na_th_an - 01-10-2006, 03:47 PM
Here's another....file I/O difficulties. - by DrV - 01-16-2006, 03:08 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)