Should I be using something like
print(string.lower("Hello")) -- > "hello"
print(("Hello"):lower()) -- > "hello"
by default in my scripting?
I am aware that using
string.lower works on numbers (eg.
string.lower(2)) whereas calling
:lower() on numbers (eg.
(2):lower()) will result in an error.
:lower() keeps the code shorter when not working with numbers (which is almost always the case here).
So, in terms of performance (which way is more efficient, and is this difference significant?) and conventions (is there a general preference by scripters?), would
str:lower() be the better default option?
This question extends to several other
string library functions that can also be called as methods of a string type, such as
byte, et cetera. For example,
string.format("Hello %s world!", "cruel") versus
("Hello %s world!"):format("cruel").