Friday, March 21, 2008

Thoughts While Reading About D

I first heard about D quite a while ago, but I never really looked into it. I stumbled upon it again today and I’m actually reading on the website right now. Some quick thoughts I wanted to jot down:

  • It’s compiled, no VM or interpreter, and supports inline assembly, pointers, etc. (could it be used in embedded systems?)
  • Doesn’t do 16-bit stuff very well (hmm, maybe not all embedded systems…)
  • No preprocessor, yay!
  • The above means, no #include, it has modules that you import.
  • Arrays know their size!
  • Arrays can be resized
  • Arrays can be associative (i.e. hash tables)
  • No forward declaration needed (from they day I learned C I’ve wondered why in the world the compiler couldn’t figure this out itself)
  • Function literals and nested functions (hence, closures). Wow.
  • Garbage collection and automatic memory allocation, but you can override it if you need to (good!)
  • Built-in synchronization
  • Direct access to C functions
  • Standard object file format

It also says it doesn’t have, “a religion, or an overriding philosophy,” yet it does seem to pick a side on the strong typing debate by advocating its better typedefs and function In and Out Parameters. It also goes on for a bit more about unit tests and “contracts” (not sure what that is even) than I figured a less philosophical language would (maybe that’s just because I’m not completely sold on those myself), saying, “if it has no unit tests and no contracts, it’s unacceptable.”

It looks promising from the marketing spiel. I’ve been secretly hoping that something a little higher-level than C++ could be used for writing firmware. Maybe D could be it. I’ll have to actually download a compiler and try it.

Wednesday, March 19, 2008

Beat the Save Habit

It only takes one unfortunate program crash where you lose a lot of work to teach you the importance of saving often. I use emacs most of the time, and I had developed a nearly subconscious, paranoid habit of hitting c-x c-s every 5 seconds or so while working. I was starting to catch myself before hitting that save-buffer shortcut even when I was typing in other applications: instant messenging, web page forms, you name it. Meanwhile, I also started noticing applications that didn't require me to tell them to save my precious work. Gmail and blogger come to mind right a way. "Why couldn't emacs do the same?" I wondered. After hashing it out in that blog entry and on the emacs wiki, I added the following to my .emacs file, and I am happy to report that my twitch is gone:


(defun save-buffer-if-visiting-file (&optional args)
  "Save the current buffer only if it is visiting a file"
  (interactive)
  (if (buffer-file-name)
      (save-buffer args)))

;; This causes files that I'm editing to be saved automatically by the
;; emacs auto-save functionality.  I'm hoping to break myself of the
;; c-x c-s twitch.
(add-hook 'auto-save-hook 'save-buffer-if-visiting-file)

;; save every 20 characters typed (this is the minimum)
(setq auto-save-interval 20)

;; save after 1 second of idle time (default is 30)
(setq auto-save-timeout 1)

Now emacs automatically saves my work for me, without me having to ask, and I love it. It makes me a little nervous when I'm working on a file that's not under revision control, but with modern revision control being so easy to set up and use1, that is happening less and less.

If you see any way to improve this, or if you just want to tell me why it's dumb, please comment. My emacs lisp skil1z are pretty feeble.

1 Just type hg init, bzr init, or git init in the directory where the file lives and you are up and running.

Wednesday, March 12, 2008

Some More Tweaks to my XO

I went through all the tweaks to get XFCE running on the XO. It definitely feels snappier than Sugar, but it's all a big hack, and you still don't get the camera and microphone, and networking with wifi-radar was a little iffy.

Bill Clementson gave some great tips for tweaking the XO to make Sugar a little more adult friendly. I love his quake terminal hack, it is so much faster and convenient than the built in terminal activity. I have also settled on Firefox as my browser like him. It looks pretty good:

For some reason I just couldn't get used to Opera. Firefox seems a little slower than Opera did, but it still feels faster than the browse activity that came with the XO. Bump up the minimum font size on Firefox to about 20 and it looks beautiful.

I got evince to install for viewing PDF files (yum install evince) and it works pretty well too:

I spent this evening upgrading my family website all from my couch with the XO. Being able to flip from Firefox to the terminal with ctrl-down was awesome, and I still can't get over how quiet, cool, and, well, cuddly the XO is. I used my work laptop for a bit and it is so uncomfortable with all it's sharp corners, noisy fans, and lap-burning heat. It's also nice to not have to worry about battery time with the XO like I do with the laptop. Just turning off the LCD backlight saves so much power. What a great machine.

Tuesday, March 4, 2008

GPS Fun(?) on Linux

I have a Magellan SporTrak Map GPS that I won as a door prize a few years back. Every now and then I dig it out of a drawer and play with it. I bought a new bike this week, you see, and I downloaded some routes from MapMyRide that I wanted to put on the GPS so I would have a route to follow while biking. Should be pretty straightforward, I thought.

MapMyRide offers downloads of routes in gpx format, which I've run into before while playing with this gps stuff. Cool. So I downloaded the files and did a quick search for Linux GPS software. Unfortunately it still looks like gpsman is still really the only software out there that does what I need (please, please correct me if I'm wrong). gpsman is a piece of ugly tcl/tk software that does a fine job of connecting to my Magellan and allowing me to download and upload track data using the gpx file format. The interface is awful. It opens up three windows that aren't really labeled as to what they are, and offers all kinds of confusing buttons. And did I mention it's ugly? Once you get the hang of it, it does work fine though.

Actually, it did work fine, until I told it to open the gpx file from MapMyRide. It gave me some kind of error with what I'm guessing was a tcl stack trace. It said something about time or date, so I opened up the gpx file. At this point I'm thankful for xml. It was pretty easy to compare the MapMyRide gpx file with one that gpsman had generated from my gps track data and see that the big difference between the two was that the MapMyRide one didn't have an <el> or a <time> element with each <trkpt> element like the gpsman file did1. If I'm reading the gpx schema correctly, those are optional elements, so I think this is gpsman's fault.

To work around this, I just grabbed the two missing elements from my gpsman generated gpx file and pasted them into my MapMyRide gpx file. After that gpsman could "import" the gpx file and then put the track onto my gps.

Now I can see the track as a nice little dotted line on my gps map view and I'll let you know how the bike ride goes.

Footnotes

1 Actually, I ran it through gpsbabel like this first, hoping that would fix the problem:

gpsbabel -i gpx -o gpx,gpxver=1.0 original.gpx original-1.0.gpx

It didn't fix the problem, but it least it added line breaks and made the xml easier to read.