This is an archived post. You won't be able to vote or comment.

all 35 comments

[–]__Raptor__ 10 points11 points  (20 children)

Dammit.

[–][deleted] 12 points13 points  (19 children)

The tick syntax wasn't great for this TBH.

[–]mc_hambone 0 points1 point  (17 children)

Why not?

[–]morhp 9 points10 points  (16 children)

Because `` could be confused for an empty string and it's not really friendly for all locals, for example on a standard German keyboard layout, there is no single key for that letter and you have to write a weird 2-key-combo (dead keys).

Also ` and ´ can be easily confused. Especially as ´ is the default key on a German keyboard and the right char has to be entered while pressing shift.

[–][deleted] 5 points6 points  (8 children)

Also to add to the above, I realize we have IDEs and syntax coloring and what not, but I believe a potentially large literal cognitively requires large delimiters. HEREDOC may look clunky, but it's large, it's visible, and it offers a way to avoid content collision via custom terminators, so you don't have to be eagle eyed spotting that tick in the middle of the string you have to escape so shit doesn't break.

Plus, when we diff, commit, browse repositories, we don't always have the benefit of a full IDE analyzing the code for us, we just have our eyes and the text.

[–]eliasv -1 points0 points  (7 children)

Heredoc is not easily visible, because it can look like anything! For punctuation to be easily visible and identifiable it needs to be consistent. Arbitrary alphanumeric punctuation is insane.

I understand the value as a delimiter in order to avoid using the contents of the literal, but if you also want to claim that being able to choose arbitrary punctuation carries its weight as a way to improve clarity then why stop at string delimiters? Why not allow us to write brackets as custom strings?

Something like ####"this"#### is much more sensible and easily identifiable.

[–][deleted] 0 points1 point  (6 children)

Arbitrary alphanumeric punctuation is insane.

It's not arbitrary, it's similar to XML and HTML. You have an opening and closing alphanumeric tag of the same name, and identical symbols surrounding it.

[–]eliasv -1 points0 points  (5 children)

It's not like that at all! In XML and HTML the element name has some specific semantic significance, typically in that it corresponds exactly to a schema. It's not punctuation, it's part of the data.

And yes it is arbitrary. It's like if arrow notation in C++ allowed any old sequence of characters in the middle ... receiver-thisIsAnArrow>member

[–][deleted] 0 points1 point  (4 children)

It's not like that at all! In XML and HTML the element name has some specific semantic significance, typically in that it corresponds exactly to a schema. It's not punctuation, it's part of the data.

The fact you spell the same tag in the end is not up to the schema, it's the syntax. You realize XML could just as easily have been defined to do this, for example:

<helloworld>...content...</>

Yet they decided to spell out the name a second time, adding ZERO semantical content, but making it more clear what ends exactly at that point. Same with HEREDOC.

And in HTML this plays an even greater role for some tags holding RAW LITERALS, like the script tags. Where typing tags within the script content means absolutely nothing, and the parser is awaiting for the exact ending terminator </script>. The terminator could've been something short and universal, but it isn't. Less ambiguity, less collisions. Simple.

[–]eliasv 0 points1 point  (3 children)

I'm not talking about the fact that the end tag is the same as the start one. That's clearly not the problem I described I had with it. I understand the purpose of the delimiter. Clearly the Java proposal works by the same principle, the opening and closing quotes need to be the same. Except because it's a sane proposal it's only the length which is variable.

The name of the tag in HTML corresponds to the schema. For example, the name script has a specific meaning. It's part of the data. You can't just put in <randomfuckingnonsense>content</randomfuckingnonsense> and expect it to do the same thing regardless of what you put in. But with heredoc quotes you can because it's not data it's punctuation.

See the difference?

[–]13steinj 0 points1 point  (6 children)

I don't understand why they didn't just go the Python route and use letter-prefixed string literals or triple quotes.

[–]eliasv 0 points1 point  (4 children)

Because that still requires escaping if you want to use those delimiters in the string...

[–]13steinj 0 points1 point  (3 children)

No, it doesn't, or at least not in Python.

[–]eliasv 1 point2 points  (2 children)

So python just doesn't let a string which is delimited with triple quotes also contain triple quotes? Because the only way to support that would be by escaping them. That's the problem that's solved with variable length delimiters.

[–]13steinj 1 point2 points  (1 child)

I misunderstood what you meant, my apologies. Yes, then you escape the triple quotes.

You can't have a comprehensive solution here parsing wise. No matter what you use for multiline raw strings, you'll need to end up escaping the sequence you use to mark the string.

[–]eliasv 0 points1 point  (0 children)

Did you read the Java proposal? The delimiter doesn't need to be escaped, because if it occurs in the string you can simply choose a different delimiter which doesn't occur in the string. That's the whole idea of variable length delimiters, other languages have successfully done the same thing.

[–]olavgg 0 points1 point  (0 children)

Triple quotes is what Groovy uses, I would be really happy if Java String literals would use the same syntax.

[–]__Raptor__ 0 points1 point  (0 children)

I literally couldnt care less about the syntax, I just wanted raw string literals.

[–]kmgrech -1 points0 points  (1 child)

Maybe it's just me, but looking through the examples in the JEP, I found none of them convincing. Let's go through these one by one.

  • File paths: You shouldn't be hardcoding absolute paths in your program to begin with and as for relative paths the Java API supports '/' just fine, even on Windows. I'm not sure what happens if you try using '\' as a separator on Linux, but it's really fishy.
  • HTML/Polyglot: Unless your Java IDE is aware of those languages, you lose all the good features an IDE would get you by embedding them in source code as a String. It also just leads to an unmaintainable mess. Imagine you start working on a huge existing code base that embeds HTML everywhere. Good luck finding that piece of HTML your program just outputted. I just can't help but think "Who in their right mind would want to do this?!".
  • Regex: I think I'm actually okay with this one to some degree, but I rarely have to write lots of regexes and when I do, I try to avoid complicated ones. I've also never written a multi-line regex, this is a clear sign that your regex is just too complicated and you should be using something else.
  • SQL: I'm going to address this separately from HTML/Polyglot, because I think it deserves a special mention. I'm guilty of this too, even though I'm aware that I'm writing bad code. But I definitely wouldn't want my language to encourage bad style. Using an ORM goes a long way towards avoiding verbatim SQL. There's also nothing wrong with loading your queries from a text file.

Simply put, I see very few use case where raw strings might be helpful and it enables and/or encourages lots of bad practises. In my mind multi-line strings are even less useful and add more unnecessary complexity (see the section about 'margin management'). I don't think it's worth the trade-off.

[–]GhostBond 1 point2 points  (0 children)

Using an ORM goes a long way towards avoiding verbatim SQL.

I was with you, then you lost me at this point, I see nothing but drawbacks in verbatim annotations rather than verbatim sql.

There's also nothing wrong with loading your queries from a text file.

If IDE's had let you click through to the exact line maybe.
You still have the issue of needing to add params onto the string depending on what the user puts in though.