Question between concatenate and string.format()

Hey guys, another question.

Recently, I’ve been hearing that string.format(formatstring, ...) is more efficient than concatenate (..). Is it true and why? Should we use string.format() everywhere or there are places where we should use concatenate as well?

its better as it makes it more visually pleasing and hurts less to look at.

Concatenation could also be pleasing to look at for some people, but that’s not the point. I asked why is it better and where should we mostly use it. Plus, I’m not here to talk about which one looking visually pleasing. If there were no differences, I could’ve easily done this:

local function format(formatstring: string, ...)
    return (formatstring .. (...)); -- This is wrong, but you know what I tried to mean here.
end;

its not really any better, they both do the same thing, people just prefer string.format() as it just looks nice

If that was the actual case, then if I give a print example with concatenation:

print("Is this nil? Result: " .. nil);
-- Attempt to index string with nil

Vs

print(string.format(("Is this nil? Result: %s"), nil));
-- Is this nil? Result: nil

But again, I’m pretty sure there’s more reasons to it being used more instead of concatenation.

That’s simply because format basically does tostring() for you

Yeah, I guess that’s right. Doing stuff with string.format() will be easier so it won’t just error. Sorry if I sounded a bit harsh. Thanks for the info.

[MARKED YOUR POST AS SOLUTION]

glad to help :grinning:

character limit