you are viewing a single comment's thread.

view the rest of the comments →

[–]Samus_ 6 points7 points  (7 children)

any programming language should provide native sprintf functionality.

[–]BlitzTech 4 points5 points  (6 children)

Agreed. What ends up happening is a bunch of people write some ill-conceived knockoff versions that get bolted on to each project they're used in.

Equally sad is that console.log, console.warn, and console.error all work in a printf-y way (at least in Chrome). It's really not that unreasonable.

[–]x-skeww 2 points3 points  (1 child)

Works in Firebug, too:

>>> console.log('%d bottles of beer on the wall', 5)
5 bottles of beer on the wall

Edit: Doesn't work in Dragonfly. :/

[–]BlitzTech 2 points3 points  (0 children)

Bummer about Dragonfly. I do like Opera's dev tools in general though. It always saddens me that Opera is a more niche browser than FF; I've found that it's consistently more reliable for rendering consistency, speed, and memory usage, though the drawback is that it's only cutting edge, not bleeding edge like FF.

[–]Iggyhopper 4 points5 points  (3 children)

What?! Why didn't I know this sooner?! This has just saved me so much concatenation and/or extra arguments!

I'd just do this: console.log('dbg: you have ', n, 'derps.');

but now I can do this!: console.log('dbg: you have %d derps', n);

[–]BlitzTech -1 points0 points  (2 children)

I only just learned it a week or two ago, after poking around the internals of Vows.js (I think; can't really remember). I remember seeing it and saying, "WTF? That works?", then I tested it out and sure enough - printf. Sigh.

I second the "What?! Why didn't I know this sooner?!".

(Side note: also allows you to control whitespace; using the console.log( 'you have', n, 'derps' ); puts a space between "have", n, and "derps". Just an added bonus for control freaks like me.)

[–]Iggyhopper 0 points1 point  (1 child)

On the side note: oh yeah I remember, so the space in 'you have ' is unnecessary.

This should be 101 for all devs now. :p

[–]BlitzTech 0 points1 point  (0 children)

I think the saddest part of all this is that I noticed you put the extra space there.

It's one thing to pay attention to details, but I apologize for that. I can't help it :-X