News for hackers. Stuff that matters.
Re:Beyond PEP 8 – Best practices for beautiful intelligible ... by pjtr on Saturday August 08, 2015 @03:29AM (#10026618)
Can I ask about a similar real problem I had a few times? How would you format this code?

    class Batman():
        # ...
        def handle_jokes(self, villains):
            for villain in villains:
                if villain.supports_jokes:
                    formats, transports = villain.query_joke_formats_and_transports()
                    # ...
That long line is 82 characters. Assume there's a good reason formats and transports are queried together. In practice this leads to variable names f and t. :(
Re:Beyond PEP 8 – Best practices for beautiful intelligible ... by sago on Saturday August 08, 2015 @12:07PM (#10027659)

    query = villain.query_joke_formats_and_transports()
    formats, transports = query
or

    formats, transports = (
        villain.query_joke_formats_and_transports())
or

    formats, transports = \
        villain.query_joke_formats_and_transports()
Of which, we tend to do the first.

Again, the longer version is clearer and simpler, but the shorter version is not so confounding that it is a slamdunk argument for longer lines, particularly as, for any length line, you could get this problem, so you'll have to do something like it eventually. If you're seeing this all over the place, it may be worth wrapping the API in more pythonic terms. 'Getters' taking no arguments, for example, are often a code-smell in python, though queries (as in your case) are a good exception, since it is also not great to have properties do expensive work (like querying a DB, say).

Re:Beyond PEP 8 – Best practices for beautiful intelligible ... by pjtr on Sunday August 09, 2015 @01:35AM (#10029599)
In reality there are multiple arguments to these functions, I just omitted them here to simplify the example.

What other more pythonic terms could be used? The proposed rename to jokes is completely unrealistic.

It seems kind of sad to butcher such nice simple code for these artificial non-reasons.

Re:Beyond PEP 8 – Best practices for beautiful intelligible ... by mherrmann on Saturday August 08, 2015 @06:41AM (#10026897)
I would rename query_joke_formats_and_transports to jokes.
Re:Beyond PEP 8 – Best practices for beautiful intelligible ... by 1wd on Saturday August 08, 2015 @06:59AM (#10026916)
What if that's part of a published interface? One that maybe also contains things like query_joke_history(), format_joke(), transport_joke() and execute_practical_joke().
Re:Beyond PEP 8 – Best practices for beautiful intelligible ... by mherrmann on Saturday August 08, 2015 @07:24AM (#10026955)
If it's painful enough, I would write an adapter as done in the video.