4 wants - simpler list, complete trim, heredoc & obfuscation
Posted: Thu Apr 07, 2016 3:47 pm
And yes, I have seen other requests for these... they would make excellent built-ins.
I hope that these are four things that would really help everyone write simpler code!
(Listed in ascending order of importance)
*** Simplified List Handling ***
Add an element to the K list should not require two statements:
AddElement(K())
K() = "New List element"
Should be allowed by:
append(k()) = "New List Element"
Same for insert...
*** We need a built in split/explode command ***
Sorry, the stringfield command is close but not enough.
We should be able to split any string into an array without
writing a subroutine each time.
And of course we need the inverse command as well:
To combine an array into a string (with or without delimiter)
The php syntax is my favorite, but the name doesn't matter:
f$() = explode(g$,"*") ; take it apart
h$() = implode(f$,"*") ; put it back together
*** Trim vs. Trimm ***
So, in newer languages, trim() gets rid of all common whitespace characters
but in purebasic, it acts in the old 1967 way. Very nostalgic for me!
I have written a function called trimm() that does
this. I think Purebasic should adopt it... then you can have old
BASIC style trim() and let newcomers use the better trimm() statement!
It should remove the following: space, tab, newline, cr and maybe
backspace or any combo of them. That way programmers coming from
modern scripting languages can adapt their code more easily. If we are
to have a huge user base, we should add such updates.
And yes, I know it's harder to do this in multibyte.
*** HEREDOC / TEXT STRINGS ***
There are 2 little issues:
a. It's painful to work with assigning big text.
b. It is painful to hide text strings from casual inspection.
FIRST, we really need support for this syntax:
f$ = "
a really long bunch of text that I want to include
and that has simple CR/LF or just CR at the end, but
you can't see it. However, I'm going to write all
this out and not worry about putting in all the a$+quote
stuff because I just want to write out my text and be done
with it"
instead of
f$ + "some words words words"
f$ + "more words words words"
AND AS WELL (and frequently asked about):
We need the ability to embed text that is somewhat obscured from
the user. It doesn't have to be super duper encryption, but the
raw text shouldn't be seen casually. And yes, I know that for real
security you must roll your own... but I only care to have a little
misdirection.
Therefore I suggest that if we can't have both, Purebasic adds a
tool like:
f$ = embed("monkeys and sheep are roller skating!")
and also
f$ = embed("
I am a long exception to how the compiler normally works
and so my text will be read until the end of the paragraph
and then saved into a buffer where we randomly xor against
the character position (so char xor pos) and now we have
unreadable text in the executable.
")
At compile time, the strings are obfuscated and handled as
normal. However, at run time, when the variable assignment is
being made, the program simply reverse the process and inserts
the decoded string into the variable as plain text!
Everyone wins!
The actual method doesn't matter - but with this it would
require that end users be willing to crack the software instead
of just sniffing around. Sometimes strings reveal things we
dont want the curious user to know.
Thank you!
I hope that these are four things that would really help everyone write simpler code!
(Listed in ascending order of importance)
*** Simplified List Handling ***
Add an element to the K list should not require two statements:
AddElement(K())
K() = "New List element"
Should be allowed by:
append(k()) = "New List Element"
Same for insert...
*** We need a built in split/explode command ***
Sorry, the stringfield command is close but not enough.
We should be able to split any string into an array without
writing a subroutine each time.
And of course we need the inverse command as well:
To combine an array into a string (with or without delimiter)
The php syntax is my favorite, but the name doesn't matter:
f$() = explode(g$,"*") ; take it apart
h$() = implode(f$,"*") ; put it back together
*** Trim vs. Trimm ***
So, in newer languages, trim() gets rid of all common whitespace characters
but in purebasic, it acts in the old 1967 way. Very nostalgic for me!
I have written a function called trimm() that does
this. I think Purebasic should adopt it... then you can have old
BASIC style trim() and let newcomers use the better trimm() statement!
It should remove the following: space, tab, newline, cr and maybe
backspace or any combo of them. That way programmers coming from
modern scripting languages can adapt their code more easily. If we are
to have a huge user base, we should add such updates.
And yes, I know it's harder to do this in multibyte.
*** HEREDOC / TEXT STRINGS ***
There are 2 little issues:
a. It's painful to work with assigning big text.
b. It is painful to hide text strings from casual inspection.
FIRST, we really need support for this syntax:
f$ = "
a really long bunch of text that I want to include
and that has simple CR/LF or just CR at the end, but
you can't see it. However, I'm going to write all
this out and not worry about putting in all the a$+quote
stuff because I just want to write out my text and be done
with it"
instead of
f$ + "some words words words"
f$ + "more words words words"
AND AS WELL (and frequently asked about):
We need the ability to embed text that is somewhat obscured from
the user. It doesn't have to be super duper encryption, but the
raw text shouldn't be seen casually. And yes, I know that for real
security you must roll your own... but I only care to have a little
misdirection.
Therefore I suggest that if we can't have both, Purebasic adds a
tool like:
f$ = embed("monkeys and sheep are roller skating!")
and also
f$ = embed("
I am a long exception to how the compiler normally works
and so my text will be read until the end of the paragraph
and then saved into a buffer where we randomly xor against
the character position (so char xor pos) and now we have
unreadable text in the executable.
")
At compile time, the strings are obfuscated and handled as
normal. However, at run time, when the variable assignment is
being made, the program simply reverse the process and inserts
the decoded string into the variable as plain text!
Everyone wins!
The actual method doesn't matter - but with this it would
require that end users be willing to crack the software instead
of just sniffing around. Sometimes strings reveal things we
dont want the curious user to know.
Thank you!