Wednesday, September 30, 2009

On BA Chapter 11 (Emacs Architecture)

With its development beginning in the mid-70s and continuing actively even today, “Emacs text editors are most popular with technically proficient computer users and computer programmers. The most popular version of Emacs is GNU Emacs, a part of the GNU project, which is commonly referred to simply as Emacs.”

Structured as a Model-View-Controller architecture for interactive applications, with the Model, the underlying representation of the data, the View presenting the data to the user and the Controller taking care of the user’s interaction with the View, Emacs delivers a very influential architecture. And this comes from Emacs’s most striking feature, extensibility.

Applications like Eclipse, Firefox and other architectures are extensible through user extensions. In a similar manner, if the user wants to customize Emacs to meet his own needs, he has to write his own customization code in Lisp. Emacs Lisp, the flavor of Lisp implemented by Emacs, is key to Emacs’s ability to accommodate a wide range of new functionality. This is mainly because Emacs Lisp acts as an important abstraction boundary, which hides away the complexity of the Lisp interpreter and of the underlying processor architecture. Through the contributions of the users (now isolated from details), Emacs has grown more into some sort of platform rather than a unified whole, a platform comprising of a multitude of Lisp packages. In fact, the concept of Emacs is more than that of an editor. Same even say that Emacs was many years ahead of his time.

Another interesting aspect of Emacs is the Emacs compiler, capable of translating Emacs Lisp source files into a special representation known as bytecode. Compared to source files, bytecode files load faster, occupy less space on the disk, use less memory when loaded, and run faster. From this description, the analogy with the Java, .NET and other interpreted languages seems to be clear. One can almost claim that Java is an extension of Emacs as a platform concept: it has a byte compiled, garbage collected language, a display library and network functionality, etc.

The dissociation of the Lisp code from handling events from an event loop because of the automatic display management is another great important feature which speaks again for the simplicity of integrating new features into Emacs. The same automatic display management we notice with JavaScript, which only modifies the DOM tree representing the web page, while the browser takes care of updating the display when needed.

Even from only the perspective of designing an editor, analyzing the Emacs architecture, one may notice again design decisions that make Emacs unique. For instance, in order to manipulate text, the Model is a buffer, which is a flat string, where newline characters mark line endings. This is way simpler than the approach of most other editors where the text is represented as an object, a data structure, a tree etc. This representation matches perfectly with the Emacs Lisp primitive operations on buffers that can insert, delete, extract portions of buffers as strings etc. With its UI design, with frames, windows, with its ability to manipulate commands and output of commands inside the editor, with its command line, Emacs, as an editor, has again a different fresh approach, which makes its proponents swear nothing else comes even close.

No comments:

Post a Comment