Premature Optimization and Bugs

All developers are aware of Knuth’s warning about the dangers of premature optimization. Yesterday, I ran across two posts that nicely illustrate those dangers in the wild.

The first is a tweet that explains why Unix files that begin with a dot are hidden—that is, why they are not normally displayed by the ls command. That turns out to be a bug: the result of an optimization attempting to simplify a test for another condition.

The second is a post by Eric Raymond that explains how he was recently seduced by the siren song of premature optimization. He ended up with buggy, complicated code that, as it turns out, was slower than doing the same task by the obvious brute force approach.

If you write code, you should definitely read these two items. They serve as an excellent reminder that even the masters can get tripped up when they optimize too early. That said, I’m sure I haven’t done it for the last time but at least we’re all warned.

UPDATE: ESR wrote to say that he hadn’t measured the relative speeds of the two methods so I’ve deleted that part of the post.

Posted in Programming | Tagged | 2 Comments

Open the Current Buffer’s File in Another Application

Ustun Ozgur has posted a video in which he demonstrates his package emacs-friends. The idea is that you provide the package with an association list mapping (your name for) an application to it’s executable and the code automatically generates functions you can call to open the file associated with the current buffer in that application.

Watch the video to see how it works. Oddly, a couple of the examples he uses are opening the file in Vim and Sublime. I’m not sure why an Emacser would want to do that but he finds it useful. In any event, don’t be put off by that. Look at the other examples and the association list he’s using to get an idea of what’s possible.

Xah Lee has a bit of code that does something similar. If you’re in the market for this sort of thing, take a look at both packages to see which best fits your needs.

Posted in General | Tagged | 3 Comments

The Mysteries of Perl

Those of you who have used Perl will understand this:

It turns out, though, that the joke’s on us:

Posted in General | Tagged | Leave a comment

Emacs Tips

Davide Giannella has been blogging for some time and has collected a nice set of Emacs tips going back to 2007. Mostly they are the solutions to problems that Giannella ran into and which we could probably figure out for ourselves but it’s nice to see them written out. Perhaps the list will help you remember a solution when you run across a similar problem.

If you use Emacs to deal with logs, you should take a look at his post about log4j-mode and log4j-start-filter. It seems like a useful tool. Thankfully, I don’t deal with log files much anymore so I haven’t tried it but you may find it useful. It’s still under active development and is available on Melpa.

Posted in General | Tagged | 1 Comment

Emacs 25

We’re getting there:

Kudos to everyone working on the new release. We all really appreciate your efforts.

Posted in General | Tagged | Leave a comment

Autocorrecting

Avdi Grimm has posted a nice video demonstrating Artur Malabarba’s autocorrect code. The code is just a bit of Elisp that you paste into your init.el; no packages necessary.

Once you have it installed, it allows you to correct a misspelling and add the misspelling and correction to the abbrev list so that the next time you make the misspelling, it will be automatically corrected.

Old Unix heads will remember aliases in their .bashrc (or whatever) files for things like mroe = more and other common typos. This facility is similar but more convenient because you can add to the list on the fly. If you have things you commonly mistype, this may be just what you need. Watch the video and see if it’s for you. The video is less than 3 minutes so it doesn’t require much of an investment.

Posted in General | Tagged | 1 Comment

Why Indeed?

Posted in General | Tagged | Leave a comment

Cabledolphin

If you’re a networking geek like me or if you write Elisp that uses the network to communicate with external sources, you may find cabledolphin useful. It captures network traffic to and from Elisp processes in a form that can be read and formatted by wireshark or tcpdump.

The data is captured at the application level so even if the network connection is encrypted, you can still see the data. The data is written to a file in pcapng (default) or pcap format. After capturing the data you use your favorite TCP line monitoring software to read it.

Since the data is captured at the application layer, the TCP headers have to be synthesized for wireshark or tcpdump so cabledolphin probably isn’t useful for troubleshooting actual network problems. Think of it as an aid in debugging Elisp applcations.

UPDATE Fixed misspellings of ‘cabledolphin’

Posted in General | Tagged , | 2 Comments

Emacs Garbage Collection

Bailey Ling over at bling on software has a great post on tuning Emacs garbage collection. Most of us never think about Emacs garbage collection but Ling shows that it can have an effect on performance.

The Emacs garbage collection strategy is pretty simple: once it’s allocated a certain amount of memory, it stops and does garbage collection. The default threshold is pretty small: 800 KB. It seems to make sense, given today’s systems, to increase this. The problem, Ling says, is that if you increase it too much there’s a lot of memory to recover and it can stop things for 20 seconds or more. That’s clearly not acceptable.

On the other hand, if it’s too small Emacs spends a large proportion of its time garbage collecting, also not optimal. It turns out that the Emacs manual has a solution and Ling has ferreted it out for us. Head over to Ling’s site for the details. If you’re seeing Emacs delay processing often or for long times, garbage collection may be the problem and you should check out Ling’s post.

The garbage collection threshold is a simple variable that is easily changed in your init.el so it’s easy to experiment with different values or to try Ling’s solution.

Posted in General | Tagged | Leave a comment

Editors Explained

Posted in General | Tagged , | Leave a comment