Code so bad it causes me physical pain

Here's the code.

def get_categories(file):
    """
    Get categories.
    """
    verify_file(file)

    categories = set()

    with open(file, "r") as cat_file:
        while line := cat_file.readline().rstrip():
            categories.add(line)

    return categories

To me this was terrible. truly and deeply horrifying. Let me count the ways.

  1. The docstring repeats the name of the function …
more ...

Dictionary clear() as a code smell

Using the clear() method of a dict isn't *wrong*. But. The reasons have to be investigated. I got a question about this code not working "properly." ("Properly"? Seems too vague to be useful.)

Here's a summary of the example.

final_list = []
temp_dict = {}
for obj in some_source:
    cool_function(obj, temp_dict)
    final_list.append …
more ...





Bind Variables and Prepared Statements -- Good, Bad or Indifferent?

A Gentle Reader provided references to folks who are distrustful of prepared statements.

See "Prepared Statements, Musings " and "Prepared statements are dead, long live prepared statements ".

In "musings" we're told "...users do not clean up/close unused prepared statements." For this reason, they're bad, and should be avoided. Eventually, "...unless …

more ...

What's Central Here?

The requirements are a sequence diagram showing a complex back-and-forth with the vendor's web service. Each request and reply is detailed, but there's no overview or summary stated. It's implied, and all of the business folks can articulate it, but no one wrote any of it down.

This looks like …

more ...

Wrestling with REST

REST is cool because there's less protocol there -- little more than HTTP and some kind of representation for objects (XML, JSON or whatever.) It seems to me that REST with JSON is a very lightweight approach to implementing web services. Doing this in Python further trims down the technology stack …

more ...