> On Jun 7, 2018, at 1:39 PM, Guy Steele <guy.ste...@oracle.com> wrote:
> 
> 
>> On Jun 7, 2018, at 9:11 AM, Jim Laskey <james.las...@oracle.com 
>> <mailto:james.las...@oracle.com>> wrote:
>> 
>> This topic died down while we were off doing other things including some 
>> more research, consequently Raw String Literals will miss the JDK 11 train.
>> 
>> We have introduced some new String methods in JDK 11 (and one Predicate 
>> method) that will help us along the way (used in some of the examples below.)
> 
> Very nice.  I do note that the meaning of .indent() is not immediately 
> apparent from the name, especially because if it does anything at all, it 
> *removes* some indentation.
> 
> Allow me to suggest eliminating .indent(), and replacing it with 
> .reindent(n), which has the effect of .indent().indent(n) (in other words, it 
> "changes the indentation to be n”).  If you don’t like the name “reinvent”, 
> it could be “leftMargin”.

Part of the goal was to shorten the name to reduce the annoyance quotient. 
“reindent” speaks to me more than “leftMargin” (starts searching thesaurus.) 
The combo makes sense too. Then you start thinking in terms of indent is just 
reindent without the magic.

An alternative “think” is  string.indent().indent(n) -> 
string.indent(string.minIndent() + n). Unfortunately, this pattern doesn’t 
chain well.

> 
> The name “lines” is similarly uninformative, and the LinesOptions business 
> seems kind of clunky: useful if we expect to be “computing lines options”, 
> but if not, I would rather see
> 
>         System.out.println(`
>            abc
>            def
>            ghi
>         `.removeOneLeadingBlankLine().removeOneTrailingBlankLine().count());
> 
> and other available methods are
> 
>       removeAllLeadingBlankLines()
>       removeAllTrailingBlankLines()
>       removeAllSurroundingBlankLines()
>       removeAllBlankLines()
> 
> which I think would cover 99.9% of uses.

Any shorter naming options?

Assuming you are returning Strings, this would be costly (string copying), but 
reasonable. 

If you are returning Stream<String>, first and last combinators really suck 
with streams. That is, you have to make full passes with each call.

Internally, I have it implemented as .lines(int maxLeadingBlanksRemoved, int 
maxTrailingBlanksRemoved)

        System.out.println(`
           abc
           def
           ghi
        `.lines(1,1)).count();

This keeps everything single pass.


> 
> —Guy
> 
> P.S. In doc for .indent(int n), "take affect” => “take effect”.
> 

D’oh thanks.

Cheers,

— Jim

Reply via email to