Alignment algorithm (was: Wrapping up the first two courses)

Jim Laskey james.laskey at oracle.com
Mon Apr 22 16:23:34 UTC 2019



> On Apr 22, 2019, at 1:04 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
> 
> 
> 
> On 4/22/2019 11:26 AM, Jim Laskey wrote:
>> 
>> 2. long count = lines().count();
>>    if (count == 1) {
>>        return strip();
>>    }
>> 
>> Single line strings (no line terminators) are simply stripped.
>> 
>>     """  single line  """ ==> "single line"
> 
> I think we should reconsider this one.  The interpretation we settled on is: we're willing to treat a multi-line string as being a sequence of lines, not just of characters, and we're willing to strip incidental whitespace that arises from accidents of how the string is embedded in the program.  But a single-line string doesn't have any of that; I think it should be left alone, regardless of quotes.  

Why didn't they write as single quote string in the first place?  Having a """ removing incidentals works in our favour for examples like;

	""""in quotes"""" vs """  "in quotes"  """

> 
>>    
>> 3.  int outdent = lines().skip(1) ...
>> 
>> Ignoring first line, determine least number of leading whitespaces for all
>> non-blank lines.
>> 
>>     String s = """
>>     ................line 1..
>>     ....................line 2.
>>                 """;  ==> 16
> 
> I think we should reconsider whether a non-blank first line means that we should consider any indentation on the first line too.  This has the likely-beneficial side-effect that having a non-blank character immediately following the """ effectively means "no stripping." 

Not sure this is a workable perspective. Opting out this way forces the user into some weird configurations that they have to unmangle to get a useful result.

 	String s = """opt-out
		      line 2
		   """;

Result:
opt-out
.....................line 2
..................


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20190422/a06112f2/attachment-0001.html>


More information about the amber-spec-experts mailing list