Page 1 of 1

Readfile()

Posted: Tue Dec 06, 2016 3:40 pm
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?

Re: Readfile()

Posted: Wed Dec 07, 2016 2:46 pm
by Fred
I agree, but it's history now and will broke almost every PB code written.

Re: Readfile()

Posted: Wed Dec 07, 2016 4:46 pm
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...

Re: Readfile()

Posted: Wed Dec 07, 2016 9:46 pm
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...

Re: Readfile()

Posted: Wed Dec 07, 2016 10:29 pm
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...

Re: Readfile()

Posted: Thu Dec 08, 2016 12:00 am
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.

Re: Readfile()

Posted: Thu Dec 08, 2016 12:45 am
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.

Re: Readfile()

Posted: Thu Dec 08, 2016 2:04 am
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

Re: Readfile()

Posted: Thu Dec 08, 2016 3:34 am
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:

Re: Readfile()

Posted: Thu Dec 08, 2016 8:11 am
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:

Re: Readfile()

Posted: Thu Dec 08, 2016 10:44 am
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:

Re: Readfile()

Posted: Thu Dec 08, 2016 10:50 am
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()

Re: Readfile()

Posted: Thu Dec 08, 2016 9:43 pm
by Mistrel