* best to have max width of 79 or 80 in source code? @ 2008-11-30 19:10 seberino 2008-11-30 20:25 ` Drew Adams 2008-11-30 20:50 ` Xah Lee 0 siblings, 2 replies; 5+ messages in thread From: seberino @ 2008-11-30 19:10 UTC (permalink / raw) To: help-gnu-emacs Many try to keep their source code to a max width of around 80. Someone recommended 79 for some reason but I can't remember why. Is it because you need to allow another column for newline? (I think there is a good reason for 79 but for the life of me I can't remember what it is.) Chris ^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: best to have max width of 79 or 80 in source code? 2008-11-30 19:10 best to have max width of 79 or 80 in source code? seberino @ 2008-11-30 20:25 ` Drew Adams 2008-11-30 20:50 ` Xah Lee 1 sibling, 0 replies; 5+ messages in thread From: Drew Adams @ 2008-11-30 20:25 UTC (permalink / raw) To: seberino, help-gnu-emacs > Many try to keep their source code to a max width of around 80. > Someone recommended 79 for some reason but I can't remember why. > Is it because you need to allow another column for newline? 79 is a prime choice. ;-) Punched ("IBM") cards had 80 columns (actually, the original Hollerith cards had 45 columns - http://en.wikipedia.org/wiki/Punched_cards). From that, 80 became typical for max line length in code. In some languages, such as Fortan, it was (still is?) a hard line limit (but statements could be continued across multiple lines). Newline at line end does not count as a column, BTW. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: best to have max width of 79 or 80 in source code? 2008-11-30 19:10 best to have max width of 79 or 80 in source code? seberino 2008-11-30 20:25 ` Drew Adams @ 2008-11-30 20:50 ` Xah Lee 2008-12-01 1:45 ` seberino 1 sibling, 1 reply; 5+ messages in thread From: Xah Lee @ 2008-11-30 20:50 UTC (permalink / raw) To: help-gnu-emacs On Nov 30, 11:10 am, "seber...@spawar.navy.mil" <seber...@spawar.navy.mil> wrote: > Many try to keep their source code to a max width of around 80. > > Someone recommended 79 for some reason but I can't remember why. > > Is it because you need to allow another column for newline? > > (I think there is a good reason for 79 but for the life of me I can't > remember > what it is.) > > Chris in my opinion, hard wrappnig lines or in general any manual code formatting is a major damage in computing, to the degree that influenced bad tools and language design which forces humans to think and do what dumb machines can easily automate. The line wrapping convention largely spurred the perpetual time wasted on arguing about code formatting and tools about it. See: • The Harm of Hard-wrapping Lines http://xahlee.org/UnixResource_dir/writ/hard-wrap.html • A Simple Lisp Code Formatter http://xahlee.org/emacs/lisp_formatter.html • A Text Editor Feature: Extend Selection By Semantic Unit http://xahlee.org/emacs/syntax_tree_walk.html Xah ∑ http://xahlee.org/ ☄ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: best to have max width of 79 or 80 in source code? 2008-11-30 20:50 ` Xah Lee @ 2008-12-01 1:45 ` seberino 2008-12-01 2:54 ` Xah Lee 0 siblings, 1 reply; 5+ messages in thread From: seberino @ 2008-12-01 1:45 UTC (permalink / raw) To: help-gnu-emacs On Nov 30, 12:50 pm, Xah Lee <xah...@gmail.com> wrote: > in my opinion, hard wrappnig lines or in general any manual code > formatting is a major damage in computing, to the degree that > influenced bad tools and language design which forces humans to think > and do what dumb machines can easily automate. The line wrapping > convention largely spurred the perpetual time wasted on arguing about > code formatting and tools about it. I read some of the links you posted. I like idea of Emacs automagically handling wrapping but one of those links seemed to suggest that C and Python and Perl weren't amenable to this. cs ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: best to have max width of 79 or 80 in source code? 2008-12-01 1:45 ` seberino @ 2008-12-01 2:54 ` Xah Lee 0 siblings, 0 replies; 5+ messages in thread From: Xah Lee @ 2008-12-01 2:54 UTC (permalink / raw) To: help-gnu-emacs On Nov 30, 5:45 pm, "seber...@spawar.navy.mil" <seber...@spawar.navy.mil> wrote: > On Nov 30, 12:50 pm,XahLee<xah...@gmail.com> wrote: > > > in my opinion, hard wrappnig lines or in general any manual code > > formatting is a major damage in computing, to the degree that > > influenced bad tools and language design which forces humans to think > > and do what dumb machines can easily automate. The line wrapping > > convention largely spurred the perpetual time wasted on arguing about > > code formatting and tools about it. > > I read some of the links you posted. I like idea of Emacs > automagically handling wrapping but one of those links seemed to > suggest that C and Python and Perl weren't amenable to this. One cannot auto-format Python source code due to the fact that formatting is part of the syntax, but C and Perl can to a large extent. (the automatting needn't be something like 100% “perfect” to be useful. (but it should be 100% correct. That is, the reformatted code should not break the code)) actually, having learned a lot elisp in the past couple of years, i think it's rather trivial to do. Basically, the command will just need to inseart line breaks in the right places in the source code, then call indent-region. (i.e. utilizing emacs's existing functions that handle indentation for each lang.) The tricky part would be to not break lines if it is inside string. But there are existing function(s) to determine if cursor is inside string. Also, lines must not be cut when inside comment block. Overall, the bulk of effort for this to work is massive amount of testing. e.g. Apply this to all source code in a large project, and compile and test if the program still runs. (this can be done for example for lisp mode on all elisp source code in emacs) ----------------------- So, in summary, each lang mode should have these functions: format-block format-buffer (current buffer) The format-block will just reformat the block of code the cursor is on. (a block can be defined as between 2 newlines) The fomat-block will have a easy keyboard shortcut of course. Also, for each lang mode, it'll have a local variable “format-style”, whose value can be something like: logical, BSD-style, GNU-style, condensed (all white spaces removed). So, a user can just set one of these. (as opposed to setting 10 or so variables related to indentation style and brackets placement style and tabs/spaces style.) ------------------------- with the above, coder simply press a button and have his current block or buffer or files all reformatted to a style he likes. Instead of each coder pressing tab or delete or fill-* etc on a line-by-line basis as is currently practiced. this format-block can be tied to Enter key, so that it becomes automatic. (similar to, for example, how word processors auto wrap lines, started in about early 1990) Today, the Mathematica language autoformat code, even its source code is perhaps the most complex of all computer languages, since the source code also handles math formulas and on-the-fly rendering to traditional math notation (e.g. TeX). Mathematica has this auto format feature since ~1997. ---------------- the above sounds fancy, but it's is rather very trivial to do with respect to today's technology. (for most lang's source code anyway, such as C, Java, C++, Perl, Ruby, lisp etc) If one looks at IDEs, lots more much more harder problems have been solved. As far as i know, there are also standalone tools that reformat source code. I know Java has, and i think C has something called lint. There's also HTML::Lint. As examples of much harder problem being solved... e.g. Steve Yegge recently implement Javascript in elisp. And google implemneted Javascript that compiles to native code, for their Google Chrome browser. Emacs being what it is, this as a programing problem is easily handled in elisp, and this feature is the most fitting for emacs. ------------------- i will code this eventually just for my own use. (using a simple implementation on top of emacs's various indentation functions, as described above) In any case, for those elisp developer reading this, i think it would be quite a killer app for emacs. Xah ∑ http://xahlee.org/ ☄ ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-12-01 2:54 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-11-30 19:10 best to have max width of 79 or 80 in source code? seberino 2008-11-30 20:25 ` Drew Adams 2008-11-30 20:50 ` Xah Lee 2008-12-01 1:45 ` seberino 2008-12-01 2:54 ` Xah Lee
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).