Assignment with line continuation - Python

Line continuation is a bit taboo, but not the end of the world. We must always strive to write code such that some other programmer down the line can understand what we were doing.

Using the line continuation character \ is but one tool in our arsenal for achieving this goal of legibility.

Naming conventions are another issue. As da Vinci said "Simplicity is the ultimate sophistication." If you can make variable names small AND understandable, then you are sophisticated ;-). It's too easy to just say var1, var2, var3 etc. Coming up with good names is a skill, which takes effort.

Would you rather see a variable named ChiefExecutiveOfficerOfCompanysName or CEOName?

If you can combine if statements, then your code can become even more legible. Chances are, if you have some big hierarchy of if...else-if, then you're doing something wrong (this is a code smell). For example, you might change this:

if this:
    if that:
        if here:
            if there:

Into this:

if this and that and here and there:

Or toss such gross logic into an evaluator function like so:

if EvaluateConditions(<args>):

Breaking code up into logical pieces, and putting those pieces into functions is another way to make things readable (we only have so much RAM, and we'd like to fit entire functions in it... humans aren't very good at paging)

Avoid copying and pasting code with slight changes by using parameterized functions, or some good design patterns


I don't think there is any problem with line continuation in Python. But sometimes I prefer this:

big_variable['big_key']['big_value'] =(
    another_big_variable_that_pushes_line_over_79_characters
)

It is useful in long expressions, too.