Re:Algorithmic Interviewing – Optimizing to Hire the Wrong D...
by philangist on Saturday August 31, 2013 @11:19PM
(#6308992)
Coding noob here. Can someone explain the problem with the
`for foo in queryset`
implementation? Is it that for loops are inherently inefficient? What would be a better alternative?
Re:Algorithmic Interviewing – Optimizing to Hire the Wrong D...
by victorf on Sunday September 01, 2013 @12:44AM
(#6309186)
I don't see a problem with an O(n) algorithm to set some property on n objects.
Re:Algorithmic Interviewing – Optimizing to Hire the Wrong D...
by victorhooi on Monday September 02, 2013 @01:01AM
(#6313522)
I think the issue is the call to save() (I assume this is meant to be outside the comma).
Basically, it'll hit the database after each query.
Re:Algorithmic Interviewing – Optimizing to Hire the Wrong D...
by philangist on Monday September 02, 2013 @02:52AM
(#6313775)
I originally thought it might be that too, but it seems to me like you'll have to hit the database n times for n queries no matter what. Unless Django has some builtin batch save functionality.
Re:Algorithmic Interviewing – Optimizing to Hire the Wrong D...
by victorhooi on Monday September 02, 2013 @08:26AM
(#6314808)
Hmm, there's bulk_create(), introduced in Django 1.4, to create multiple new objects in one DB call.
However, I'm not aware of anything that would do the same to update properties.
I made a mistake by hiring someone who knew django [who originally wrote plugins in WP] and the coding was just plain horrible. One such example.
`for foo in queryset: foo.prop = 'i m bar' foo.save() ` Simple things like this, where a good engineer would know because of O(n) nature of the code, the so called programmer didn't.
And then there are guys who fork every possible repo, have blogs about how-tos, etc but really can't code for nuts.