WriteStringN() extra parameter

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

WriteStringN() extra parameter

Post by IdeasVacuum »

We need an extra parameter to specify line ending type - CR, LF and CRLF
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: WriteStringN() extra parameter

Post by Sicro »

Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: WriteStringN() extra parameter

Post 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'.
sorry for my bad english
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: WriteStringN() extra parameter

Post 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.
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: WriteStringN() extra parameter

Post 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
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: WriteStringN() extra parameter

Post 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().
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: WriteStringN() extra parameter

Post 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).
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: WriteStringN() extra parameter

Post by skywalk »

It is better to reduce the number of commands. But search and replace would require more thought here.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply