Mar 10

Ugly code of the week 1

Ugly code of the week #1

As I'm in the process of working out what to write for my first weeknote I thought I'd start another weekly posting schedule - hence Ugly Code Of The Week.

I thought it would be quite useful, or at least interesting historically, to occassionally post a line of code that I am particularly ashamed of and in the process of cleaning up. I'm hoping that I can use this as a record of what I want to avoid. It won't always be Python, and I should point out that not all of my code is like this - I just tend to write code before going back to clean it up once it works - a habit I am trying to reduce by getting it right first time.

results = [ add_fields(show_fields,x) for x in model_cls.objects.filter( Q(**{qf:q}) ).order_by(field).all() ]

Yes, I know. Sorry, I won't do it again. Part of the problem with this is that the naming is not very clear, and another problem is that there is far too much going on in one line for a reasonable amount of readability. On the other hand, list comprehensions rock.

Tags: python

About

This is the official blog of Servercode Ltd where we will be posting our weeknotes and other things of interest that we may have found from time to time.

Subscribe

Categories

Recent Posts

Archive

BlogRoll

Popular Posts