Charlie Martin

The only problem being that this doesn't work: if the args dict doesn't have a value for the 'website' key you get a KeyError.

```

In [3]: args = dict()

In [4]: website = args['website'] or "https://imsanjams.tk/"

---------------------------------------------------------------------------

KeyError Traceback (most recent call last)

<ipython-input-4-1810666da1c9> in <module>

----> 1 website = args['website'] or "https://imsanjams.tk/"

KeyError: 'website'

In [5]:

```

```

website = args['website'] if 'website' in args else "https://imsanjams.tk/"`

```

works, but

```

website = args.get('website', "https://imsanjams.tk/")

```

is better yet.

--

--

One token: """

Wrap the whole string in """With subject AS ...""" and you get rid of all the nasty \ line endings — which are also notorious bug traps, since you can't visually distinguish between "\newline" and "\ space newline" — and you follow the usual conventions for long strings.

Alternatively, you can exploit the fact that Python automagically concatenates adjacent strings, as with

query = (

"a string "

"another string"

)

print(query)

example output:

$ python3 doesitwork.py

a string another string

Having a good coding style is a fine idea: as you note, programs are read far more than they're written. But making sure you exploit the features of the language that can make the code clear is even better.

--

--

Light bulbs have lifetimes while burning that are characterized by an exponential distribution, which is also known as a memoryless distribution: the probability of it failing at time t is the same over its entire lifetime. I'm sure this bulb is never turned off or on so it's never confronted with the time most bulbs fail. The most probable, if most implausible, explanation is that of the thousands or millions of light bulbs, this is the one that won the lottery.

--

--

So, in similar spirit of brevity: you're wrong.

Like most programming arguments, this one misses the point. The right thing to do with code structure is to do the right thing. In many cases, eg where you have a computed value that is to be returned, then a single return makes sense. In other cases, like where you have some guards on inputs before performing a complex computation, it can be much clearer to return as soon as a guard fails, rather than having to follow code down pages to find out what happens. And then, of course, there are exceptions, which naturally return from the point at which the exceptional condition occurred; to avoid that you have to do some really atrocious things.

Honestly, any "good practice" recommendation can be a good guideline, but they don't excuse you from the responsibility to think.

--

--

Charlie Martin

Charlie Martin

Creative software innovator, educator, architect, writer. Consultant. Mentor at https://www.wyzant.com/Tutors/CharlieM