-
Notifications
You must be signed in to change notification settings - Fork 175
API: Consider the formatted output/logging functions #419
Description
(Request For Early Feedback. Work in Progress)
Latest State
- Brief Illustration of the Proposed Changes (with Code Fragments and Usage Examples)
- What Happens to DoubleAsStringWithFormat() and IntAsStringWithFormat().
- How the Changes Cope With the Other Proposals
Earlier Story
(Links DoubleAsStringWithFormat(), IntAsStringWithFormat(), Standard numeric format strings, Custom numeric format strings).
Discussion:
[12:42 PM] Bettina Heim
Hi all,
As part of adding support for Q# to the QIR runtime, we came across the logging functions that allow to give a formatting option. Right now, the option seems to be exactly what C# provides. Since this is pretty extensive and I am not eager to blindly duplicate the C# behavior in our native implementation, I would like to gather your input regarding what formatting options we need and want to support going forward?
[12:50 PM] Chris Granade (THEY/THEM)
There's not a single line of Q# in all of our libraries or samples that calls either function...
Thinking to kind of first principles for the language and libraries, though, the whole point of Message is to provide optional logging information back to the host. To that end, I wouldn't think that it's intended that we should provide UX features like formatting at the Q# level.
I know Bettina, Alan and I played around with the concept of a function that would emit logging info other than strings years ago (e.g.: if a Q# program wants to send a Double to the host as a log message); that may be better than trying to handle formatting at the Q# level.
[12:57 PM] Bettina Heim
Chris Granade (THEY/THEM) Do you know why these have been added in the first place? Do you know of anyone else that could be using them? Would it be good to keep some minimal formatting options, or would you suggest deprecating them?
My inclination would be to allow for some minimal formatting, but definitively not the extensive support that C# provides.
Robin Kuzmin, What kind of formatting support does C++ provide?
[1:32 PM] Robin Kuzmin
The simple option is the printf() formatting of C, see "Conversion specifiers" (or a broader picture - "Format of the format string") in the printf() manual page.
As for C++, let me summarize...
As a short answer I would say, C++ formatted output is harder to adapt as an implementation of the Q# calls. And that C++ formatted output would be described here. E.g. see "hex" that will take you to here and show the examples like std::cout << std::hex
, after which all the integer output will be in hexadecimal form.
[1:48 PM] Robin Kuzmin
As a minimalistic implementation I would say that we need
- the conversion of any type to string,
- concatenating the strings and string literals,
- and outputting/logging a string.
[1:48 PM] Robin Kuzmin
And most (if not all) of that is already implemented, I believe.
[2:07 PM] Chris Granade (THEY/THEM)
Do you know why these have been added in the first place?
I don't, no; they are amongst the first intrinsics added to the language, IIRC, back when everything was somewhat chaotic.
Do you know of anyone else that could be using them? Would it be good to keep some minimal formatting options, or would you suggest deprecating them?
I'm not aware of such, no; was unable to find a single usage when I looked, so I'm not sure there's a lot of demand for that feature. My initial thought would be to deprecate entirely for now, but happy to discuss further.
[8:20 PM] Robin Kuzmin
I looked at .NET's (C#'s) formatting - Standard numeric format strings and Custom numeric format strings.
looks like for the minimalistic implementation (mentioned in my previous 2 posts) we also need (EN-US locale):
- Hexadecimal (at least for Int type)
- Exponential (scientific)
- Fixed-point (with the specification of number of digits before and after the
.
)