Page 1 of 1

[Implemented] Command system getting 'messy'?

Posted: Fri Apr 16, 2004 1:05 pm
by Kris_a
Hi,

Before you go mad at me, please hear me out :D

Since #PB_ANY came out, I think that a lot of commands have become obselete, yet they get used anyway. In particular, Use<something>().

For example:

Code: Select all

x = OpenFile(#PB_ANY,"c:\boot.ini")
y = OpenFile(#PB_ANY,"c:\pbidetest2.rtf")

While Eof(x) = 0 And Eof(y) = 0
   Debug ReadString()
Wend
In this code it's obvious to see that readstring() will read from stream Y, but how on Earth do I get it to read data from Stream X without opening it again?
Usefile(x) and UseFile(y) don't work for this, and they sound like the only way to do it.

I think it would be a lot easier and logical to refer to everything by a returned handle, possibly removing the whole 'ID table' system:

Code: Select all

x = OpenFile("c:\boot.ini")
y = OpenFile("c:\pbidetest2.rtf")

While Eof(x) = 0 And Eof(y) = 0
   Debug ReadString(x)
   Debug ReadString(y)
Wend
I know this brings backward-compatibility issues, but it wouldn't exactly be hard to sift through an old program and convert it to this sort of system. Backward-compatibility seems to be what makes Microsoft's programs so big, bloated and buggy.

The same general rule applies to things like directories. The other day I tried to make a recursive directory browser in PB. I ended up with a bunch of "UseDirectory()" calls in completely illogical (at first glance) places, just to get it to work, whereas in Blitz (sorry to bring this up, but it's true) I could just refer to each directory with a handle that expired once it dropped out of scope, so I didn't have to worry about it again.

Don't get me wrong, I love the PB language, it just seems that there's a lot of power being left out because of this system, and although the system has changed, the artifacts of the old one are still there.

-Kris

Posted: Fri Apr 16, 2004 1:14 pm
by freak
UseFile() doesn't work with a #PB_Any file?
That sure is a bug then.

btw, i vote for both ways..

The UseXXX() way is pretty good when you have to work with the same
object with several commands, then you won't have to specify the 'object'
on each function you call for it.. just one UseXXX() before and you're done.

The direct access way is good when you mix them a lot. For example read
a line from one file and write it to another.

So the ReadString( [File] ) would just be a optional parameter. No backward
compatibility issue then.


Some commands allready support that (like WindowID), and afaik, this
is planned to be added for every command.

Timo

Posted: Fri Apr 16, 2004 1:35 pm
by Dare2
Hi Kris_a,

Fred has made a fix for useFile(returnedID), a download from the update folder is available.

Posted: Fri Apr 16, 2004 5:06 pm
by blueznl
i vote for both options to make the use of the language more flexible

Posted: Fri Apr 16, 2004 7:27 pm
by Karbon
Both, if nothing else for backwards compatibility.

Both, and apply across all PB

Posted: Fri Apr 16, 2004 9:28 pm
by USCode
I agree, both would be nice for backwards compatibility but at a higher level, Kris_a is asking that this apply throughout PB.

I've never liked any of the Use...() functions and would much prefer the clarity of specifying exactly which object I'm calling a function for as a parameter to that function, rather than setting a "current" reference using the Use...() functions. Not to mention it makes it easier to avoid some tough bugs.

This would apply to any functions that are dependant on any of the Use...() functions, such as:
UseDatabase
UseFont
UseWindow
etc. etc.