The Developer’s Cry

Yet another blog by a hobbyist programmer

The importance of a good code editor

One of the programmer’s most important tools is the editor. Whether (s)he is crafting a GUI app or a graphical game, for the most part code is still being written using a text editor. Have a look at your desktop. Behind the curtains of all those windows there is a binary code running, binary code that was crafted from thousands and thousands of lines of code, written mostly by hand, by programmers—the monks of the digital age.
Since the editor plays such an important role, it is never a waste of time to have a look around and investigate potentially better editing programs. But there are so many … and so little time. In this post I will talk about a few decent editors that I love. Mind you, the choice for a code editor is a very personal one.

1. Xcode

Rather than just an editor, Xcode is a full development studio. You need Xcode in case you are developing apps for OSX or iOS. Use the Interface Builder to draw the app and tie GUI elements to actions in the code.
Xcode actually analyzes and precompiles bits of code as you type. This allows it to find type errors in your code even before hitting the Build button. This is pretty amazing as much as it is annoying. Xcode will happily disrupt your train of thought by pointing out errors while you were still pondering that line of code.
It comes with great profiling tools. I once fixed a memory leak in an Objective-C app by using its memory analyzer, which says enough about the technical prowess of Xcode. Amazingly, this software comes entirely for free.
On the downside, Xcode is very heavyweight. Updates are a whopping 4.5 GB in size. The whole program feels heavy, too. Simply paging through a large source code is not as fast as it should be. The live code analysis comes with a price, I suppose.
Defining a new project from scratch with multiple build targets and dependencies etcetera is a non-trivial task. My wish is that it could import a plain Makefile as a project—this is, however, unlikely to happen.

2. TextWrangler

TextWrangler is the free (as in beer) cousin of the commercially available BBEdit. The web site starts by mentioning HTML, but TextWrangler supports a long list of programming languages. Syntax highlighting is easily customized using the Preferences dialog. One sweet feature is the ability to search using regular expressions.
It supports a page guide at the 80th column, which is convenient for eg. Python and formats like Markdown.
TextWrangler supports running scripts, including custom scripts, and it can fire up a command-line debugger for you in a Terminal window. There is no hotkey to do so, however—at least, not by default. If you take the time, TextWrangler can surely be tuned to build/run/debug programs. But it appears a little tucked away, as if it wasn’t a core feature of the editor.
One thing TextWrangler doesn’t understand is that I want my C++ code to use tabs, and spaces for Python. It’s not intelligent about it, and having to switch by hand is annoying.

3. ViM

This one is for command-line people, who aren’t afraid of a terminal window. vim comes from the Linux and BSD world, where software is typically free. On a glance, vim looks like it walked right out of the eighties, and it kind of did—it is an improved clone of the (now ancient) UNIX vi editor. This editor is notorious for having a ‘command mode’ and an ‘insert mode’. If it’s your first time, vim will be very difficult to wield. Lesson 1: Press i for insert mode and start typing. Hit escape and type :q! to quit the editor.
Despite the arcane interface, vim is powerful and remains hugely popular to this day. One of its key strengths is that you control the entire editor with the keyboard. There is no mousing in vim.
There is a steep learning curve involved, but like riding a bicycle, once you get to do it on a daily basis, you’ll never unlearn it.
vim has many commands, and I don’t even know where to begin. For programming, syntax highlighting is important, so look into how to customize colors. A great feature of vim is softtabstop in combination with expandtab and smarttab. Using these settings, vim can be made to understand that Python code has tabs that consist of 4 spaces. Not only that, but hitting backspace on such a ‘soft’ tab will set you back 4 spaces, as if it were a real tab. This feature is just super convenient when writing Python code.
vim supports a vertical split window mode, but I don’t use it. Instead, I work a lot with ‘buffers’; you can easily load up multiple files and switch between them. Be sure to learn to use this feature! Finally, I use visual block a lot (shift-v key) to select blocks of code and move them around using cut/paste.

4. Visual Studio Code

Lastly, there is the freely available VS Code editor. It runs on Windows/Linux/Mac and is brought to you by … Microsoft. Really? Yes, really. And it’s pretty amazing, too. Microsoft software typically sports an ugly bulky toolbar at the top, but VS Code appears clutter free. VS Code is a newcomer and there still are some things that may be improved, but overall I’m pleasantly surprised with this programmer’s editor.
When you search text, it will display markers in the scrollbar where the matches are. When you edit Markdown text, it can render a HTML preview. When you use git, it will mark any lines that were added or changed. It can show a side by side diff. It can run scripts, and display the output in a split-screen output window. It can parse compiler output and use it to mark errors and warnings in the source code. It’s pretty great, albeit a little hard to configure. Configuration is rather UNIX-like, just editing config files rather than ticking checkboxes in dialogs. Syntax highlighting is limited to offered color schemes, unless you dive in and make a custom XML file by yourself.
The debugger function seems defunct. The web site says it can be configured, but I seem to lack understanding how to achieve this. Something tells me the debugger will only be available commercially as an extension. VS Code wants to be a full IDE, but hasn’t fully grown up yet.

January 2016 update — A recent update messes up the editor for those who use alternate keyboard layouts like dvorak, colemak. VS Code blatantly assumes US qwerty for command keys, disregarding whatever keyboard layout you configured in the operating system’s preferences. This is totally nuts and unacceptable. Clearly VS Code is still in heavy development, but unfortunately this also means things may break sometimes.

Honorable mention goes to Sublime Text. This editor features a mini-map of your code, that you can use to scroll through large sources. Configuration is done through text files, also meaning that you will have to edit the color scheme file in case you don’t like any of the bazillion available color schemes for syntax highlighting. It has a “distraction free” mode in which the rest of the screen blacks out, so that you can concentrate on coding. The editor is not free however, and will nag you about purchasing.

One thing that none of these editors get right, is having a customizable cursor (the caret). My favorite is a non-blinking green block cursor. Well, vim does have one, but that’s because the OSX Terminal can do it.

Another annoyance is the lack of a proper debugger. Xcode has one, but it isn’t all that great. I only use it as a last resort. The reality is that I’m still with printf() when it comes to debugging. Kind of sad, in this day and age. It’s almost 2016.