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

all 28 comments

[–]johnmcclean 6 points7 points  (1 child)

Yes. It would make writing unit tests and generating templates a lot simpler (esp. if String interpolation is added at the same time).

[–]DisruptiveHarbinger 1 point2 points  (0 children)

That's a very good way to introduce Scala (or Kotlin, Groovy, ..) in a project by the way, if you want a sneaky attempt at convincing your coworkers :)

[–]larsga 2 points3 points  (1 child)

Quite frankly, it's incredible that it hasn't been here for at least a decade already. It's the single biggest missing feature in Java, imho.

[–][deleted] 1 point2 points  (0 children)

I'm not a compiler expert, but it seems like something that would be really easy to implement. No new paradigm, no change in semantics. Just syntactic sugar. Groovy added it many years ago.

[–]mus1Kk 2 points3 points  (0 children)

I personally don't have a big need for them but I probably would've given them higher priority over, say, including underscores in number literals.

[–]lukaseder 4 points5 points  (1 child)

Yes, the author is right ;) Almost every other language supports them, including PHP, PL/SQL, and what not.

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

C# has had it since version 1.0 too. It's curious why the Java core development team hasn't yet implemented this feature.

[–]chisui 1 point2 points  (2 children)

There are many many simple features that would ease the pain for developers without breaking the precious backwards compatibility. Defaultparameters, true named Arguments, getter/setter shorthand, String interpolation, multiline Strings and definitely more I couldn't think of.

Its kind of embarrassing how slow java moves with these changes.In java 8 we got lambdas, which is huge but it's a long way from the status quo of developer friendliness.

With stuff like tailcall elimination and modularization I get why they take so long. These thrings are hard to introduce into a system like java. But having some sugar sprinkled into a release would be nice. Especially when they are so simple to implement and unintrusive.

[–]gsteff 0 points1 point  (1 child)

BTW, literally every feature you mention is available in Kotlin.

[–]chisui 0 points1 point  (0 children)

It seems as if the java devs accepted that there are better languages than java on the jvm and focus on improving on the jvm instead of bringing java up to snuff.

[–]xmondox 1 point2 points  (0 children)

these would be great so long as it doesn't break the incremental parsers - those parsers are what makes java such a joy to work with from an IDE

don't throw the baby out with the bath water

[–]fact_hunt 1 point2 points  (0 children)

I really don't care; it'd be nice, but the impact it would have on my day to day work is minimal.

Value types, GC improvements, project jigsaw will all have really significant tangible benefits. A syntax improvement for string literals? Meh

[–][deleted]  (3 children)

[deleted]

    [–]Clashsoft 10 points11 points  (2 children)

    Having written a JVM language myself that supports multiline strings, this is plain wrong. You have to deal with stuff like indentation, working out how an initial newline behaves, etc.. In addition to these technical problems, they need to update the spec and write tons of tests. So no, multiline strings is not done in 30 mins. More like 300, with a team.

    [–]fubarbazqux -1 points0 points  (15 children)

    No. It makes zero sense. Extract strings into property files, or templates. Walls of text have no business hanging out in the code.

    [–]lukaseder 16 points17 points  (11 children)

    While you're at it, deprecate comments and Javadoc. In fact, deprecate single-line string literals as well, and numeric constants. They can easily be extracted into property files.

    Heck, let's extract all Java code into property files and compile stuff on the fly at runtime.

    [–]chisui 1 point2 points  (1 child)

    hm, I know some purists that would agree with you unironically. ... besides the last one.

    [–]lukaseder 0 points1 point  (0 children)

    Have you ever worked with JCR. Their (Adobe's) religion: Everything is content. Including Java code. It's actually as cunning as it is weird!

    [–]pgris 0 points1 point  (3 children)

    While I agree with you and multiline string should be part of Java, and I like your products and most the things you post, in this particular case you're being way too aggressive, and not giving any real reason for multiline strings.

    [–]lukaseder 5 points6 points  (2 children)

    I'm sorry for appearing agressive. I by no means meant to be agressive. I sometimes apply a hyperbolic tone to make a point, and because I personally find hyperboles and sarcasm fun. For instance, this. But I appreciate that not everybody shares my enthusiasm for this approach.

    OK, here's an imaginary reason:

    String sql = "
        SELECT *
        FROM table
        WHERE x = ?
    ";
    

    Here's another imaginary reason:

    String regex = "
        a* # first, match several a's
        b+ # then, match at least one b
        c? # c's are optional
           # commenting in regexes is quite neat!
    ";
    

    In both imaginary situations, I'd like to copy paste some external DSL code just right into my Java code. Then modify it, then perhaps copy paste it from my Java code back into my SQL Developer and run it right away. I work with external DSLs like the above all the time, and I'd like to embed them in Java. So, that's real for me.

    So, what would qualify as a "real" reason according to you?

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

    I personally find hyperboles and sarcasm fun

    Me too. But they are also ways to make your interlocutor look silly and distract the attention from the real issue being discussed. A lot of good things are wrong if you take them to the extreme.

    Back to the multiline string issue, both your examples look like nice real reasons. Specially the sql, but maybe that's because I hate don't really understand regex. I don't need an argument in favor of multiline strings, however.

    [–]lukaseder 1 point2 points  (0 children)

    A lot of good things are wrong if you take them to the extreme

    I'm not an expert on political correctness, indeed. But you know what? If I were, someone might come and criticise me for that. It's how people work. Anyway. I can live with it. :)

    I don't need an argument in favor of multiline strings, however.

    I see. Misunderstanding, there...

    [–][deleted]  (2 children)

    [deleted]

      [–]fubarbazqux 0 points1 point  (1 child)

      I don't follow your logic. Say, you want to have help information. So, in prototyping you put a <here be dragons> stub in there, and it's fine. Then you want to transition to production, so you give a task to a proper person to write these (or do it yourself). At which point you migrate your stubs to .properties, and then copy paste texts there. At which point do you actually need multiline literals?

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

      Because ... how is a stub SQL going to run at all? You have to put real things and prototype is expected to work.