Encodings and Unicode

David C. Zentgraf over at Kunststube.net has a useful post about character encodings, Unicode, and UTF-X. The post is entitled What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text, which is a pretty good summary of its content. I’m confident that almost all Irreal readers will already know this material but if you’re confused about the difference between Unicode and UTF-8 or some other UTF encoding then you may find this post enlightening. Similarly, if you have non-technical friends who want a succinct explanation of why they’re getting a stream of gibberish characters in their browser this may be a good resource.

Posted in General | Leave a comment

Further Evidence for the Demise of Cursive

I’ve written a couple of times about the demise of cursive handwriting. Its proponents’ arguments have pretty much been reduced to (1) it is the apotheosis of all that is good and holy in written communication and (2) if we don’t learn to write in cursive, we won’t be able to read cursive. If you’re like me, you won’t find either of those arguments compelling.

Recently, I came across a column in The Washington Post Magazine by Gene Weingarten entitled Cursive, Foiled Again in which, with tongue firmly in cheek, he talks about cursive handwriting and how young people simply aren’t learning it. What struck me was the ages of the “young people.” I had imagined that today’s elementary school children weren’t learning cursive but Weingarten relates how neither a 28 year old colleague nor his son, also 28, had been taught cursive. Surprised by this, Weingarten checked and discovered that schools have been deemphasizing cursive for the last 20 years. Of course that will vary by state and school district but the trajectory is clear.

Weingarten’s column is amusing and worth a read. I especially like that he confirms my suspicion that the real reason the traditionalists maintain their death grip on cursive is, to quote Weingarten,

Why shouldn’t kids today have to suffer through learning cursive the
way we did, and from the same idiot book, which seemed to have been
designed by 19th-century French fops with perfumed doilies in their
sleeves.

Yes. I remember those books. Whether or not they were written by French authors, I recall that even as a third grader I found them annoying.

I am more than ever convinced that cursive—and probably all handwriting—is in a death spiral. It won’t bother me but there seems to be a lot of people for whom it appears to be the apocalypse.

Posted in General | 1 Comment

Some Common Sense on OOP

A few days ago, I ran across an interesting and commonsensical article on OOP by James Hague over at programming in the twenty-first century. In it he says that while OOP is sometimes useful, it’s not a fundamental particle of computing. Too often, he says, OOP is blindly applied to inappropriate problems. Problems that aren’t complicated enough to warrant its use and the difficulties that it brings.

It is, as I say, an interesting post and I was going to blog about it in a little more detail but Rob Pike beat me to it with his own post on OOP that makes the same point—and even mentions Hague’s post—in a more provocative way. Pike points to an example of OOP run amok that can be characterized only as terrifying. Pike says of it

Local discussion focused on figuring out whether this was a joke or
not. For a while, we felt it had to be even though we knew it wasn’t.

I can’t begin to describe the horror of it so you’ll have to go over to Pike’s post and follow the link that he gives.

The problem itself is to determine the operating system you’re running on and output a value judgment about it. As Pike says, this is a trivial problem that can be solved easily with a simple table look up in any language. Here it is in Elisp, for example:

(defvar systems '((usg-unix-v "UNIX" "good")
                  (gnu/linux "UNIX" "good")
                  (windows-nt "Windows" "bad")
                  (darwin "Mac OS" "far superior")))

(let ((box (assoc system-type systems)))
  (if box
      (message "This is a %s box and therefore %s." (cadr box) (caddr box))
    (message "This is not a box.")))

Simple, extensible, and not a class to be seen.

Posted in Programming | Tagged | 3 Comments

An Optimal .emacs File

I recently stumbled across this old post from Nickel’s Worth on optimizing your .emacs file. It’s from 2009 so it is, in some parts, dated but it still contains a lot of good ideas.

To me, the most controversial piece of advice is to avoid using load or require in your .emacs. I’ll let you read the post for the reasons for that but I will say that the suggestion is not without merit.

Another idea that solves a problem I seem to keep having is to use eval-after-load so that you can set various package-configuration variables without loading the package. For example, you might have the autoloaded package foo that requires that you configure the foo-blah1 and foo-blah2 variables. The way to do that is

(eval-after-load "foo"
  '(progn
    (setq foo-blah1 "some string")
    (setq foo-blah2 "some other string")))

That way, the setting of the foo-blah1 and foo-blah2 variables is not executed until the package is actually loaded so you won’t get a void-variable error. This suggestion alone makes the post worth reading.

This is a short post so there’s no reason not to give it a look. You may get some ideas that hadn’t occurred to you before.

Posted in General | Tagged | 9 Comments

Traveling Salesmen, NP, NP Complete, and NP Hard

Ron Hilton over at Absolutely No Machete Juggling has an excellent post on the traveling salesman problem. Hilton explains that when people say the traveling salesman problem is NP Complete they are almost always wrong. Almost because there are two formulations of the problem but only one of them is NP Complete and it’s not the formulation that everyone associates with the problem.

You can follow the link for the details but what I found especially interesting in the post was his explanation of the meanings of NP, NP Complete, and NP Hard. It’s one of the best explanations that I’ve seen. The short summary is

NP A proposed solution can be verified in polynomial time
NP Hard The problem is as hard or harder than any NP problem
NP Complete The problem is both NP and NP hard

but be sure to read Hilton’s more complete explanation. He also has a nice Venn diagram that shows how the three properties relate to each other.

You often see problems described as NP or NP Complete so if you have any doubt as to what that means, spend a couple of minutes on this post. It will be worth your while.

Posted in General | Leave a comment

Advanced Dired Tips

Xah Lee has updated his Emacs Advanced dired Tips page. I thought I knew all this stuff but Lee has some tips I wasn’t aware of. For example, you can configure what dired does when you try to copy or delete a directory. You can have it ask once for the top directory, ask for every directory and subdirectory, or not allow it at all.

At the bottom of the page he has a pointer to his Using Emacs’s “Dired+” (DiredPlus) Mode page. Almost every time I blog about a dired feature someone will comment that the feature doesn’t work for them. That’s because I use dired+. I’ve been using dired+ for so long I always forget that I’m running it instead of plain dired. Everyone should be using it. There’s no reason not to and it’s easy to install with ELPA. There’s virtually no configuration either. Here’s what I have in my init.el:

(require 'dired+)
(put 'dired-find-alternate-file 'disabled nil)  ;enable `a' command

The put command enables the 【a】 command that replaces the current dired buffer rather than opening an additional buffer when you move to another directory. If you don’t include that, Emacs will ask you if you want to enable it when you try to use it so it’s not necessary to include it.

Take a look at Lee’s Advanced dired page and for goodness sake install dired+ if you haven’t already.

Posted in General | Tagged | Leave a comment

Common Lisp Naming Conventions

Over at the newly redesigned Common Lisp Wiki, CLiki, they have an excellent page on Common Lisp naming conventions. Most people that have done a non-trivial amount of Lisp programming will be at least dimly aware of many of these conventions but there’s also a number of rarer conventions that may be new to many.

Most Lispers know the “predicate convention:” predicates end with “p” unless the predicate contains a hyphen, in which case it ends with “-p”. Thus it’s zerop and simple-vector-p. But what about string-lessp? That seems to violate the convention and I’ve always wondered why. It turns out that the actual convention has a third part that says if a new predicate is formed by adding a qualifying prefix to an existing predicate, then the new predicate is formed by adding a hyphen between the prefix and old predicate and the “p” or “-p” at the end is unchanged. Thus when lessp is qualified with the prefix string we get string-lessp instead of string-less-p. Follow the link for the rationale for this rule. Of course, there’s also the grandfathered-in predicates such as null and equal that don’t honor the p convention at all.

There are other interesting notes about the conventions so even experienced Lispers are likely to find the page interesting. If you program in Common Lisp you should check it out.

Posted in Programming | Tagged , | Leave a comment

Randall Munroe on XKCD

The MAA has a great interview with Randall Munroe on every geek’s favorite online comic. Being the Mathematical Association of America, the interview concentrates on the more mathematical of the cartoons. Munroe talks about how he comes up with the ideas for and how he solves the problems that the cartoons explore. You may be surprised at how he arrives at some of those solutions.

If, like me, you’re an XKCD fan, you should definitely take a look at the interview. It’s interesting and gives some insight into how Munroe produces our favorite cartoon.

Posted in General | Leave a comment

Bookmarks

I’ve been rewatching some of Tim Visher’s VimGolf for Emacs videos (where are you Timmy?) and one of the things that struck me the second time through was his demonstration of Emacs bookmarks. I remembered my old post on opening frequently accessed Emacs files in which I wrote about storing frequently accessed files in registers so that you could jump to them with【Ctrl+x r j】. Many of the commenters on that post told me that I really should be using bookmarks for that sort of thing. For unfathomable reasons I have resisted using bookmarks but Visher’s videos spurred me to give them a try. Serendipitously, Xah Lee’s blog had a short piece on bookmarks with a pointer to his bookmarks tutorial so I was able to get started quickly.

At first, I used them as Visher did in his videos: to jump to parts of the Emacs manual. How much easier to just type【Ctrl+x r bregisters to bring up the documentation on registers than to bring up Info with 【Ctrl+h i】 and navigate to the register node. Then I remembered the reason I wrote that post on opening frequently accessed Emacs files to begin with so I added bookmarks for my tax file, my steps.org file, and my init.el file.

I keep my bookmarks file in a git repository so that it gets synced between my machines. I noticed that this can be a bit tricky because even if git updates your bookmark file, Emacs will overwrite it the next time you save your bookmarks. For that reason, I added the following line to my sync-repos function

That means that when I pull in changes from the other machines my bookmarks will be updated at the same time. It can be hard to get this right because bookmark-load and its siblings will, by default, add to the current bookmarks rather than replacing them. The second argument to bookmark-load says to overwrite the bookmarks rather than add to them.

Posted in General | Tagged | Leave a comment

Using Acme

A while ago I wrote about Russ Cox’s Tour of the Acme Editor. Acme has a lot of great ideas. It is, in some sense, the opposite of Emacs. Where Emacs puts every conceivable functionality into the editor, Acme has minimal internal functionality but makes it easy to access external tools. In that, it is the incarnation of the Unix way.

For an Emacs guy, however, there are some problems. The most important is that Acme is totally mouse-centric. There is no cursor addressing at all. Want to move down a line? Don’t bother with the arrow keys let alone 【Ctrl+n】. You have to click on the line you want to go to. Like syntax highlighting? Sorry.

A lot of this, of course, is a matter of what you’re used to. Editors are an intensely personal choice and most of us find it hard to change. With that in mind, it would be interesting to see how well an established Emacs user could adapt to Acme. Fortunately, Vince Foley has done the heavy lifting for us and written a review of Acme from an Emacs user’s point of view. If you’re like me, you’ll find his conclusions interesting. I didn’t agree with everything he said—Acme’s color scheme, for example, is just fine with me (being close to my Emacs scheme)—but overall I found myself nodding in agreement.

Foley says he doesn’t think Acme will replace Emacs for him and I don’t think it would for me either. I really like how Emacs recapitulates the Lisp Machine milieu and can’t imagine giving it up. Still, I’d be interested in hearing about the experiences of any Emacs users who’ve tried Acme.

Posted in General | Tagged , | Leave a comment