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

Add a short discussion of string concatenation to the FAQ. #24487

Merged
merged 4 commits into from
Oct 18, 2018

Conversation

tpapp
Copy link
Contributor

@tpapp tpapp commented Nov 6, 2017

Rationale: even though #11030 was closed, there is discussion of the issue from time to time on Github and the forum; so if any question is frequently asked, this is.

Rationale: even though JuliaLang#11030
was closed, there is discussion of the issue from time to time on
Github and the forum; so if any question is frequently asked, this is.
@fredrikekre
Copy link
Member

See also #19643, perhaps link to that discussion also?

@@ -593,6 +593,12 @@ julia> remotecall_fetch(anon_bar, 2)
1
```

### Why does Julia use "*" for string concatenation? Why not "+" or something else?

The [main argument](@ref man-concatenation) against `+` is that string concatenation is not commutative, while `+` is generally used as a commutative operator. While the Julia community recognizes that other languages use different operators and `*` may be unfamiliar for some users, syntax choices always have a subjective element and further discussions about this operator have not turned out to be productive, so it is not likely to change in the short run.
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nature of the discussion around the operator is not really relevant here. This reads a bit passive-aggressive to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that, English is not my first language. The intent was to convey the idea that the question has been given due consideration.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish something like this had been merged into the docs - my colleague and I were wondering why such an awkward operator was being used for string concatenation, and at least this provides the rationale. I mean, it still doesn't really make sense to me since * is generally used for multiplication which is also a commutative operation (between scalars).

In any case, I think the first sentence of that explanation is great and would make a valuable addition to the docs i.e.

Why does Julia use "*" for string concatenation? Why not "+" or something else?

The [main argument](@ref man-concatenation) against + is that string concatenation is not commutative, while + is generally used as a commutative operator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I can reword this. In the past year or so, this issue/discussion came up surprisingly rarely, so the FAQ may not need to address that part.

@kshyatt kshyatt added docs This change adds or pertains to documentation strings "Strings!" labels Nov 8, 2017
@@ -593,6 +593,12 @@ julia> remotecall_fetch(anon_bar, 2)
1
```

### Why does Julia use "*" for string concatenation? Why not "+" or something else?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use code formatting in headings, so maybe update "*" -> `*` and likewise for +?


The [main argument](@ref man-concatenation) against `+` is that string concatenation is not commutative, while `+` is generally used as a commutative operator. While the Julia community recognizes that other languages use different operators and `*` may be unfamiliar for some users, it communicates certain algebraic properties.

Note that you can also use `string(...)` to concatenate strings (and other values converted to strings); similarly, `repeat` can be used instead of `^` to repeat strings. The [interpolation syntax](@ref string-interpolation) is also useful for constructing strings.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split up these two lines into multiple ones at around ~92 chars?

@StefanKarpinski StefanKarpinski merged commit 0bab957 into JuliaLang:master Oct 18, 2018
@tpapp tpapp deleted the faq-string-concatenation branch April 2, 2020 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation strings "Strings!"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants