On 04/03/2013 09:36 PM, Steven D'Aprano wrote:
Although PEP 8 is only compulsory for the Python standard library, many
> users like to stick to PEP 8 for external projects. > > http://www.python.org/dev/peps/pep-0008/ > > With perhaps one glaring exception: many people hate, or ignore, PEP 8's > recommendation to limit lines to 80 characters. (Strictly speaking, 79 > characters.) > > > Here is a good defence of 80 char lines: > > http://wrongsideofmemphis.com/2013/03/25/80-chars-per-line-is-great/ > > >
I think one important consideration that wasn't mentioned yet is one of Python principles: practicality beats purity. I can see how someone could have a preference for 80 char width, there are some valid reasons to prefer it. I think other reasons to prefer (slightly) longer width outweigh them, but that's a judgement call. However, if you work with other people's code, you will surely run into all kinds of widths, 100, 120, 140+, etc. For someone with a rigid 80 limit, it's a real pain. I feel that somewhere around 100 width, must be the reasonable middle ground: for me at soft 105 limit, editing 80 limit code feels almost like my own, in fact the range of 80-110 is going to fit neatly into my setup without any hassle. 120 is minimal hassle: I adjust Gvim to take a bit more space, resize browser to take a bit less space and I'm set. 140 is a bit uncomfortable, but I generally notice that even when people code to 140 limit, nearly all of their lines are actually going to be at about 120 limit at most, with only a few offenders, so it's trivial to adjust to 120 limit. If people go over 140, that conclusively proves they're smoking crack and the code needs to be refactored anyway. I also find the argument about 80 width used in books a little odd. I read webpages with 100-140 widths all the time with not the slightest problem. As far as I know, no browser in existence lets you uniformly adjust all pages to wrap at 80 limit except for lynx/links; if it was hard to read at wider sizes, surely there would be at least one graphical browser that would give that option (and get all the user share from other browsers?) Code is rather different from regular text. I would not want my books formatted like this: The story had held us, round the fire, sufficiently breathless, but except the obvious remark that it was gruesome, as, on Christmas Eve in an old house, a strange tale should essentially be, I remember no comment uttered till somebody happened to say that it was the only case he had met in which such a visitation had fallen on a child. Nor am I (warning: understatement) particularly enthusiastic about editing code that looks like (formatted to 72 width): try: request = self.request_class(environ) except UnicodeDecodeError: logger.warning('Bad Request (UnicodeDecodeError)', exc_info=sys.exc_info(), extra={ 'status_code': 400, }) response = http.HttpResponseBadRequest() else: response = self.get_response(request) response._handler_class = self.__class__ try: status_text = STATUS_CODE_TEXT[response.status_code] except KeyError: status_text = 'UNKNOWN STATUS CODE' status = '%s %s' % (response.status_code, status_text) response_headers = [(str(k), str(v)) for k, v in response.items()] for c in response.cookies.values(): response_headers.append((str('Set-Cookie'), str(c.output(header='')))) start_response(force_str(status), response_headers) return response -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ -- http://mail.python.org/mailman/listinfo/python-list