Page 1 of 1

WriteStringN() extra parameter

Posted: Sat Aug 31, 2019 9:29 pm
by IdeasVacuum
We need an extra parameter to specify line ending type - CR, LF and CRLF

Re: WriteStringN() extra parameter

Posted: Sat Aug 31, 2019 10:07 pm
by Sicro

Re: WriteStringN() extra parameter

Posted: Sun Sep 01, 2019 2:45 pm
by Josh
Dude has already written in this topic why this wish is unnecessary.


It would make more sense to have a command that writes a string with a terminating 'Null' character.
E.g. WriteStringT for 'Write String Terminated'.

Re: WriteStringN() extra parameter

Posted: Sun Sep 01, 2019 5:43 pm
by Sicro
Josh wrote:Dude has already written in this topic why this wish is unnecessary.
It is not unnecessary to propose alternative solutions, just because there is already a solution. Perhaps there are better, clearer solutions than the built-in solution.
Josh wrote:It would make more sense to have a command that writes a string with a terminating 'Null' character.
E.g. WriteStringT for 'Write String Terminated'.
Such a command / flag would be good, too.

Re: WriteStringN() extra parameter

Posted: Sun Sep 01, 2019 11:23 pm
by kenmo
I like optional flags and small features that make it simpler to achieve common tasks...

But I don't get this one, it just makes it longer to type common commands?

Code: Select all

WriteString(File, Text$ + #CRLF$)
; or
WriteString(File, Text$, #PB_File_CRLF)

WriteStringN(File, Text$)
; or
WriteString(File, Text$, #PB_File_SystemEOL)

It can be easily macro'ed, like

Code: Select all

Macro WriteStringCRLF(File, Text, Format = #Null)
  WriteString((File), Text + #CRLF$, (Format))
EndMacro

Macro WriteStringLF(File, Text, Format = #Null)
  WriteString((File), Text + #LF$, (Format))
EndMacro

Re: WriteStringN() extra parameter

Posted: Sun Sep 08, 2019 6:18 pm
by Sicro
Originally, this thread is about an extra parameter for WriteStringN(). My linked thread is about WriteString().

In the beginning the wish of my thread was exactly the same as in this thread. The command description in the PB help for WriteString() tempts you to use the WriteStringN() command if you want a new line after the string:
PB help wrote:To write a string including a newline sequence, use the WriteStringN() function.
After further considerations, I then revised my first post in my thread. My thought was: Why is another function WriteStringN() necessary, which differs only very slightly from the function WriteString(). Isn't it enough to just add another flag to WriteString()? Besides the existing constants there has to be another constant #PB_File_SystemEOL or #SystemEOL and the function WriteStringN() is no longer needed.

But the removal of a programming language command that exists since a long time is very serious, because many existing codes do not work anymore due to such a change.

The best option is, I think, to leave the commands as they are, and only the description of the command WriteString() should be improved. There should be a hint that WriteString() can also be used when a new line should be appended after the string. Unlike the WriteStringN() function, newline formats other than the operating system standard are also possible.

Some people will think that such a hint is ridiculous, but sometimes such simple solutions do not come to mind. So it would be good if the command description pointed this out and didn't confuse with just a reference to WriteStringN().

Re: WriteStringN() extra parameter

Posted: Sun Sep 08, 2019 10:04 pm
by BarryG
Sicro wrote:But the removal of a programming language command that exists since a long time is very serious, because many existing codes do not work anymore due to such a change.
It's just a quick one-minute search/replace with any given tool to fix that for all sources in a folder. Not a serious problem at all.

And PureBasic has made us do this countless of times in the past, when command names have changed (MD5FingerPrint is one off the top of my head).

Re: WriteStringN() extra parameter

Posted: Sun Sep 08, 2019 11:04 pm
by skywalk
It is better to reduce the number of commands. But search and replace would require more thought here.