bbatsov / emacs-lisp-style-guide

A community-driven Emacs Lisp style guide
1.08k stars 53 forks source link

Proposal: Always use lexical scope in new code #11

Closed skeeto closed 10 years ago

skeeto commented 10 years ago

Lexical scope was introduced in Emacs 24. All new Emacs Lisp code should begin with a local variable statement setting the file to lexical scope.

;;; foo.el --- Foo the bars -*- lexical-binding: t; -*-

Lexical scope has safer and cleaner semantics (local assignments aren't visible in callees, scopes are predictable at compile time), allows for additional checks by the compiler (free variables must be declared as global variables, variables aren't just opaque symbols), and has better performance (stack-oriented storage). All new code should take full advantage of it. Global variables are still dynamic, so there are no disadvantages to using lexical scope.

bbatsov commented 10 years ago

Definitely. Feel free to turn this into a PR.

On Friday, September 5, 2014, Christopher Wellons notifications@github.com wrote:

Lexical scope was introduced in Emacs 24. All new Emacs Lisp code should begin with a local variable statement setting the file to lexical scope.

;;; foo.el --- Foo the bars -- lexical-binding: t; --

Lexical scope has safer and cleaner semantics (local assignments aren't visible in callees, scopes are predictable at compile time), allows for additional checks by the compiler (free variables must be declared as global variables, variables aren't just opaque symbols), and has better performance (stack-oriented storage). All new code should take full advantage of it. Global variables are still dynamic, so there are no disadvantages to using lexical scope.

— Reply to this email directly or view it on GitHub https://github.com/bbatsov/emacs-lisp-style-guide/issues/11.