Re: [R] R programming style

From: Barry Rowlingson <b.rowlingson_at_lancaster.ac.uk>
Date: Mon, 11 Feb 2008 17:37:37 +0000

Roland Rau wrote:
> Hi,
>
> I think using Emacs+ESS [1,2] is always a good starting point for a
> clear layout with consistent and meaningful indentation.
>
> I don't know how other people think about it, but in my opinion,
> "Elements of Programming Style" by Kernighan and Plauger is still an
> interesting read -- although their programs are either Fortran or PL/1
> and the book itself is 30 years or old. Of course, I am not always
> successful but at least I try to incorporate their 'mantras':
> - write clearly, don't be too clever [3]
> - say what you mean, simply and directly
> - use library functions
> - write clearly -- don't sacrifice clarity for "efficiency"
> - let the machine do the dirty work
> - parenthesize to avoid ambiguity
> - 10.0 times 0.1 is hardly ever 1.0
> - ...

  Reminiscent of The Zen Of Python, which you get by typing 'import this' at the python prompt:

 >>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules. Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never.
Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!

  [Note that Guido Van Rossum, inventor of Python, is Dutch]

Barry



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 11 Feb 2008 - 21:19:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 11 Feb 2008 - 21:30:13 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive