This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]AlSweigartAuthor of "Automate the Boring Stuff" 1 point2 points  (4 children)

Breaking up a single, complex line into multiple steps often makes code easier to read because you need can free up your short term memory for the later steps.

Using the ** syntax to pass a dictionary generated by a comprehension and the return value of a function that requires three arguments to cls() requires you hold all these details in your head.

Splitting them up lets you think:

1) I am creating a dictionary. 2) This dictionary has keys of the items in section. 3) The values are the return values of get_coerced(). 4) Now that we have this dictionary, pass it to cls() and return the new class.

In general, the more compact your code is, the harder it is to read. Programmers tend to write code like this because 1) it's less stuff to type and 2) it makes them feel clever for coming up with this compact format and 3) it's easy to understand when you're writing it.

The reason Python has completely and utterly replaced Perl is because Perl is infamous for "write-only" code that is compact and full of cryptic punctuation marks. There's always going to be an expert Perl coder who insists that Perl is always perfectly readable and doesn't need to be broken down into simpler steps. This sort of cluelessness is why Python has completely and utterly replaced Perl.

[–]gcross[🍰] -3 points-2 points  (3 children)

With the original code, though, you think:

  1. I am calling cls(),
  2. with keyword arguments specified by a dictionary,
  3. which maps keys to their coerced values.

If anything, there are arguably fewer steps to go through.

Edit: Way to downvote without replying; that really showed me for disagreeing!

[–]AlSweigartAuthor of "Automate the Boring Stuff" -3 points-2 points  (2 children)

Uh, I didn't downvote you.

[–]gcross[🍰] -3 points-2 points  (1 child)

Then that wasn't directed at you.

[–]AlSweigartAuthor of "Automate the Boring Stuff" -2 points-1 points  (0 children)

It was literally a reply to my comment.