On Wed, Sep 10, 2008 at 5:55 AM, Per Cederberg <[EMAIL PROTECTED]> wrote:
>
> I guess this is a question for Bob, but others might have some clues
> here also. Thus sending it to the list.
>
> I've recently done some Python coding and found the % string formating
> there very convenient. Now, as MochiKit is so inspired by Python, I
> find it a bit odd that there is no generic string formatting similar
> to the Python version. Is this just due to lack of time or is it a
> deliberate omission?
>
> The MochiKit.Format.numberFormatter function is of course very
> powerful, but it doesn't provide everything that the Python equivalent
> does:
>
> 1. No type selection mechanism. Cannot format strings, random objects
> or hexadecimal, octal, binary or floating point exponential numbers.
> 2. No generic string formatting. Cannot output "Value: %d" or similar.
> 3. Inconvenient API for throw-away formatting. You have to create a
> formatting function and then call it (very Java-ish).
>
> Has anybody created a generic formatting function in JavaScript? Other
> libraries? Or am I the only one seeing the need?

I've wanted to have it once or twice, but the number formatting has
worked out well for what I wanted to do. Conversely, Python's
formatting functions don't allow you to put thousands separators in
numbers, which is something we do very often.

The number formatter uses the same spec as Java does so the way it
acts should be of little surprise. The API isn't terribly inconvenient
other than the length of the name I guess, since functions are first
class. numberFormatter("###,###%")(2134) isn't that much longer than
say formatNumber("###,###%", 2134) or something like that.

If we do implement a string formatting library my personal preference
would be the advanced string formatting from PEP 3101 that is going
into Python 2.6/3.0:
http://www.python.org/dev/peps/pep-3101/

We've also got a similar Erlang implementation here:
http://code.google.com/p/mochiweb/source/browse/trunk/src/mochifmt.erl

-bob

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to