Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String.format() #1

Closed
wants to merge 3 commits into from
Closed

Conversation

Smoozilla
Copy link

No description provided.

@alexfernandez
Copy link
Owner

Why not use the same format as util.format()? Like:

"Show something here: %s, or here: %s".format(1, 2);
  \=> "Show something here: 1, or here: 2"

@Smoozilla
Copy link
Author

Originally picked up the habit from C#, what you're suggesting doesn't allow stuff like:

var body = "<{0}>" +
"<{1}>{2}</{1}>" +
"</{0}>".format("body", "h1", "Hello World!");

As an example.

@alexfernandez
Copy link
Owner

The node convention is more limited, true, but also more familiar. Also: less typing of those pesky curly brackets.

In the prototypes library I try to put only things that have wide use already, not to invent new ways of doing things. (Which perhaps I should be doing.) I have often felt the need of formatting a string without importing util so I think your PR is a great opportunity to do it, but if the format is too alien I fear it is not going to be used as much except by people already familiar with C#.

@Smoozilla
Copy link
Author

Were you thinking something like this?

var body = "<%0>" +
"<%1>%2</%1>" +
"</%0>".format("body", "h1", "Hello World!");

@alexfernandez
Copy link
Owner

Hmmm, better, but still not the format that Node.js uses. Why not adopt it
as is? Granted, there may be some repetition in parameters, but I think it
can even be less confusing.

@alexfernandez
Copy link
Owner

A few weeks have passed, if you don't mind I will implement it as suggested, which is a shallow wrapper over util.format().

@alexfernandez
Copy link
Owner

Reimplemented with the same conventions as util.format() in 0.3.1, closing. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants