groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8431) toDebugString method as a core concept
Date Wed, 03 Jan 2018 23:03:00 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-8431?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16310437#comment-16310437
] 

Paul King commented on GROOVY-8431:
-----------------------------------

Some points to consider in no particular order:
* if any one has in-depth knowledge of what other languages provide in this area, please feel
free to comment
* we already have the {{dump}} method - is that a suitable starting point?
* we should clarify the intent when we say "human" readable output - my guess is we mean suitable
for consumption by a "human developer"
* we already have some methods with different but related functionality, can/should we be
leveraging/generalising those methods, e.g. the output from failed assert statements, {{InvokerHelper#toArrayString(Object[]
array, boolean verbose, int maxSize, boolean safe)}} and {{InvokerHelper#(Collection arg,
int maxSize, boolean safe)}}
* we should consider previous requests to override the default {{toString}} for some of the
built-in formatting and/or more generally, e.g. pr#566, GROOVY-3250, GROOVY-4654, GROOVY-4653,
GROOVY-4302

> toDebugString method as a core concept
> --------------------------------------
>
>                 Key: GROOVY-8431
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8431
>             Project: Groovy
>          Issue Type: Proposal
>          Components: GEP, groovy-jdk
>    Affects Versions: 3.x, 2.5.x
>            Reporter: mgroovy
>              Labels: features
>
> * Groovy should introduce a toDebugString method as a core concept, to separate debug
to-string-conversion semantics from heavily oversubscribed standard Java Object#toString.
> * The power of this feature as a core concept lies in support to create
> ## Easy to use, human readable debug output of any object
> ## Creating debug output of objects owned by other objects (i.e. hierarchical debug output)
> * Adding this feature should be relatively simple, the challenge is to decide what features/parameters
toDebugString should have, because this will be hard to change once the feature has been introduced.
  
> * The default implementation could
> ## Call the Java default Object#toString method
> ## Automatically create a reflection based output (performance will probably be bad for
this, so it might be better to enable this behavior through an annotation)
> ## Returns something along the line of getClass().simpleName + '@' + System.identityHashcode(this)
(though Object#toString is probably more useful)
> ## Fall back to the class' toString method (although in most cases it's most likely not
what the user wants/expects)
> * An extension would be for an overloaded toDebugString to take an indentationLevel and
indentationString parameter:
> {code}String toDebugString(int indentationLevel, String indentationString = '\t'){code}
> ** Implementations would be expected to indent the resulting String accordingly, which
is very helpful for
> ### Complex objects which require a multi-line output to make sense of them in a debug
log
> ### Outputting inner objects (e.g. a collection) owned by an object
> ** Groovy default implementation could be, to indent the result of calling toDebugString(),
by scanning for newline sequences in the returned string
> * Questions:
> ## Is there a better name than the (relatively long) "toDebugString" ?
> *** toDebugString was suggested, since it is easy to discover, and its purpose should
immediately clear
> ## Should the return type of toDebugString be GString instead of String ?
> *** This would allow for Groovy to process the objects embedded in the GString differently
> *** Having an additional GString toDebugGString() method might be an alternative
> ## Should there be additional parameters such as a terseness/verboseness parameter, which
indicates how compact or verbose the generated debug string should be (implementations would
be free to ignore this, of course) ?



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message