Skip to content

String interpolations vs util.format #10

@vilimco

Description

@vilimco

I think that we should define this and what are we going to use.

I have seen that on some project that util module is being used for string formatting, which is exact equivalent of PHPs sprintf function.

console.log(
    util.format("some text %s, and some number %d", 
        stringVar, 
        numberVar
   ) 
);

While it has its benefits, like never used %j format, this was written while there were no native string interpolations in nodeJS. Something more natural for the JS world are native string interpolations being used in following format.

console.log(`some text ${stringVar}, and some number ${numberVar}`);

I get that we are used to sprintf format from PHP, but I would go propose that we go with something that is native and ditch util.format.
While we pull one less dependency that way, it really looks a lot prettier and less bloated.

I am ok with using this module in cases that require translation and we are binding specific values that just need templating or something else, but for pure logging it just looks unreadable.

What do you guys think?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions