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?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
Readfile()
Readfile()
sorry for my bad english
Re: Readfile()
I agree, but it's history now and will broke almost every PB code written.
Re: Readfile()
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
as meaning
Also it makes sense if you consider
Code: Select all
If ReadFile(0, "test.dat")
ReadString(...
ReadByte(...
EndIf
If I can read file "test.dat" then
Read this string...
Read that byte...
Re: Readfile()
You could make OpenFile() a replacement command, where ReadFile will be obsolete, and removed after any code using it won't work anyway...Fred wrote:I agree, but it's history now and will broke almost every PB code written.
- Andre
- PureBasic Team
- Posts: 2071
- Joined: Fri Apr 25, 2003 6:14 pm
- Location: Germany (Saxony, Deutscheinsiedel)
- Contact:
Re: Readfile()
I agree with kenmo - "open file for reading" is my understanding of it (maybe cause I'm no native english speaker... ), and as long as the OpenFile() docs are linking to the ReadFile() command I see no need for a change...
Re: Readfile()
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.
- netmaestro
- PureBasic Bullfrog
- Posts: 8433
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Readfile()
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
- StarBootics
- Addict
- Posts: 984
- Joined: Sun Jul 07, 2013 11:35 am
- Location: Canada
Re: Readfile()
Same here, in fact since OpenFile() instruction can be used to read and write to a file, I never used it.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.
Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
Re: Readfile()
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).Josh wrote:...to use ReadFile() for opening a file is so curious that I stumble as I read the code...
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!
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
Re: Readfile()
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.Josh wrote:to use ReadFile() for opening a file is so curious
Re: Readfile()
But it's not reading anything; it's just opening the file in read-only mode.Dude wrote:Why is it curious? It's perfectly logical and makes sense. You're reading the file's content...
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
Re: Readfile()
Sorry Dude (and some others), I thought programmers had a logical understandingDude 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.
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()
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()Fred wrote:I agree, but it's history now and will broke almost every PB code written.
sorry for my bad english