Skip to content

[SUGGESTION] Better "printf debugging" #1409

@DyXel

Description

@DyXel

Essentially, implement the "self-documenting f-strings" from Python (link to feature). Note that today most of Python-style formatting is already supported OOTB (Link to cppfront documentation), since C++'s standard format specification is based on Python's specification (cppreference), this is just a small but nice productivity enhancement to have.

Examples:

>>> my_var = 42
>>> f"Prefix|{my_var}|Postfix"
'Prefix|42|Postfix'
>>> f"Prefix|{my_var=}|Postfix"
'Prefix|my_var=42|Postfix'
>>> f"Prefix|{my_var =}|Postfix"
'Prefix|my_var =42|Postfix'
>>> f"Prefix|{my_var = }|Postfix"
'Prefix|my_var = 42|Postfix'
>>> my_f = lambda x: x+2
>>> f"Prefix|{my_f(2)}|Postfix"
'Prefix|4|Postfix'
>>> f"Prefix|{my_f(2)=}|Postfix"
'Prefix|my_f(2)=4|Postfix'
>>> f"Prefix|{my_f(2) =}|Postfix"
'Prefix|my_f(2) =4|Postfix'
>>> f"Prefix|{my_f(2) = }|Postfix"
'Prefix|my_f(2) = 4|Postfix'

You can then imagine how cppfront's would look like:

test: std::string_view = "My String";
main: () = std::cout << "Prefix|(test = )$|Postfix";

// Outputs: Prefix|test = My String|Postfix

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions