Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reword REPLACE #212

Closed
xvxx opened this issue Dec 3, 2022 · 5 comments
Closed

Reword REPLACE #212

xvxx opened this issue Dec 3, 2022 · 5 comments

Comments

@xvxx
Copy link
Collaborator

xvxx commented Dec 3, 2022

While looking at #205, I noticed compileman.php does lots of string replacing.

In PHP and other languages, you use something like replace(inString, searchFor, replaceWith)

But in LDPL, it's more like replace(searchFor, inString, replaceWith). Which is fine, but seeing a bunch of them in a row makes it a bit less clear what's actually going on:

replace "\\" from $manPage with "\\\\" in $manPage
replace "\(" from $manPage with "(" in $manPage
replace "\)" from $manPage with ")" in $manPage
replace "**" from $manPage with "" in $manPage
replace "_ " from $manPage with " " in $manPage
replace " _" from $manPage with " " in $manPage

As opposed to something like this, where the connections are closer and slightly more obvious

replace "\\" with "\\\\" from $manPage in $manPage
replace "\(" with "(" from $manPage in $manPage
replace "\)" with ")" from $manPage in $manPage
replace "**" with "" from $manPage in $manPage
replace "_ " with " " from $manPage in $manPage
replace " _" with " " from $manPage in $manPage

So anyway, I'm proposing adding a new syntax for REPLACE and using that in all the docs, but still keeping the old one around as a forever deprecated alternative.

As a bonus, would this be worth adding too?

replace "\\" with "\\\\" in $manPage
replace "\(" with "(" in $manPage
replace "\)" with ")" in $manPage
replace "**" with "" in $manPage
replace "_ " with " " in $manPage
replace " _" with " " in $manPage
@Lartu
Copy link
Owner

Lartu commented Dec 4, 2022

I like the alternatives! Although I'm wondering, couldn't they just be implemented using a CREATE STATEMENT like this?

image

@xvxx
Copy link
Collaborator Author

xvxx commented Dec 4, 2022

I'm not suggesting any alternatives. I am proposing that we change the current syntax for REPLACE.

@Lartu
Copy link
Owner

Lartu commented Dec 4, 2022

Ah! Right! Yes, I like the alternative you propose.

@dgarroDC
Copy link
Collaborator

dgarroDC commented Dec 6, 2022

I agree, the current syntax reads really awkward. My friend ChatGPT also agrees:

Me: "I'm creating a programming language. One of the statement allows you to replace text. I have two possibles syntaxes for it (the parameters are between < and >):

REPLACE < searchFor > FROM < inString > WITH < replaceWith > IN < variable to hold the result >

REPLACE < searchFor > WITH < replaceWith > FROM < inString > IN < variable to hold the result >

Which one is better?"

ChatGPT: "The second syntax is better because it follows a more logical order and is easier to read. It first specifies the text to be replaced, then the replacement text, then the string where the replacement will take place, and finally the variable where the result will be stored. This follows the order in which a person would naturally think about the task of replacing text. The first syntax does not have a clear order and could be confusing for a programmer to read and understand."

Me: "I also want a variant that replaces the text in place, what do you think and what syntax do you propose?"

ChatGPT: "For a variant that replaces the text in place, I would recommend the following syntax:

REPLACE < searchFor > WITH < replaceWith > IN < inString >

This syntax clearly specifies the text to be replaced, the replacement text, and the string where the replacement will take place. It is concise and easy to read, and it follows the logical order of the task. It also avoids the need for an additional variable to hold the result, which makes it more efficient and straightforward to use."

@Lartu
Copy link
Owner

Lartu commented Dec 6, 2022

Holy fuck the machines are rising run to the hills!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants