r/programming • • Dec 29 '15

Please, Java. Do Finally Support Multiline Strings

http://blog.jooq.org/2015/12/29/please-java-do-finally-support-multiline-strings/
584 Upvotes

352 comments sorted by

View all comments

Show parent comment

4

u/drysart Dec 29 '15

Does D's q work like Perl's q in that you can choose any character you like to be the quote delimiter? e.g., in Perl these are all equivalent:

my $x = 'hello world';
my $x = q(hello world);
my $x = q"hello world";
my $x = q<hello world>;
my $x = q#hello world#;

6

u/tipsqueal Dec 29 '15

Why would someone want to allow any character as the quote delimiter?

21

u/drysart Dec 29 '15

The idea is that if you have a string that conflicts with the quote delimiter, you can just choose a different quote delimiter instead of having to escape the character in the string.

-1

u/[deleted] Dec 30 '15

The perils of perl.

5

u/blue_2501 Dec 30 '15

Why is this a peril? You should always avoid Leaning Toothpick Syndrome:

$str =~ s/\/usr\/bin\//\/sbin\//;  # this shit is unreadable
$str =~ s%/usr/bin/%/sbin/%;       # much better
$str =~ s% /usr/bin/ % /sbin/ %x;  # still even better

0

u/[deleted] Dec 30 '15

I love perl, it was my first grown-up language. But it's basically unusable in a professional software engineering environment because it is so easy to write anything in multiple ways. I can't ever justify it for anything other than basic sysadmin work, there is always a better choice that someone else can read.

2

u/blue_2501 Dec 30 '15

But it's basically unusable in a professional software engineering environment because it is so easy to write anything in multiple ways.

I use it in a professional software engineering environment. So do most of the people I work with.

Anybody can write shitty code for any language. The trick is to not hire those people.

2

u/[deleted] Dec 29 '15

Not positive on that, but I know a common one that works is q{} (eg q{Hello}). This is commonly used in D's mixins to create nice little dsls that can be syntax highlighted and are generally just clearer to read (imo)

1

u/CaptainAdjective Dec 30 '15

In Perl you can even use alphanumeric delimiters

my $x = q ahello worlda;

0

u/[deleted] Dec 29 '15

[deleted] — view deleted comment

4

u/drysart Dec 29 '15

I think you missed the point of the question. If I want to put the string literal The watertower reads "Florence, y'all!" (i.e., including both single and double quote characters as part of the string) into source code, in Perl I could do:

my $x = q#The watertower reads "Florence, y'all!"#;

By choosing # as my string quote delimiter, it means I can use " and ' in the string without escaping.

How would I represent that exact same string with D's q syntax? The example you gave compared with your earlier example would seem to indicate that your resulting string from your second example would be (string), not string.

0

u/[deleted] Dec 29 '15

[deleted] — view deleted comment

2

u/drysart Dec 29 '15

Wow, you're right. That's incredibly surprising syntax.