Multiline string literals

Kai Kunstmann Kai.Kunstmann at combase.de
Mon Aug 8 03:17:02 PDT 2011


Hi,

I support Maurizio's argument: If your are in need of quotes within
quotes ("I said \"Quote me!\" to make my point.") or something similar
that has some kind of structure, you probably are in need of an
abstraction to your use case rather than a language change:

"I said " + quote("Quote me!") + " to make my point."


About the platform dependency: Maybe I'm missing something here, but I
don't see how the compiling platform can even effect or alter a literal
String expression anyway. The line-break already is in the source code,
and it is Unix/Windows/Mac depending on what delimiter your IDE chose to
put down when you hit enter (or which one you told it to choose). Every
reasonable compiler should come up with the same result independent of
the compiling platform, which is to use the same line-break as in the
source. If your source changed during the transfer from OSix to wOS,
then that's the problem. My IDE supports the display of typographic
(hidden) characters and the explicit line-break conversion between the
major standards. How about yours?

If anything, I would like string literals to support the in-lining of
escape-sequences and/or line-wrapping support by means of a trailing
backslash to improve readability of code:

"This is a single-line string literal although it \
has 2 lines in the source to illustrate my point."


However, the major question with multi-line string literals is, how the
broken lines fit into the indention structure of the surrounding context
(indention is not a syntax rule but merely a convention), and how they
will improve or impair the overall readability:


public class SomeClass
{
  private final static String MULTI_LINE = "This is a deranged multi-
                                            line string literal.";

//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --> whitespace hell ???

  public static class SubClass
  {
    public void doSomething()
    {
      final String label = "this is the first line;
this is the second line;
this is the third line;
this is the last line";
this is an error;
    }

    public void doSomethingElse()
    {
      final String label = " // this label will confuse you...
      
      this.confuse(label);
    }
    
    public void confuse(String confusion)
    {
      System.out.println(confusion);
    }
    
      // "; // end of label
    }
  }
}


Regards,
Kai



Am Montag, den 08.08.2011, 09:16 +0100 schrieb Maurizio Cimadamore:
> On 07/08/11 14:54, Artur Biesiadowski wrote:
> > Because it is not only about multiline literals, it is about avoiding
> > escaping common expressions - in particular, "" delimited strings.
> >
> > This is why somebody was discussing 'single line multiline string
> > literal' here ;)
> Hi,
> it seems to me that we are asking for a silver bullet that solves all 
> our string-related problems; how much would we need escaping for 
> delimited strings if we had explicit syntax support for XML, JSON (etc.) 
> literals (possibly checked at compile-time against a schema?) - at the 
> end of the day, a string is a string - there's nothing much the compiler 
> can do about it; on the other hand, most of the examples of multiline 
> strings I've seen in this discussion do have a 'structure' that can be 
> checked.
> 
> Maurizio
> > Regards,
> > Artur Biesiadowski
> >
> > On 07/08/2011 13:36, Rémi Forax wrote:
> >> An why not using " ?
> >> why do we need a different syntax for single line and multiple lines
> >> string literals ?
> >>
> >
> 
> 





More information about the coin-dev mailing list