Your Editor Shows the Flaws of Your Language

In a recent update of Sublime Text 2, my programming editor of choice of these days (only ’cause I wanted a break from VIM, for the fun of having to learn how to edit things in the “normal person” way) got a “Vim mode” and I decided to enable all the other features, just for kicks. One of those features was the “auto close brackets” (or whatever name they call that these days).

The only thing I’m using the “auto close brackets” feature is to make sure all the mess with opening square brackets inside functions inside functions would have the proper closing element. It’s somewhat easy to get lost in a str_replace(' ', '', trim($param['string'])) line.

But that’s only one thing editors do that are only there to work as a “walking stick” for the language you’re working on.

  • Auto close brackets: As I mentioned, that’s because accessing most array elements requires at least two characters ("[" and "]") or 4 if you use associative arrays/dictionaries/objects. JavaScript does this right by not having associative arrays and making objects. You can kinda do the same with Python objects, but it feels somewhat wrong when you do have dictionaries. You can somewhat fix that with __getitem__ or just monkeypatching the dict object. But in some languages, there is no such option. Also, as you can imagine, the problem is “lessened” with languages where all the basic types are objects: instead of making function return the parameter of another function (like I did above), you simply call function and then the next function. The same example above in Python would be something like param['string'].trim().replace(' ', ''). This obviously reduces the changes of forgetting to close one of the parenthesis.
  • Snippets: Snippets are small pieces of code that you repeat most, but not to the point you can simply write a function to do such thing. C/C++ allow you to somewhat skip that by using macros but one must reckon that macro syntax is a bit cumbersome.
  • Templates: Templates are large snippets that encompass whole files. It seems templates are there not to just solve a language design problem, but a general “language design principle” problem. The most obvious example I can think of is using Eclipse to write a Java application to connect to a database. To do it so, it requires so much boilerplate that Eclipse itself offers a way to create the whole file to you based on a simple database definition.

I’m probably forgetting a lot more programming editors do these days just to cover languages’ asses here. But I guess you start viewing programming languages a lot different when you think any feature in the editor is just to solve a problem with the languages we use today.