Readfile()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Readfile()

Post by Josh »

Brain to eyes
Hey eyes, please be so kind and read the code for me from screen

Eyes to brain
.... .... ....
.... .... ....
.... ReadFile ....
.... .... ....

Brain to eyes
Eyes, please stop and read again

Eyes to brain
.... .... ....
.... .... ....
.... ReadFile ....
.... .... ....

Brain to eyes (louder)
EYES, ARE YOU DRUNKEN? IT'S NOT POSSIBLE TO READ FROM FILE AT THIS POINT IN THE CODE

Eyes to brain (sad)
Sorry brain, but that's written here *sniff*

Brain to eyes (embarrassed and quietly)
Sorry eyes, I have forgotten, that this crazy command 'ReadFile' does not read from file, but it's opening a file
Sorry Fred, but to use ReadFile() for opening a file is so curious that I stumble as I read the code over and over again. Is it possible to replace it with a flag in the OpenFile() command?
sorry for my bad english
Fred
Administrator
Administrator
Posts: 16686
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Readfile()

Post by Fred »

I agree, but it's history now and will broke almost every PB code written.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Readfile()

Post by kenmo »

I prefer the existing command ReadFile(Num, File) (meaning "Open File For Reading") over OpenFile(Num, File, #PB_File_Read) :)

Also it makes sense if you consider

Code: Select all

If ReadFile(0, "test.dat")
  ReadString(...
  ReadByte(...
EndIf
as meaning
If I can read file "test.dat" then
Read this string...
Read that byte...
User avatar
Tenaja
Addict
Addict
Posts: 1949
Joined: Tue Nov 09, 2010 10:15 pm

Re: Readfile()

Post by Tenaja »

Fred wrote:I agree, but it's history now and will broke almost every PB code written.
You could make OpenFile() a replacement command, where ReadFile will be obsolete, and removed after any code using it won't work anyway...
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2071
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Readfile()

Post by Andre »

I agree with kenmo - "open file for reading" is my understanding of it (maybe cause I'm no native english speaker... :wink:), and as long as the OpenFile() docs are linking to the ReadFile() command I see no need for a change...
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Readfile()

Post by Mistrel »

I actually quite partial to the Read/Open paradigm. It's easy to remember and I don't have to hunt for the right constant every time I want to read a file immutably.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Readfile()

Post by netmaestro »

I like ReadFile(), it's very self-explanatory and I've never gotten confused and tried to write in one. If this is a vote, I vote it stays unchanged.
BERESHEIT
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Readfile()

Post by StarBootics »

netmaestro wrote:I like ReadFile(), it's very self-explanatory and I've never gotten confused and tried to write in one. If this is a vote, I vote it stays unchanged.
Same here, in fact since OpenFile() instruction can be used to read and write to a file, I never used it.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Readfile()

Post by TI-994A »

Josh wrote:...to use ReadFile() for opening a file is so curious that I stumble as I read the code...
I agree that the lexical theme is broken and is contextually not intuitive. It is only logical to assume that the Readxxx() commands perform similar functions, but only on different data types (ie. ReadFile to read a file, ReadString to read a string, ReadInteger to read an integer, and so on).

However, as Fred had said, such a change would break backward compatibility. One possible solution would be to add a read-only flag to the OpenFile() function, while maintaining the ReadFile() function for legacy apps.

Alternatively, since it's only a matter of readability, consider implementing an aliasing macro, or even procedure. Reduce the stumbling! :lol:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Readfile()

Post by Dude »

Josh wrote:to use ReadFile() for opening a file is so curious
Why is it curious? It's perfectly logical and makes sense. You're reading the file's content... can't get any more simple or logical than that. :shock:
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Readfile()

Post by TI-994A »

Dude wrote:Why is it curious? It's perfectly logical and makes sense. You're reading the file's content...
But it's not reading anything; it's just opening the file in read-only mode. :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Readfile()

Post by Josh »

Dude wrote:Why is it curious? It's perfectly logical and makes sense. You're reading the file's content... can't get any more simple or logical than that. :shock:
Sorry Dude (and some others), I thought programmers had a logical understanding :mrgreen:


It's all other than logical and makes absolutely no sense. It is only curios. Look at other keywords, like:

ReadAsciiCharacter
ReadByte
ReadCGI
ReadCharacter
ReadConsoleData
ReadData
ReadDouble
ReadFloat
ReadInteger
ReadPreferenceDouble
ReadPreferenceFloat
ReadPreferenceInteger
ReadPreferenceLong
ReadPreferenceQuad
ReadPreferenceString
ReadProgramData
ReadProgramError
ReadProgramString
ReadQuad
ReadSerialPortData
ReadString
ReadStringFormat
ReadUnicodeCharacter
ReadWord

That's not only with Read..., that's the same with few hundred other examples, like:

CopyArray
ClearConsole
OpenConsole
CreateDialog
CreateDirectory
RenameFile
.......

They all have the same scheme and this is also common in other programming languages. If a double word is used:
- The first part is the verb and says what this function will do
- Followed by the noun that the verb supplements

The only one in Pb (maybe there are some others) doesn't fit with this scheme is ReadFile()

Fred wrote:I agree, but it's history now and will broke almost every PB code written.
I know, that it's not possible to remove Readfile(), but maybe it's possible to make a additional flag in OpenFile() and make a remark like you did at the Help for CountList()
sorry for my bad english
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Readfile()

Post by Mistrel »

Post Reply