-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The representation returned by value:toString
is not human readable
#296
Comments
The design of
At which step do you disagree with the logic? My view is that In the future, I expect us to define a Ballerina equivalent of JSON; as part of that there would be a function that converts an anydata value to a string in that format, which will clearly show an arbitrarily complex anydata structure, but neither point 1 nor point 2 would hold for it. |
Maybe something like the following would help (without losing the good points of toString):
|
Here is another proposal for the design of
With this design you get the following output: {name=Sameera county=England otherNames=[Madushan Jayasoma] addr={line2= line1=1234 Skyline st city=Mountain View postalCode=97803}} I think simply wrapping lists with |
I strongly dislike that approach. Using toString is doing something fundamentally different: it is using the conventions of normal, human, written language, which uses punctuation and white-space to separate things. toString does not work well for all cases, but it works great for simple lists of tokens, such as are often contained within strings in JSON or XML attributes or content. If toString wrapped with |
My main concern with the current approach is that it is not human readable, even though we say it is human readable. What I am striving for is to output a human-readable representation of Ballerina values. The current string representation is not useful IMO. I wouldn't use it because I don't see the structure even for simple structured values. In, my proposal my intention was not to output a parsable representation but to make the current representation a little bit more readable. If we stick to the current representation, I assume most people would use |
I am happy to tweak the design of toString, but I want to observe three requirements:
Subject to the above three points, whatever we can do to improve readability is good. The best I have come up so far is as follows:
So your example
would turn into
This is using parentheses to control grouping, in the same way as mathematics. I think this is more coherent with overall design of toString than using bits of Ballerina/JSON syntax. |
I had a long discussion with @sanjiva about this, and we came to the conclusion that it was better not to make any change here. The right solution to this problem is ti have the function described in #159 (we need to think of a good name for it). That function will always do a better job of providing a human readable representation of an arbitrary value because it does not have the constraint that I will clarify the docs for |
Consider the following example:
The output is:
This output is not human-friendly IMO. It is hard to tell the difference between a string with white spaces vs. an array of values. This representation has a flat structure, whereas the actual value has nested records, etc.
The text was updated successfully, but these errors were encountered: