Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #58298
| References | <l4v12j$98o$1@ger.gmane.org> <CAPTjJmocz_Kq-TxFzOBRCmq_xxVWdrYiz8LapRSr-r3LXpuAKw@mail.gmail.com> <mailman.1898.1383270899.18130.python-list@python.org> <107ac59a-229c-4da0-bea1-a93834624bc8@googlegroups.com> |
|---|---|
| Date | 2013-11-02 10:13 +1100 |
| Subject | Re: Python wart |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1943.1383347616.18130.python-list@python.org> (permalink) |
On Sat, Nov 2, 2013 at 8:47 AM, Peter Cacioppi <peter.cacioppi@gmail.com> wrote:
> I always thought printf was sort of crappy.
>
> I thought the C++ << business even worse.
Oh, you'll get no argument from me about the std::*stream types! When
I write C++ code, I almost exclusively use C-style formatted strings,
even sometimes going to the extent of using fopen() just so I can use
fprintf() rather than fstream. Also, I often create a class something
like this:
struct format
{
char *data;
format(const char *fmt, ...);
operator char *() {return data;}
};
where the constructor calls vsprintf and there's a bit of new/delete
work to manage memory, but that's all under the covers; in code, I use
it like this:
some_function_call(format("Hello, %s!", "world"));
making it almost as if it's a function returning a string, like you
would in Python.
Most of the problems with printf come from the fragility of C's
variadic functions. Some C compilers can deal with that (gcc happily
checks printf args), but there are still fundamentally hard problems
around it. They don't apply in Python (or Pike, which has an sprintf
function[1] with even more power), as issues can be signalled with
exceptions - clean, easy, safe.
ChrisA
[1] http://pike.lysator.liu.se/generated/manual/modref/ex/predef_3A_3A/sprintf.html
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Python wart Chris Angelico <rosuav@gmail.com> - 2013-11-01 12:54 +1100
Re: Python wart Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-11-01 00:11 -0700
Re: Python wart Chris Angelico <rosuav@gmail.com> - 2013-11-01 18:59 +1100
Re: Python wart Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-01 09:08 +0000
Re: Python wart Chris Angelico <rosuav@gmail.com> - 2013-11-01 20:17 +1100
Re: Python wart Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-01 09:32 +0000
Re: Python wart Chris Angelico <rosuav@gmail.com> - 2013-11-01 20:42 +1100
Re: Python wart Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-11-01 14:47 -0700
Re: Python wart Chris Angelico <rosuav@gmail.com> - 2013-11-02 10:13 +1100
Re: Python wart Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-11-01 18:11 -0700
Re: Python wart Chris Angelico <rosuav@gmail.com> - 2013-11-02 12:18 +1100
Re: Python wart Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-11-01 18:26 -0700
csiph-web