From: Carl Banks on 29 Jun 2010 23:24 On Jun 28, 3:07 am, Dennis Lee Bieber <wlfr...(a)ix.netcom.com> wrote: > On Sun, 27 Jun 2010 21:02:57 -0700, Stephen Hansen > <me+list/pyt...(a)ixokai.io> declaimed the following in > gmane.comp.python.general: > > > (This is an area where parametrized queries is even more important: but > > I'm not sure if MySQL does proper prepared queries and caching of > > execution plans). > > MySQL version 5 finally added prepared statements and a discrete > parameter passing mechanism... > > However, since there likely are many MySQL v4.x installations out > there, which only work with complete string SQL, MySQLdb still formats > full SQL statements (and it uses the Python % string interpolation to do > that, after converting/escaping parameters -- which is why %s is the > only allowed placeholder; even a numeric parameter has been converted to > a quoted string before being inserted in the SQL). > > It would be nice if MySQLdb could become version aware in a future > release, and use prepared statements on v5 engines... I doubt it can > drop the existing string based queries any time soon... Consider the > arguments about how long Python 2.x will be in use (I'm still on 2.5)... > Imagine the sluggishness in having database engines converted > (especially in a shared provider environment, where the language > specific adapters also need updating -- ODBC drivers, etc.) Thanks, your replies to this subthread have been most enlightening. Carl Banks
From: Nobody on 30 Jun 2010 08:22 On Tue, 29 Jun 2010 08:41:03 -0400, Roy Smith wrote: >> > And what about regular expressions? >> >> What about them? As the saying goes: >> >> Some people, when confronted with a problem, think >> "I know, I'll use regular expressions." >> Now they have two problems. > > That's silly. RE is a good tool. Like all good tools, it is the right > tool for some jobs and the wrong tool for others. "When all you have is a hammer, everything looks like a nail" ;) Except, REs are more like a turbocharged angle grinder: bloody dangerous in the hands of a novice. [I was going to say "hole hawg", but then realised that most of my post would be a quotation explaining it. The reference is to Neal Stephenson's essay "In the Beginning was the Command Line": <http://www.cryptonomicon.com/beginning.html>] > I've noticed over the years a significant anti-RE sentiment in the > Python community. IMHO, the sentiment isn't so much against REs per se, but against excessive or inappropriate use. Apart from making it easy to write illegible code, they also make it easy to write code that "mostly sort-of works" but somewhat harder to write code which is actually correct. It doesn't help that questions on REs often start out by stating a problem for which REs are inappropriate, e.g. parsing a context-free (or higher) language, and in the same sentence indicate the the poster is already predisposed to using REs.
From: Jorgen Grahn on 30 Jun 2010 10:14 On Tue, 2010-06-29, Stephen Hansen wrote: > On 6/29/10 5:41 AM, Roy Smith wrote: >> Nobody<nobody(a)nowhere.com> wrote: >> >>>> And what about regular expressions? >>> >>> What about them? As the saying goes: >>> >>> Some people, when confronted with a problem, think >>> "I know, I'll use regular expressions." >>> Now they have two problems. >> >> That's silly. RE is a good tool. Like all good tools, it is the right >> tool for some jobs and the wrong tool for others. > > There's nothing silly about it. > > It is an exaggeration though: but it does represent a good thing to keep > in mind. Not an exaggeration: it's an absolute. It literally says that any time you try to solve a problem with a regex, (A) it won't solve the problem and (B) it will in itself become a problem. And it doesn't tell you why: you're supposed to accept or reject this without thinking. How can that be a good thing to keep in mind? I wouldn't normally be annoyed by the quote, but it is thrown around a lot in various places, not just here. > Yes, re is a tool -- and a useful one at that. But its also a tool which > /seems/ like an omnitool capable of tackling everything. That's more like my attitude towards them. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o .
From: Stephen Hansen on 30 Jun 2010 11:23 On 6/30/10 7:14 AM, Jorgen Grahn wrote: > On Tue, 2010-06-29, Stephen Hansen wrote: >> On 6/29/10 5:41 AM, Roy Smith wrote: >>> Nobody<nobody(a)nowhere.com> wrote: >>> >>>>> And what about regular expressions? >>>> >>>> What about them? As the saying goes: >>>> >>>> Some people, when confronted with a problem, think >>>> "I know, I'll use regular expressions." >>>> Now they have two problems. >>> >>> That's silly. RE is a good tool. Like all good tools, it is the right >>> tool for some jobs and the wrong tool for others. >> >> There's nothing silly about it. >> >> It is an exaggeration though: but it does represent a good thing to keep >> in mind. > > Not an exaggeration: it's an absolute. It literally says that any time > you try to solve a problem with a regex, (A) it won't solve the problem > and (B) it will in itself become a problem. And it doesn't tell you > why: you're supposed to accept or reject this without thinking. > > How can that be a good thing to keep in mind? That it speaks in absolutes is what makes it an exaggeration. Yes, it literally says something kind of like that (Your 'a' is a mischaracterization). It's still a very good thing to keep in mind. Its a "saying" -- a proverb, an expression. Since when are the wise remarks of our ancient forefathers literal? Not last I checked. Reading into a saying as not a guide or suggestion or cautionary tale but instead a doctrinal absolute is where we run into problems, not in the repeating of them. -- ... Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/
From: Terry Reedy on 30 Jun 2010 12:56
On 6/30/2010 8:22 AM, Nobody wrote: >> I've noticed over the years a significant anti-RE sentiment in the >> Python community. > > IMHO, the sentiment isn't so much against REs per se, but against > excessive or inappropriate use. Apart from making it easy to write > illegible code, they also make it easy to write code that "mostly sort-of > works" but somewhat harder to write code which is actually correct. > > It doesn't help that questions on REs often start out by stating a problem > for which REs are inappropriate, e.g. parsing a context-free (or higher) > language, and in the same sentence indicate the the poster is already > predisposed to using REs. They also often start with a problem that is 'sub-relational-grammar' and easily solved with string methods, and again the OP proposes to use the overkill of REs. In other words, people ask "How do I do this with an RE" rather than "What tool should I use for this, and how". If people asked "How do I push a pin into a corkboard with a (standard) hammer" or "How do I break up a concrete sidewalk with a (standard) hammer), it would not be 'anti-hammer sentiment' to suggest another tool, like pliers or a jackhammer. -- Terry Jan Reedy |