Rants on software, computing, and any other topic I feel like.

Thursday, January 20, 2011

Emacs for Visual Studio users

Now that I'm using Linux to do all my development, I'm finding that a few things that I got used to in Visual Studio can be a little more difficult in emacs and a terminal. However, I'm finding that emacs generally has all the features I'm looking for and more if I take the time to learn them. Here are a few features I used in Visual Studio for which I've found equivalents in emacs.

Find in Files

"Find in Files" is a particularly useful feature in Visual Studio. For a while I was just using grep in a terminal and manually jumping to files it found. Slow and annoying. M-x find-grep is just what I was looking for. It would be nice if I could more easily tell it not to search everything and just *.cpp and *.h files for example.

M-x find-grep-dired puts the found files in a dired buffer (something I need to learn more about) and lets you do things like query-replace on a marked file. I haven't used this but it seems much more powerful than Visual Studio's system.


Until I'm convinced otherwise, I still think that Visual Studio's debugger is the best in the business. Qt Creator comes close but the rest of the interface there isn't so hot. Emacs with gdb is surprisingly good and much better than the last time I tried using it a few years ago.

One problem is that I can't set or even enable a breakpoint while the program is running. Sometimes this is really useful as you have to run some code that will hit the breakpoint a lot before the one time you're interested in. Sometimes, it's really a matter of clicking "enable" at just the right time. Conditions help here, but sometimes it's just easier to enable when you need to.

Saving breakpoints was something I didn't think I could do, but the "save breakpoints" command seems to overcome that. Not as clean as Visual Studio, as I have to "source" the resulting file when I restart.

One command that has promise is rbreak, which I can use to set a breakpoint on all functions which match some regex. I couldn't get it to work however. It seems to find all the functions, but when it tries to set the breakpoints, it can't find them and asks if I want to delay setting them. Bug.

File Navigation

I like "C-x b", which allows you to load existing buffers quickly. I think there was something in Visual Studio that did this, but I never used it. If anything, I don't think it had tab completion, which emacs does.

Labels: ,

Thursday, January 13, 2011

iPhone on a virtual machine

Ever since I started my new job where I don't have to run Windows all the damn time, I haven't sync'ed my iPhone. So, when I tried to just back it up on Ubuntu, it totally messed up the iPod app. So I decided I wouldn't try that again. Anyway, now that VirtualBox supports USB passthrough, I figured it was time to try to get it working again. I created a Windows 7 virtual machine and installed iTunes, moved my library over, and started syncing. Some things that might make it easier on those trying to do this:

1. Make sure you're in the vboxusers group. Things worked for me without doing this, but I had problems, so just do it even if things work for you.

2. The iPhone occasionally will disconnect on certain types of operations and come up as a different device which won't get automatically captured by VirtualBox. iTunes then waits and waits for the iPhone, but never sees it so bad things happen. Watch for this and tell VirtualBox to capture the iPhone when it happens. I think the USB filter thing in VirtualBox helps here. This is especially important when updating to a new version of iOS. If you have problems, look up UDF mode.

Labels: ,

Tuesday, January 04, 2011

Switching on Boolean Conditions and Flags

I just posted an article over at CodeProject.com about what I call a boolean switch or switch flags (as the library I wrote is called). I've thought a lot about it over the years and implemented in a couple ways. It reduces the complexity of nested if statements. Basically, it allows for code like this:

switch_flags_2(a > b, c != d)
case flags_2(T,T):
// only execute when "a > b" and "c != d"
case flags_2(F,X):
// execute when "a > b" is false

Labels: , ,

This page is powered by Blogger. Isn't yours?