0 points

You can give it variables:

let foo = 4;
let bar = "bar";
format!("{foo}{bar}");

If you have a format string that long with arbatary expressions putting them all raw in the format string is not going to improve much. Better to give them actual names first.

permalink
report
reply
0 points

in this case it’s about 80% function calls. They’re convenience functions for assembly instructions, so they’re of the form:

load(Reg::D, "A"),
load_const(5),

which is more useful than variables would be. I guess i could use .join or a crate like concat_string? Either way i sorely miss arbitrary expression format strings from python =(

permalink
report
parent
reply
2 points

Creating an array of the function calls, and joining those seems more readable in that case.

Plus you don’t have to take care that you use the correct number of placeholders.

permalink
report
parent
reply
0 points

As far as I remember, the point for not allowing arbitrary expressions is that it makes what looks like formatting an arbitrary complex operation and that it doesn’t improve readability that much.

Although sometimes I miss being able to refer to fields in format, for function calls and especially this many, I agree with an advice to put strings in a vector and joining them. Plus, there is a limit to how many arguments format macro can accept, iirc

permalink
report
parent
reply

Programming Horror

!programming_horror@programming.dev

Create post

Welcome to Programming Horror!

This is a place to share strange or terrible code you come across.

For more general memes about programming there’s also Programmer Humor.

Looking for mods. If youre interested in moderating the community feel free to dm @Ategon@programming.dev

Rules

  • Keep content in english
  • No advertisements (this includes both code in advertisements and advertisement in posts)
  • No generated code (a person has to have made it)

Credits

  • Icon base made by Lorc under CC BY 3.0 with modifications to add a gradient

Community stats

  • 1

    Monthly active users

  • 19

    Posts

  • 55

    Comments

Community moderators