Dan & Stuart (& Martin, below),

>> he argued that if your code was getting constrained to the right-hand edge (in his words "more than 3 levels of indentation"), your functions were probably getting too complex 

OK, I get that. I follow the rule of refactoring down to "single-purpose" functions all the time. But, here's an example of a function that can't get any simpler: It's only doing one thing (repeatedly 9 times). It should only take (9 + overhead) lines of code, but with PEP8 it gets spread out to 50 lines.


    def interpret_extra_channel_data(self, mem, _mem):
        mem.extra = RadioSettingGroup("Extra", "extra")
        mem.extra.extend(
            [
                RadioSetting(
                    "rev", "Reverse", RadioSettingValueBoolean(_mem.rev)
                ),
                RadioSetting(
                    "compander",
                    "Compander",
                    RadioSettingValueBoolean(_mem.compander),
                ),
                RadioSetting(
                    "talkaround",
                    "Talkaround",
                    RadioSettingValueBoolean(_mem.talkaround),
                ),
                RadioSetting(
                    "pttid",
                    "PTT ID",
                    RadioSettingValueList(
                        self._PTT_IDS, self._PTT_IDS[_mem.pttid]
                    ),
                ),
                RadioSetting(
                    "bclo",
                    "Busy Channel Lockout",
                    RadioSettingValueList(self._BCLO, self._BCLO[_mem.bclo]),
                ),
                RadioSetting(
                    "optsig",
                    "Optional Signaling",
                    RadioSettingValueList(
                        self._OPT_SIGS, self._OPT_SIGS[_mem.optsig]
                    ),
                ),
                RadioSetting(
                    "dtmfSlotNum",
                    "DTMF",
                    RadioSettingValueList(
                        self._DTMF_SLOTS, self._DTMF_SLOTS[_mem.dtmfSlotNum]
                    ),
                ),
                RadioSetting(
                    "twotone",
                    "2-Tone",
                    RadioSettingValueList(
                        self._TONE2_SLOTS, self._TONE2_SLOTS[_mem.twotone]
                    ),
                ),
                RadioSetting(
                    "fivetone",
                    "5-Tone",
                    RadioSettingValueList(
                        self._TONE5_SLOTS, self._TONE5_SLOTS[_mem.fivetone]
                    ),
                ),
            ]
        )

vs. this version with a 132 char line limit:

    def interpret_extra_channel_data(self, mem, _mem):
        mem.extra = RadioSettingGroup("Extra", "extra")
        mem.extra.extend(
            [
                RadioSetting("rev", "Reverse", RadioSettingValueBoolean(_mem.rev)),
                RadioSetting("compander", "Compander", RadioSettingValueBoolean(_mem.compander)),
                RadioSetting("talkaround", "Talkaround", RadioSettingValueBoolean(_mem.talkaround)),
                RadioSetting("pttid", "PTT ID", RadioSettingValueList(self._PTT_IDS, self._PTT_IDS[_mem.pttid])),
                RadioSetting("bclo", "Busy Channel Lockout", RadioSettingValueList(self._BCLO, self._BCLO[_mem.bclo])),
                RadioSetting("optsig", "Optional Signaling", RadioSettingValueList(self._OPT_SIGS, self._OPT_SIGS[_mem.optsig])),
                RadioSetting("dtmfSlotNum", "DTMF", RadioSettingValueList(self._DTMF_SLOTS, self._DTMF_SLOTS[_mem.dtmfSlotNum])),
                RadioSetting("twotone", "2-Tone", RadioSettingValueList(self._TONE2_SLOTS, self._TONE2_SLOTS[_mem.twotone])),
                RadioSetting("fivetone", "5-Tone", RadioSettingValueList(self._TONE5_SLOTS, self._TONE5_SLOTS[_mem.fivetone])),
            ]
        )

That cuts it down to 15 lines. This is much, much easier to read. It only takes a split second to understand that "it's just a block of settings." The 50-line version takes way longer to inspect before you can see that there's nothing special about any of the 9 settings.

Martin and Stuart,

>> side-by-side viewing

I would also argue that even then, it's more important to preserve vertical real estate than horizontal. When all you can see within 50 physical lines is 9 logical lines of code, you easily lose track of where you are in the grand scheme of things. Sticking to this one simple example, say that someone added six more RadioSetting calls to this function and moved the Compander setting to the bottom because it logically goes together with one of the new settings. With one line per call, you'd spot the difference immediately in a side-by-side. With 15 calls spread across 80 lines, you wouldn't.

I'm just say'n, it's been 50 years since the world went from 80-character teletypes to 132-character line printers and I, for one, never looked back.

Anyway, If you can't see your way to 132 much less 160, I'll take whatever I can get. Do I hear 100? Hell, I'd even take 90. I lost count of how many comments I've written in the last few days that had to be continued to the next line because of just one word.

(Dan, I saw your "not interested" declaration. Please know that I'm not in the habit of beating a dead horse, so this will be my last post on the subject, and I'll certainly respect your final decision. I'll get back to work now. Thanks for listening.)



Virus-free.www.avg.com