How I learned about delete-selection-mode

One thing I really like about stackoverflow.com is that you end up learning as much answering questions on there as you do by asking them.

For example, when I saw this question I was sure there would be a way to delete a region by simply starting to type after selecting the region, but I didn’t know how. However given that this is emacs, I seriously doubted the person asking the question would be the first one to want this particular feature.

Sure enough, a quick dig around EmacsWiki brought up delete-selection-mode which does exactly what the poster wanted. And I’ve learned a little bit more about Emacs, again.

At this rate I’ll be reasonably proficient in Emacs in a decade or two :).

Repost – how to get rid of those pesky ^M characters using Emacs

I had another of these annoying mixed-mode DOS/Unix text files that suffered from being edited in text editors that didn’t agree which line ending mode they should use. Unfortunately Emacs defaults to Unix text mode in this case so I had an already ugly file that wasn’t exactly prettified by random ^M characters all over the place.

I also don’t have the cygwin tools on the machine that I was seeing this problem on, I couldn’t just run unix2dos or dos2unix over the file and be done with it, but at least I had emacs on that machine. So, emacs to the rescue again…

First, I used query-replace to get rid of the ^Ms in so the file was turned into a “proper” Unix text file. The trick here is that you need to use control-Q to quote the control character. In my case on a Windows box, the key sequence was M-Shift-% Control-Q Control-M and then use the empty string as a replacement value. Job done, we’ve now got a proper Unix mode text file. Well, after almost wearing out the ‘Y’ key but of course you can use replace-string instead.

In order to turn the Unix mode text file into a Dos mode one, run the command set-buffer-file-coding-system with the parameter undecided-dos and save the resulting file. Job done.

A couple of useful Emacs modes

This is a repost from my old blog – I’m moving some of my older articles over as nobody knows how long the machine that hosts that blog will still be around.

highlight-changes-mode – as the name implies, it highlights changes that you make to a file. I do find it useful for the typical scenario of checking out a file, making a couple of smaller changes to it and then having to diff it to work out what you actually changed. As mentioned over at Emacswiki it doesn’t play too nicely with font-locking but I’ll try out some of the suggestions in the “Taming Highlight-Changes-Mode” section on this page. The one big advantage is that it’s available on an out-of-box GNU Emacs, so you don’t need to install any new modes.

nxml-mode – my preferred mode for editing XML. Of course it would be better if I could be bothered to create schemas for some of the files I’m editing but even without them, it does a pretty good job. As it’s trying to parse the XML that you write, it’s very helpful when it comes to highlighting mismatched tags or auto complete tags.

ido-mode – I’ve only recently started to use it and I’m still trying to work out if it is useful enough for me or if the improved file finding capability does bother me more than it helps. Yes, I know it can do a lot more but so far I’m only using the improved file finding and buffer switching. I really rate the buffer switching which is the main reason I leave it turned on.

Not really a mode, but I like using bm.el for visible bookmarks. I don’t use bookmarks that often but the package is extremely useful when I do need them.

If we consider software creation a craft, Is it time to”bring our own tools”?

If you look at really productive programmers – like the top 10-20% – there are usually a couple of characteristics that they share. Aptitude and in-depth understanding of both the system they are working on and the technologies involved is obviously one very important factor. Another factor that tends to be overlooked is that these programmers are also masters of their tools in the same way that a master craftsman – say, a carpenter – is also a master of their tools. That includes potentially obscure tools, and the ones handed down from grandps or found at a yard sale.

I think that mastery of your tools plays an important role in your ability to be a productive software engineer. If your tool interrupts your workflow because you need to figure out how to accomplish a task at hand, you immediately waste precious brain cycles on this disruption rather than being able to use them in the flow of software creation. That sort of disruption can easily drops you out of “the zone”, and those brilliant thoughts might never make it into your software as a result.

There’s also a trend that I’ve seen over quite a few years in a lot of companies (usually large, with IT departments that most developers would find overbearing, but it’s not limited to these companies) limiting the tools that are available to developers. The usual attitude seems to be that if a certain tool is not included in <insert development environment of choice>, it is not needed for serious software development and thus developers are only requesting these tools because of their magpie like tendencies or worse, because it allows them to polish their resumes and then wander off and get a better job.

Leaving aside the latter “justification” – if you work for a company like that, my suggestion is that you find yourself some career opportunities elsewhere anyway – you’ll end up running into the issue that the one tool you need hasn’t been requested by anybody else and thus is not on the very short “approved” list. Your manager will have a hard time justifying the expense because nobody else “needs” that tool and thus requested it. Plus, IT departments tend to have an ingrained dislike of exceptions of any kind, because it usually tends to make their job a lot harder. A short list of approved software with everything else banned does make it possible for them to support thousands of machines, but at the expense of inhibiting the creation of a work environment that is designed to give people all the right tools they need for maximum productivity.

Most craftsman own their own tools. A carpenter will show up at a job site with their own tools, a car mechanic uses tools he’s acquired over his career. If you subscribe to the view point that software development is a craft and not an assembly line operation, then maybe it is time for us software engineers to step up and tell our employers or clients that we don’t expect them to pay for certain tools, but we will bring them with us and expect to be able to use them. Of course, the latter is going to be the issue – there will be clients and workplaces with the IT policies designed by Mordac The Preventer’s cousin that will under no circumstances allow a tool on the premises that has not gone through an 18 month vetting process by the secret IT ninjas – but to me this is the sign of an environment that is conducive to good software development if it is being recognised that a craftsman’s tools play an important role in both their ability to produce quality work and enjoy producing said quality work.

If your development team doesn’t enjoy what they’re doing, they’re not going to be at their best and create the absolute best software they can. And we already have virtual shelves of “good enough” software available, we don’t need more of that.

While there is a need for some standardized tools like the compilers and the basic build environment – I really do not want to work in an environment where everybody gets to bring their own compiler, I’ve seen how that movie plays out, thankyouverymuch – there is absolutely no reason to hire someone who is a SublimeText/VIM/MultiEdit/BBEdit wizard and force him or her to use Notepad or edlin. Let them bring their own editor, IDE plugins, customizations and let them use it. Let them use the shell they can drive in their sleep.

The same goes for certain types of specialised tools or plugins, heck, even keyboards. For example I expect to use a certain type of keyboard at my workplace due to an old injury and I’m happy to bring one in so I don’t have to use the “but it came standard with the Dulls we buy and it is the only keyboard you are allowed to use” $5 RSI-waiting-to-happen piece that gets inflicted on seemingly everybody.

That said, I am in no way advocating anarchy in the workplace here. There are certain limits that need to be set in a case like this – for example, one of my rules is that no matter what editor you use to write your code, it has to apply the same formatting in all editors across the team. Yes, as a result everybody in the team will have to tweak their editors to ensure they don’t litter the code with tabs instead of spaces and result in formatting that make the source code unreadable in six out of ten editors used by other members of the team. The code will however look the same in everybody’s editor and its readability (or lack thereof) will be the same. Large bodies of code are already hard enough to read as is, we don’t need to introduce additional hurdles.

You also don’t get to pick your own build tool and thus be the only person on the team using CMake while everybody else is using MSBuild. Or use the latest nightly build of GCC when the production code is built using Visual C++.

At the end of the day it’s a balancing act, but as a manager you want to ensure that the tools your developers use are the ones that provide the least distraction to them. You absolutely do not want to inflict tools on a team that get in the way (ClearCase, anybody) when there are tools out there that are designed to complement the workflow rather than inhibit it.