Project

General

Profile

Feature #5352

How about using <> to represent Here Document?

Added by yimutang (Joey Zhou) over 6 years ago. Updated 3 days ago.

Status:
Rejected
Priority:
Normal
Target version:
[ruby-core:39672]

Description

"<<" is a frequently used method in text manipulation. Meanwhile, it's also the beginning token of a here-document.
Sometimes it may be confusing to newbies.

Unlike Perl, in which "<>" is a very very frequently used operator to read lines from a filehandle, in Ruby, "<>" has no meaning. So I think it can be used to represent Here Document, so as to reduce the possibility of misunderstanding method "<<" and here-document token "<<". And In my opinion, <> is more clear than <<, because it looks like kind of brackets.

For example,

  str = <SECT1>.upcase + <SECT2>.downcase
  aaaaaa
  SECT1
  XXXXXX
  SECT2

may be clearer than:

  str = <<SECT1.upcase + <<SECT2.downcase

History

#1 [ruby-core:39679] Updated by duerst (Martin Dürst) over 6 years ago

If anything is done in this direction, I'd prefer

   str = <>SECT1.upcase + <>SECT2.downcase

over

   str = <SECT1>.upcase + <SECT2>.downcase

It seems to stick out much better.

#2 [ruby-core:39680] Updated by yeban (Anurag Priyam) over 6 years ago

On Fri, Sep 23, 2011 at 7:08 AM, Martin Dürst duerst@it.aoyama.ac.jp wrote:
[...]

If anything is done in this direction, I'd prefer
  str

#3 [ruby-core:39686] Updated by nobu (Nobuyoshi Nakada) over 6 years ago

Joey Zhou wrote:

Unlike Perl, in which "<>" is a very very frequently used operator to read lines from a filehandle, in Ruby, "<>" has no meaning. So I think it can be used to represent Here Document, so as to reduce the possibility of misunderstanding method "<<" and here-document token "<<". And In my opinion, <> is more clear than <<, because it looks like kind of brackets.

I'm somewhat negative.
It looks like Perl's "<>" but is pretty different, so I'm afraid that it would be also confusing.

#4 [ruby-core:39702] Updated by yimutang (Joey Zhou) over 6 years ago

Nobuyoshi Nakada wrote:

I'm somewhat negative.
It looks like Perl's "<>" but is pretty different, so I'm afraid that it would be also confusing.

There are a few things different in Ruby and Perl.

$foo is not a scalar, @bar is not an array, %w is not a hash

"re = /pattern/" in Ruby means assigning a regexp to re, but in Perl "$re = /pattern/" means "$re = $_ =~ /pattern/"...

So I think the difference is not a problem, some differences already exist.

"<<" of Perl has two meanings: shifting bits and here document. One is for the integers and the other is for the string, maybe leading to less confusing. However, in Ruby, "<<" is instance method of String and IO/File, and here document is also string, the probability of confusing is larger, I'm afraid.

#5 [ruby-core:43713] Updated by mame (Yusuke Endoh) about 6 years ago

  • Status changed from Open to Assigned
  • Assignee set to matz (Yukihiro Matsumoto)

#6 Updated by mame (Yusuke Endoh) over 5 years ago

  • Target version set to Next Major

#7 Updated by naruse (Yui NARUSE) 3 days ago

  • Description updated (diff)

#8 [ruby-core:86599] Updated by matz (Yukihiro Matsumoto) 3 days ago

  • Status changed from Assigned to Rejected

Rejected. I don't want to change the basic syntax (without major benefit). Besides that, I want to keep <> for future syntax extension.

Matz.

Also available in: Atom PDF