Forum: Ruby-core [ruby-trunk - Feature #9043][Open] Add String#f method as shortcut for #freeze

F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-10-22 14:17
(Received via mailing list)
Issue #9043 has been reported by headius (Charles Nutter).

----------------------------------------
Feature #9043: Add String#f method as shortcut for #freeze
https://bugs.ruby-lang.org/issues/9043

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


We have String#b to create a binary-encoded String, and we have the "f"
suffix (going away, hopefully) and the "literal".freeze optimization
(#8992). I think it would be reasonable to add String#f as a shorter
method for producing a frozen string.

If String#f is added the "literal".freeze optimization could be dropped
in favor of "literal".f. This would provide something very close to the
original "literal"f syntax but in a backward-compatibility-friendly way
(class String; alias f freeze; end).
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-10-22 14:17
(Received via mailing list)
Issue #9043 has been updated by headius (Charles Nutter).

Category set to core
Target version set to current: 2.1.0


----------------------------------------
Feature #9043: Add String#f method as shortcut for #freeze
https://bugs.ruby-lang.org/issues/9043#change-42544

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: current: 2.1.0


We have String#b to create a binary-encoded String, and we have the "f"
suffix (going away, hopefully) and the "literal".freeze optimization
(#8992). I think it would be reasonable to add String#f as a shorter
method for producing a frozen string.

If String#f is added the "literal".freeze optimization could be dropped
in favor of "literal".f. This would provide something very close to the
original "literal"f syntax but in a backward-compatibility-friendly way
(class String; alias f freeze; end).
F736999f7c1b7a87a100faa112bbc0f3?d=identicon&s=25 charliesome (Charlie Somerville) (Guest)
on 2013-10-22 22:09
(Received via mailing list)
Issue #9043 has been updated by charliesome (Charlie Somerville).


I feel really negatively about optimizing only String#f and not
String#freeze. You could make the argument that it's backwards
compatible, but in reality it means every bit of code that wants to use
this optimization needs to monkey patch its own String#f.

Otherwise I support adding String#f as an alias for String#freeze and
removing f-suffix syntax.
----------------------------------------
Feature #9043: Add String#f method as shortcut for #freeze
https://bugs.ruby-lang.org/issues/9043#change-42553

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: current: 2.1.0


We have String#b to create a binary-encoded String, and we have the "f"
suffix (going away, hopefully) and the "literal".freeze optimization
(#8992). I think it would be reasonable to add String#f as a shorter
method for producing a frozen string.

If String#f is added the "literal".freeze optimization could be dropped
in favor of "literal".f. This would provide something very close to the
original "literal"f syntax but in a backward-compatibility-friendly way
(class String; alias f freeze; end).
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-11-12 23:24
(Received via mailing list)
Issue #9043 has been updated by headius (Charles Nutter).

Assignee set to matz (Yukihiro Matsumoto)

The change to optimize String#freeze has landed for #8992, which
compiler-optimizes String#freeze. The only remaining decision is whether
to also add #f with the same optimization.

matz likes the idea of String#f. I'm happy either way, since #8992
landed, but a shorter method would be nice. With String#f acting like
"str"f, we'd only be one character more verbose than the original
syntax.

I believe matz needs to decide this one.
----------------------------------------
Feature #9043: Add String#f method as shortcut for #freeze
https://bugs.ruby-lang.org/issues/9043#change-42888

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


We have String#b to create a binary-encoded String, and we have the "f"
suffix (going away, hopefully) and the "literal".freeze optimization
(#8992). I think it would be reasonable to add String#f as a shorter
method for producing a frozen string.

If String#f is added the "literal".freeze optimization could be dropped
in favor of "literal".f. This would provide something very close to the
original "literal"f syntax but in a backward-compatibility-friendly way
(class String; alias f freeze; end).
18813f71506ebad74179bf8c5a136696?d=identicon&s=25 Eric Wong (Guest)
on 2013-11-13 01:27
(Received via mailing list)
Fwiw, I am against adding aliases to the same method,
especially extremely short names which are hard to search for.

It is confusing and increases overhead for reading/following code.

Easy-to-write code is not necessary easy-to-read.
(speaking as a sometimes Perl hacker)
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 matz (Yukihiro Matsumoto) (Guest)
on 2013-12-17 09:24
(Received via mailing list)
Issue #9043 has been updated by matz (Yukihiro Matsumoto).


Despite the OP's intention, String#f should not be an alias to #freeze,
but should work as #dedup described in #9229.
I am quite positive, but it must be too late for 2.1.

Matz.

----------------------------------------
Feature #9043: Add String#f method as shortcut for #freeze
https://bugs.ruby-lang.org/issues/9043#change-43718

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


We have String#b to create a binary-encoded String, and we have the "f"
suffix (going away, hopefully) and the "literal".freeze optimization
(#8992). I think it would be reasonable to add String#f as a shorter
method for producing a frozen string.

If String#f is added the "literal".freeze optimization could be dropped
in favor of "literal".f. This would provide something very close to the
original "literal"f syntax but in a backward-compatibility-friendly way
(class String; alias f freeze; end).
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-12-29 16:56
(Received via mailing list)
Issue #9043 has been updated by headius (Charles Nutter).

Target version changed from 2.1.0 to current: 2.2.0

I'd like to see this get into 2.2, and it sounds like Matz wants it too.
----------------------------------------
Feature #9043: Add String#f method as shortcut for #freeze
https://bugs.ruby-lang.org/issues/9043#change-43943

Author: headius (Charles Nutter)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.2.0


We have String#b to create a binary-encoded String, and we have the "f"
suffix (going away, hopefully) and the "literal".freeze optimization
(#8992). I think it would be reasonable to add String#f as a shorter
method for producing a frozen string.

If String#f is added the "literal".freeze optimization could be dropped
in favor of "literal".f. This would provide something very close to the
original "literal"f syntax but in a backward-compatibility-friendly way
(class String; alias f freeze; end).
18813f71506ebad74179bf8c5a136696?d=identicon&s=25 Eric Wong (Guest)
on 2013-12-30 02:46
(Received via mailing list)
I'm still against this (and having aliases at all for standard).
It makes code harder to search/read, especially when they have
short names like "f".
This topic is locked and can not be replied to.