4 ms·
Yes, it's been tried before, and gets periodically re-invented by everyone who thinks seriously about language design. Lisp works on this principle. The langu
by nostrademons 14y ago
Yes, it's been tried before, and gets periodically re-invented by everyone who thinks seriously about language design.
Lisp works on this principle. The language is nothing but S-expressions, which are a serialized representation of the parse tree. Nobody bothers to format their Lisp code: they let Emacs format it for them. As you write it, Emacs reformats it into canonical Lisp style, and then that's what gets saved.
There were also various experiments at saving SmallTalk into an object database, which were then carried over into some Java IDEs. IntelliJ has a setting where you can have it automatically format your Java according to the formatter you specify as it saves the file; the representation inside IntelliJ is a parse tree, which gets created when the file is opened and serialized when saved.
Go operates on a similar property. You run the gofmt tool on your source code before you check it in; it formats your source code in a canonical way and then writes it back out. Go code always has a consistent style, because nobody bothers to format their own code, they let the tool do it for them.
Several people swear by this. It eliminates all the time wasted by arguing about style, and it also makes it much easier for refactoring and code generation tools to operate (they can operate on the raw parse tree and rely on the formatter to generate the final source code). There's still a bunch of resistance in the wider programming world, though, largely because such formatting is inherently lossy (there's information conveyed in our style choices) and because programmers are people too who like to be individuals.