StringJoiner: detect or fix delimiter collision?
mike.duigou at oracle.com
Sat Aug 31 21:13:15 UTC 2013
On Aug 30 2013, at 23:40 , Philip Hodges wrote:
> Why is there such a bandwagon rolling for this "convenience" feature?
Perhaps others just don't agree with you. The choice of functionality offered in the JDK 8 StringJoiner was not arbitrary or haphazardly chosen. If it doesn't meet your particular needs, I am sorry to hear that. Our belief as the proposers is that it offers a reasonable mix of functionality and simplicity to cover useful number of requirements. Our intent was certainly not to create the kitchen magician  of string joiners that attempted to incorporate every conceivable option. In particular your concerns about escaping are out of scope for the joiner in part because
String concat = strings.stream().map(MyUtils::escape).collect(Collections.joining(","));
seems like an adequate and flexible solution to most people.
> We already have joiners in apache commons and guava.
This is the reason that StringJoiner was considered for JDK--that many others were "rolling their own".
> At first I thought they were cool. Then I tried to use them in anger.
> And was forced to roll my own.
I would encourage you to share your implementation or the javadocs as grist for discussion. An actual alternative is the *only* thing that is likely to be persuasive.
> That can't be right.
Sometimes it is. The JDK doesn't make any attempt to satisfy everyone (or anyone). We all end up writing lots of non-business logic utility functions to bridge gaps in what JDK offers. This is normal. And, if it turns out to be something lots of people need then it's entirely possible that it could be added to the JDK.
> A more elaborate offically blessed feature that
> only does half the job is worse than useless.
> Without the extra complex ability to detect or avoid collisions
> it is neither "nice", nor a "Good Thing".
> "StringJoiner and String.join(...) are long, long overdue. They are so long overdue that the vast majority of Java developers likely have already written or have found utilities for joining strings, but it is nice for the JDK to finally provide this itself. Everyone has encountered situations where joining strings is required, and it is a Good Thing™ that we can now express that through a standard API that every Java developer (eventually) will know. "
> On 2013-07-23 22:09, Mike Duigou wrote:
>> On Jul 23 2013, at 12:43 , ph wrote:
>>> didn't see delimiter collision mentioned anywhere - are you really offering
>>> an interface that only joins a list of entries without escaping or quoting
>>> or even checking for separators (or escape or quote sequences) that might
>>> occur in the entries?
>> Correct. StringJoiner makes no effort to address escaping/quoting.
> > Doing so would add a lot of complexity that would not
> > useful interesting to most users and probably still wouldn't satisfy everyone.
>> If you wish some form of escaping or quoting you can pre-processed entries however you like before joining them.
More information about the core-libs-dev