ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:83399] [Ruby trunk Feature#14033] Alias String#<< as String#append
       [not found] <redmine.issue-14033.20171019201048@ruby-lang.org>
@ 2017-10-19 20:10 ` mail
  2017-10-19 21:39 ` [ruby-core:83401] " shevegen
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: mail @ 2017-10-19 20:10 UTC (permalink / raw
  To: ruby-core

Issue #14033 has been reported by sos4nt (Stefan Schüßler).

----------------------------------------
Feature #14033: Alias String#<< as String#append
https://bugs.ruby-lang.org/issues/14033

* Author: sos4nt (Stefan Schüßler)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Ruby 2.5 introduces `Array#append` as an alias for `<<` / `push`.

Likewise, there should be `String#append` as an alias for `<<` / `concat`. The documentation for `<<` even says "append":

> Append—Concatenates the given object to str. [...]

And `String` already has a `prepend` method.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:83401] [Ruby trunk Feature#14033] Alias String#<< as String#append
       [not found] <redmine.issue-14033.20171019201048@ruby-lang.org>
  2017-10-19 20:10 ` [ruby-core:83399] [Ruby trunk Feature#14033] Alias String#<< as String#append mail
@ 2017-10-19 21:39 ` shevegen
  2017-10-20  0:22 ` [ruby-core:83402] " matthew
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: shevegen @ 2017-10-19 21:39 UTC (permalink / raw
  To: ruby-core

Issue #14033 has been updated by shevegen (Robert A. Heiler).


I +1 agree with Stefan for symmetry. :)

However had, I may be biased since I discussed in favour of the
Array-methods .prepend() and .append().

But I suppose the reasoning is very similar. I think that both class
String and class Array could share the same method .prepend and
.append here, from a functional point of view. The ruby user may
want to put something on the "beginning" of the array - and the
ruby user may put something on the "end" of the array. Same for
a string (if we assume that the entity of a string are
characters).

The .prepend() method may be more useful for Strings; for append()-like
operations, I personally  always prefer <<. I do not know why, I just
love <<.

I think the major point I agree with it is that it, to me, appears
to make sense from an english language point of view. A short
"action-method" name - prepend this, append that. It would make 
sense in my opinion to have .append for strings too, but I may be
biased so perhaps others can comment.

----------------------------------------
Feature #14033: Alias String#<< as String#append
https://bugs.ruby-lang.org/issues/14033#change-67365

* Author: sos4nt (Stefan Schüßler)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Ruby 2.5 introduces `Array#append` as an alias for `<<` / `push`.

Likewise, there should be `String#append` as an alias for `<<` / `concat`. The documentation for `<<` even says "append":

> Append—Concatenates the given object to str. [...]

And `String` already has a `prepend` method.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:83402] [Ruby trunk Feature#14033] Alias String#<< as String#append
       [not found] <redmine.issue-14033.20171019201048@ruby-lang.org>
  2017-10-19 20:10 ` [ruby-core:83399] [Ruby trunk Feature#14033] Alias String#<< as String#append mail
  2017-10-19 21:39 ` [ruby-core:83401] " shevegen
@ 2017-10-20  0:22 ` matthew
  2017-10-20  6:43 ` [ruby-core:83417] " mail
  2018-08-08  3:01 ` [ruby-core:88333] [Ruby trunk Feature#14033] Add String#append samuel
  4 siblings, 0 replies; 5+ messages in thread
From: matthew @ 2017-10-20  0:22 UTC (permalink / raw
  To: ruby-core

Issue #14033 has been updated by phluid61 (Matthew Kerwin).


I am opposed to this alias as proposed.

1. `<<` is known to be "dangerous", but other "safe" concatenation operations exist for String (e.g. `+`).  I would expect that a *new* word-based name for the dangerous operation would end with "`!`".

2. `<<` (and `concat`) casts integers as codepoints. `prepend` requires that *all* arguments are Stringy (c.f. `+`).  A method named to be like `prepend`, but that behaves like `concat`, is confusing.

3. `<<` only accepts a single argument, but `concat` accepts many, so this alias would introduce confusion about which method (concat vs. append) has what arity.


If the proposal were about adding [new functionality](https://github.com/phluid61/mug/blob/master/lib/mug/affix.rb) I think it would be worth considering, but I'm against adding a new name for the sake of it.

----------------------------------------
Feature #14033: Alias String#<< as String#append
https://bugs.ruby-lang.org/issues/14033#change-67366

* Author: sos4nt (Stefan Schüßler)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Ruby 2.5 introduces `Array#append` as an alias for `<<` / `push`.

Likewise, there should be `String#append` as an alias for `<<` / `concat`. The documentation for `<<` even says "append":

> Append—Concatenates the given object to str. [...]

And `String` already has a `prepend` method.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:83417] [Ruby trunk Feature#14033] Alias String#<< as String#append
       [not found] <redmine.issue-14033.20171019201048@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2017-10-20  0:22 ` [ruby-core:83402] " matthew
@ 2017-10-20  6:43 ` mail
  2018-08-08  3:01 ` [ruby-core:88333] [Ruby trunk Feature#14033] Add String#append samuel
  4 siblings, 0 replies; 5+ messages in thread
From: mail @ 2017-10-20  6:43 UTC (permalink / raw
  To: ruby-core

Issue #14033 has been updated by sos4nt (Stefan Schüßler).


phluid61 (Matthew Kerwin) wrote:

> 1 [...] I would expect that a new word-based name for the dangerous operation would end with "!".

That contradicts `Array#append` / `Array#prepend`. And since `String#prepend` also modifies the receiver, I would expect `String#append` to work in a similar way.

(Off topic but IMO, `String#concat` is the one that should return a new string, just like the documentation for `String#+` says: _"Concatenation—Returns a new String containing other_str concatenated to str."_ But it's probably a bit late to fix that.)

> 2 [...] A method named to look like prepend, but that behaves like concat, is confusing.

Good point. I'm fine with string-only arguments. `append` would simply invoke `rb_str_append` then (is that a coincidence?).

> 3 [...] this alias would introduce confusion about which method (concat vs. append) has what arity.

It should of course work (arity-wise) like `Array#append`, i.e. accept multiple argument. I should have said "concat", not "<<" in the question's title.

---

To avoid any further confusion: I'm proposing a _new_ method `String#append` with the following signature:

> ### append(other_str1, other_str2,...) → str
> Append—Append the given strings to _str_.
>
>```ruby
> a = "hello "
> a.append("world", "!") #=> "hello world!"
> a                      #=> "hello world!"
> ```
>
> See also _#concat_.

----------------------------------------
Feature #14033: Alias String#<< as String#append
https://bugs.ruby-lang.org/issues/14033#change-67382

* Author: sos4nt (Stefan Schüßler)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Ruby 2.5 introduces `Array#append` as an alias for `<<` / `push`.

Likewise, there should be `String#append` as an alias for `<<` / `concat`. The documentation for `<<` even says "append":

> Append—Concatenates the given object to str. [...]

And `String` already has a `prepend` method.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:88333] [Ruby trunk Feature#14033] Add String#append
       [not found] <redmine.issue-14033.20171019201048@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2017-10-20  6:43 ` [ruby-core:83417] " mail
@ 2018-08-08  3:01 ` samuel
  4 siblings, 0 replies; 5+ messages in thread
From: samuel @ 2018-08-08  3:01 UTC (permalink / raw
  To: ruby-core

Issue #14033 has been updated by ioquatix (Samuel Williams).


I would like to propose to extend this method to be binary safe.

If the destination string uses `Encoding::BINARY`, the append operation should be a memcpy which doesn't affect the receiver's encoding.

----------------------------------------
Feature #14033: Add String#append
https://bugs.ruby-lang.org/issues/14033#change-73362

* Author: sos4nt (Stefan Schüßler)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Ruby 2.5 introduces `Array#append` as an alias for `<<` / `push`.

Likewise, there should be `String#append` as an alias for `<<` / `concat`. The documentation for `<<` even says "append":

> Append—Concatenates the given object to str. [...]

And `String` already has a `prepend` method.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-08-08  3:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-14033.20171019201048@ruby-lang.org>
2017-10-19 20:10 ` [ruby-core:83399] [Ruby trunk Feature#14033] Alias String#<< as String#append mail
2017-10-19 21:39 ` [ruby-core:83401] " shevegen
2017-10-20  0:22 ` [ruby-core:83402] " matthew
2017-10-20  6:43 ` [ruby-core:83417] " mail
2018-08-08  3:01 ` [ruby-core:88333] [Ruby trunk Feature#14033] Add String#append samuel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).