File commands extended

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

File commands extended

Post by TerryHough »

I would like to suggest that the File commands be extended to use a
#File parameter, such as

Code: Select all

WriteData(#File, *MemoryBuffer, LengthToWrite)
which would replace

Code: Select all

UseFile(#File)
WriteData(*MemoryBuffer, LengthToWrite)
This is a lot more intuitive, I believe. Now it is too easy to forget that the
"current file" has changed and that leads to bugs. Spent most of the
morning tracking down that exact situation.

I realize this change would break existing code, but perhaps this could
be included in the upcoming Vs 4.0.

Many of the File commands need this change. This change would
  • make them consistent with the ones that already require the #File parameter
    deprecate the need for the UseFile(#File) command
I find that

Code: Select all

; psuedo code
OpenFile(10,"Example.txt")
OpenFile(20,"Insert.txt")
OpenFile(30,"Rewrite.txt")
While Eof(10) = 0
  Text$ = ReadString(10)
  ; manipulate the data to your heart's content
  WriteStringN(30,Text$)
  Text$ = ReadString(20)
  ; manipulate the data to your heart's content
  WriteStringN(30,Text$)
Wend 
CloseFile(10)
CloseFile(20)
CloseFile(30)
is more consistent and easier for me to understand than

Code: Select all

; psuedo code
OpenFile(10,"Example.txt")
OpenFile(20,"Insert.txt")
OpenFile(30,"Rewrite.txt")
While Eof(10) = 0
  UseFile(10)
  Text$ = ReadString()
  ; manipulate the data to your heart's content
  UseFile(30)
  WriteStringN(Text$)
  UseFile(20)
  Text$ = ReadString()
  ; manipulate the data to your heart's content
  UseFile(30)
  WriteStringN(Text$)
Wend 
CloseFile(10)
CloseFile(20)
CloseFile(30)
especially when the manipulation portions of the code are many lines
and/or procedures separated.

Thanks,
Terry
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

I agree.
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

so do I.
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Would be nice. And needn't break old code.
  • WriteData( [#file,] *MemoryBuffer, LengthToWrite)

Code: Select all

WriteData(*MemoryBuffer, LengthToWrite)   ; -- use last active file ID.
WriteData(#File, *MemoryBuffer, LengthToWrite)
works for all file operations (except usefile(#File)). :)
@}--`--,-- A rose by any other name ..
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

I agree. Then it will be thread safe
Dummy
Enthusiast
Enthusiast
Posts: 162
Joined: Wed Jun 09, 2004 11:10 am
Location: Germany
Contact:

Post by Dummy »

Dare2 wrote:WriteData(*MemoryBuffer, LengthToWrite) ; -- use last active file ID.
Better:

use last ID set by UseFile(#File)
Post Reply