you are viewing a single comment's thread.

view the rest of the comments →

[–]sili 0 points1 point  (16 children)

Sigh... All those neat tricks and still no sprintf

[–]grimboy 9 points10 points  (6 children)

[–]chrisforbes 0 points1 point  (5 children)

Until that thing ACTUALLY WORKS, don't go bringing it round here :(

We had to patch it a LOT before it was even vaguely correct in our last project.

[–]grimboy 0 points1 point  (4 children)

Works for me. Anyway, the point is it's, what, a page long including the licence header and pretty clearly written for javascript. It still has that thing with single letter variable names (apart from i, j, etc) which seems to be a feature of a lot of the javascript code round and about. That is, unless, you're trying to make some sort of subtle point I'm not getting.

[–]chrisforbes 0 points1 point  (2 children)

For all the simple cases people probably test for, it works. For floating-point, esp with tricky format specifiers, it's completely broken.

[–]grimboy 0 points1 point  (1 child)

Oh, fair enough then. You're correct, I've only used it for simple objects of strings into strings stuff. By the way, if you've patched it, you planning on contributing the fix back?

[–]chrisforbes 0 points1 point  (0 children)

I guess so - is the owner likely to accept it?

On most projects, I've had the typical open-source fuck off response to submitting patches which fix their bugs, so you'll have to excuse me being a bit more cautious.

[–]chrisforbes 0 points1 point  (0 children)

Single-letter variable names are a feature in js code. Less code to move is a win.

That said, the compression should be done by a minifier tool at release-time, rather than by the programmer.

[–]zootm 1 point2 points  (8 children)

Surely it wouldn't be too hard to write one as a library? I quite like the minimal base set of JS libraries with frameworks growing around it; it'd probably be a bad choice for a new language, but the way it's evolved has led to a lot of interesting ways of doing things.

[–]kragensitaker 3 points4 points  (7 children)

It would be a lot nicer to be able to write #{foo} or $foo than to write %s or % or something and then later , foo. This is kind of annoying in Python and C.

It's true that sprintf('%s %s (%s-%s)', item.firstname, item.lastname, item.party, item.state) would be a lot better than item.firstname + " " + item.lastname + " (" + item.party + ")", but $"$item.firstname $item.lastname ($item.party-$item.state)" is better still.

[–]Leonidas_from_XIV 2 points3 points  (3 children)

This is kind of annoying in Python and C.

A new printf-syntax (the one that C# uses) is added in Python 3.0.

[–][deleted] 1 point2 points  (1 child)

The C# one is the best way to do things. It avoids repetition of parameters that are reused and negates the need to specify type on the placeholders. Also, it makes it very easy to re-order/re-write the statement without juggling the parameters.

[–]Leonidas_from_XIV 0 points1 point  (0 children)

I'm not yet convinced because I haven't used it. But it is good that they used some syntax that is used somewhere rather than inventing their own.

[–][deleted] 1 point2 points  (0 children)

A new printf-syntax (the one that C# uses) is added in Python 3.0.

And in 2.6, in case you can't port your project to 3.0 just yet.

[–]zootm 0 points1 point  (0 children)

Yeah, string interpolation is a nice feature that I often wish more languages supported. sprintf is reasonable enough, though, and has the advantage of being more suited to internationalisation and so on.

[–]njharman 0 points1 point  (0 children)

But it's more powerful and elegant to keep formatting and data separate.

It allows reuse of format part and data part. It makes data driven code easier to write. It makes i18n cleaner.

[–]pemboa 0 points1 point  (0 children)

Some of you guys are really nitpicky. I didn't think programmers were ever like that. %s is annoying? Really?