Closed rko281 closed 3 years ago
I like it. But I prefer `$[anObject] already exists in $[anObject parent]` 😄
Interpolated strings would certainly be nice (although they don't really address the localisation requirement), but I think this is a fine idea John. The only immediate concern I had was whether snaffling the << binary selector for this would be regretted in future if we thought of a better use, especially if that use involved defining it on Object. However, as #<< is already in use in Integer, it is already unavailable for global use. This doesn't seem to clash with any precedent elsewhere either. So it gets my vote.
When revisiting code I'm gradually replacing string concatenation with
expandMacrosWith:
and its variants. One (very) small annoyance is the need to wrap the modified String expression with parentheses, for example:...becomes
I've implemented a simple workaround for this by adding the binary selector
<<
as an alias forexpandMacrosWithArguments:
. Thus the above example becomes:At its most basic this just needs a single method adding to String
On checking the base image it can be seen that the majority (>50%) of uses of expandMacros... involve just a single argument. A more sophisticated implementation using double-dispatch could avoid the need to wrap a single argument in an Array whilst still supporting multiple arguments where necessary.
String method:
Object method:
Collection method:
The Object implementation also needs duplicating in String to avoid a single String argument being treated as a collection of Characters.
This then enables expressions like:
A small downside with this approach is where a collection is intended as an individual argument rather than the collection of arguments. However this can be worked around by wrapping the collection in an Array, e.g.
I'd like to submit this as a potential base enhancement (I'm happy to implement this myself, with associated tests).