20 Apr 2006, 04:54

The exciting world of operator precedence

I think it’s time we had a talk about operator precedence. Specifically operator precedence in C++ as it pertains to the bitwise “and” and “or” operators (& and |). (Ok, and let’s not forget the all too often overlooked “xor” (^)) One thing that it seems that people occasionally forget is that these operators are evaluated at a lower precedence than the comparison operators, such as == and !=. This means that the following piece of code doesn’t do what you might have assumed it would:

if (bitmap & BIT_MASK != 0)
{
...
}

Unless, of course, you correctly assumed that it would first compare BIT_MASK to see if it is not 0 (which likely is true) and then performs a bitwise “and” of the result of that comparison and the bitmap variable. Not the intended result at all. For this to work you would need to group the bitwise portion of the expression using parentheses (which also happen to be at the highest level of operator precedence) like so:

if ((bitmap & BIT_MASK) != 0)
{
...
}

(Of course the comparision to 0 is completely unnecessary in this example, but hey, it’s just an example.) This isn’t anything groundbreaking, in fact it’s pretty basic stuff. Still, given the fact that I’ve seen this several times as the root cause of defects I’ve fixed makes it seem like maybe this gets overlooked too frequently. I wonder if it may be due to the fact that the bitwise operations feel more like arithmetic operators such as + and – which do have a higher precendence than the comparison operators. It’s always a good idea to pay close attention to how your expressions will be evaluated and not just assume that things will be grouped the way you intuitively feel they would. And of course it’s an even better idea to actually step through your code and see just how that expression evalutes for different possible values of the variables, which would have caught something like the above mistake trivially.

Comments

Comment by Neal on 2006-04-20 07:52:28 +0000

I usually avoid precedence problems by blasting parentheses all over anything that is even remotely ambiguous in my mind.

Maybe I’m just being lazy to not learn the precedence tables, but I tell myself that I’m “increasing my code readability”.

Comment by Phil on 2006-04-20 11:45:28 +0000

I must say, I only understood about 34 of that, since I don’t code myself. But, seeing as how I’m writing a book with a coder as the protagonist, it’s nice to see a bit of ACTUAL C++ being thrown around (as opposed to the fake kind).

I think it’d be fun to learn C++, but sadly, I will settle for AppleScript at the moment.

Comment by Tobin on 2006-04-20 19:40:50 +0000

I can honestly say, in the past almost 5 years of career software development, I have never used the bitwise AND/OR. And I’ve used the XOR once. Maybe.

Does that make me a bad programmer?

Comment by Will on 2006-04-21 22:58:53 +0000

Yes, yes it does. Ok, no it doesn’t. But never? Really? I don’t use them every day or anything, but they certainly come in handy every now and then.

Comment by Tobin on 2006-04-23 19:21:42 +0000

Yes, really. What do you even use them for? I have a feeling they’re more useful in c++ than java.

Comment by Will on 2006-04-23 19:48:25 +0000

They’re just a convenient, fast, and succinct way to pass around and test for multiple boolean properties or flags at once. Plus if you’re passing things around as a bitmap it can be nice because if you end up needing to add a new property in the future you can just define an enum for the next bit in the bitmap without having to add a new method to the object. Also you tend to work with them a lot more when doing MFC development (I know, painfully outdated) because window properties are often set as bitmaps.

Comment by Posko on 2006-04-27 16:39:28 +0000

Nerd talk!

19 Apr 2006, 05:08

Orb

A while back when I was gushing about my new phone, I mentioned an audio/video streaming program called Orb that I thought was pretty cool. 3 months later I’m still just as impressed with how simply and conveniently it can allow my phone to function as a portable media device. I’m guessing it’s just a matter of time until something like this makes iPods obsolete (ok, but I’m not going to take a guess as to how much time. It could still be a while, fair enough) Why worry about filling up a hard drive/flash memory device with music and movies when you can just stream them from your collection at home. I’m able to listen to my mp3 collection on my phone with a level of audio quality that’s almost as good as an mp3 player. It’s not quite there but I don’t know how much of the difference comes from Orb itself, the network speed, or just the fact that the phone’s audio hardware probably isn’t designed with serious music listening in mind. In my opinion though, I think video is where Orb is the best. I can watch any of my recorded tv shows from anywhere, and the best part is that I don’t have to re-encode them to a format and size that my phone can handle. Orb manages to pull off transcoding the files on the fly so the same massive uncompressed MPEG-2 recording of say, last night’s episode of the Daily Show can be displayed on my phone’s screen even when the network speed isn’t at its highest. It’s just another example of the way Orb makes something as seemingly complicated as streaming media content to mobile phones dead simple. Here’s the entire set up process: Install Orb. Start Orb. Set the folders that have files (music or video) that you want to stream. Log in from your phone’s web browser. That’s it. And it’s free. The mind boggles. There are a couple of small drawbacks, for example the playlist control for music files is somewhat lacking. Once my phone’s media player has started playing the stream there’s no way to skip over a song without stopping the stream returning to the phone’s browser to select the next song. I usually tend to just listen to large playlists on shuffle though, so it’s not that big of a problem for me. Also, if you were hoping to make friends by letting other people stream stuff from your computer at the same time, that’s pretty much out since it only allows for one user to stream at a time (though I think they may have a non-free version that allows for this). Minor issues aside, Orb is just about the best way to make use of a mobile phone ever. Other than, you know, talking to people. I have seen the future, and any future that involves watching an episode of The Simpsons while waiting in line at the DMV to renew your license plates is ok with me.

17 Apr 2006, 05:16

Spoon @ Day on the Hill in Lawrence KS

Last weekend Jolayne and I went to Lawrence to see Spoon play at Day on the Hill, a music festival put on by KU’s student activies center. Apparently the festival was pretty big in the mid 90’s but had gotten progressively less impressive in recent years, and had been on hiatus since 2002. This year was an attempt to revive the festival, and having Spoon as the headlining act was definitely a good start. It would have been nice to see some of the opening acts too, but really you can only pretend you’re still in college for so long. The above video is of the song “Everything Hits at Once” from their album Girls Can Tell which they played during their encore. As awesome as everything from Gimme Fiction is, I still think that one is probably my favorite song of theirs. The sound and video quality aren’t anything amazing, but I was pretty impressed at how well my camera was able to double as a video camera, especially from how far back we were.

Comments

Comment by Brett on 2006-04-18 20:05:45 +0000

You’re right. That is pretty impressive for a phone. Hello! You’re recording video with your phone! That’s one of those things you wonder what you would say if someone told you that you would be doing this 15 years ago. You’d be like “Whatever. Why would I want to do that!?”

Anyway, I was way impressed when I saw Spoon last summer. They just have so many good songs. They are one of the few bands that I don’t want to stop playing. Ever.

Comment by Will on 2006-04-18 22:16:00 +0000

That definitely would be impressive for a phone, but this one was actually just done with my digital camera in movie mode. I did try using my phone to record video at a Wilco concert a couple of weeks ago and the results were much, much less impressive. We were too far back for one thing, but the sound level was just waaay more that it’s poor mic could handle and the audio was worthless. I don’t doubt that it won’t be long until something like this can be easily done on a phone though.

15 Apr 2006, 04:28

BBQueue – A Yahoo! Widget

This has kind of been out for a while now and I meant to post about it earlier but it sort of got overlooked in the craziness of moving and whatnot, but I put together a widget for Yahoo! Widgets (the exclamation mark always seems like a little bit much to me) for checking up on the movies in your Blockbuster queue. It’s called BBQueue (Oh don’t worry, I’m already aware just how terribly, terribly clever that is.) I think it’s pretty handy if, you know, you use Blockbuster instead of Netflix, which we do. Netflix is kind enough to provide RSS feeds for their user’s lists but Blockbuster apparently isn’t too hip about what the kids are up to on the internets these days. As a result this widget gets by on screenscraping and I’d be almost willing to guarantee that if Blockbuster makes any changes to their site it’ll break my modest regex-fu. But for now it works, so hopefully it’s of use to someone and maybe someday I’ll get around to adding some more functionality to it.

Comments

Comment by Neal on 2006-04-14 22:22:49 +0000

Regular expressions for the win!

13 Apr 2006, 05:13

The end of an age old debate

It seems that the whole time we were wondering whether pirates or ninjas were more awesome we were asking entirely the wrong question. The true winner of the struggle for awesomeness has emerged from the shadows and it’s… ATF agents? Despite the fact that ninjas are not normally known for being involved with either alcohol, tobacco, or firearms ATF agents recently detained a University of Georgia student who was dressed like a ninja as he was leaving a “pirates vs. ninjas event” on campus. As I’m sure you’re aware, the only way a ninja would be leaving such an event would be if all the pirates were dead. That the ATF agents were able to subdue the victorious ninja clearly shows that they deserve their place on the top rung of the awesome ladder. In addition to vast physical prowess these agents obviously possess a fearsome cunning as well:

‘Seeing someone with something across the face, from a federal standpoint — that’s not right,’ McLemore said, explaining why agents believed something to be amiss.

Obviously from a state or city jurisdiction standpoint this situation would be no cause for alarm. Fortunately thanks to highly trained federal agents we have nothing to fear from collegiate ninjas with something across their face.

12 Apr 2006, 05:36

It’s harder than it looks

Contrary to popular opinion (and by popular I mean mine, previously) a house is not just like an apartment that you’re allowed to paint. It turns out that owning one is, to put it mildly, a fair amount of work. I mean, I’m sure it’s worth it, what with all the equity and whatnot but still a lot of work. At any rate, it’s certainly kept us busy over the past couple months. The move itself went smoothly and with minimal destruction of personal belongings. We’re mostly unpacked now but we still need to kind of improve the storage situation somewhat. Another thing that I didn’t realize about getting a house is that it means that Home Depot gets all of your money. Of course I’m just kidding and that’s not really true. Lowe’s gets some of it too. Speaking of fun ways to spend a lot of money on your house, here’s what we woke up to one morning in March a couple weeks after we moved in:

You can’t really tell from the video but a lot of the hail was almost golfball sized. Here’s Jolayne holding some of the hail stones afterwards.

At the time we just thought, “Man, isn’t it awesome that we have a garage. Otherwise our cars would be totally messed up.” It looked to us like we escaped with no other damage than some window screens that got knocked out. Just to be safe though we had an insurance adjustor come out and look at the roof. And that’s when we learned a valuable lesson about home ownership, the lesson being that hail is very, very not good for your roof. Consequently, we’ll be having the roof replaced shortly. Welcome to owning a home!

Comments

Comment by Tobin on 2006-04-11 23:13:29 +0000

Welcome to owning a home.

Have you bought a lawn mower yet? That’s when it really sank in for me.

Comment by Carrie on 2006-04-12 01:10:14 +0000

Holy hail Batman! Roof damage is the worst, so luckily the worst is over. Positive thinking! 😉

I agree with Tobin — the lawn mower is the clincher … pretty much any type of lawn-care device.

Welcome to zee club!

Comment by Posko on 2006-04-12 16:11:24 +0000

Wow! It hailed so hard it shook the camera!

Comment by Will on 2006-04-12 22:21:48 +0000

Not only that but at the end the hail was coming down sideways! Or maybe it was just gross incompetence on the part of the camera operator, one of the two.

We’ve got a lawnmower, and I’m rediscovering the weekend pasttime that I loved so much when I still living with my parents. Putting off mowing the lawn as long as possible. Fortunately you only have to mow it once and then you’re done, right? Oh.

30 Jan 2006, 02:25

Is that a broadband connection in your pocket?

Why yes, yes it is. Thank you for noticing. I recently just renewed my cellphone contract with Sprint and picked up the uber cool Samsung A900. This thing is a seriously impressive piece of pocket sized hardware. While its design obviously “borrows” heavily from the Razr, the A900 wins the technological superiority contest hands down. In a form factor only slightly larger than the Razr it manages to pack in an overwhelming list of features. I’m giddy. Here are some of the high points:

· EV-DO. Or as Sprint’s marketing division prefers, “PowerVision”. This is the big one. Essentially, this phone offers an internet connection as fast as a low end DSL or cable modem. Phone web browsers and network apps were pretty much a joke in the past, being so ridiculously slow that they seemed more like a proof of concept than something that would actually be useful. Not anymore. Checking Gmail, searching Google, streaming audio/video now all work at speeds that don’t make you want to smash your head into something hard.

· Bluetooth. It took them forever, but Sprint finally has a Bluetooth phone that they didn’t cripple to only work with headsets. Sure it does headsets, but it also transfers contacts and files, and allows dial up networking over a Bluetooth connection for devices like PDAs and laptops. A high speed completely wireless network connection in your pocket. Believe me, it’s GLORIOUS.

· 1.3 megapixel camera/camcorder. Pretty decent for a cellphone camera. Nothing amazing but at least I’ll always have it on me.

· MP3 player. There’s 50 megs of internal memory that can be used to store audio files to play on the phone’s media player. Granted, that’s not much space and a miniSD card slot would have been nice, but it’s just a nice bonus feature on an already amazing phone. Plus, the connection speed is fast enough that you can just stream audio and video from home using Orb (which is really cool enough to get its own post)

Now for the negatives:

· Battery life. The phone may be sports car sleek, but it burns through its battery like a Hummer. There’s no way around it, this thing is a gas guzzler. It’s rated for 3 hours of talk time, but with any significant amount of network/camera/java app usage, it pretty much always requires charging at the end of the day. So you could say it’s a little high maintenance but I think it’s worth it.

· Confusing & expensive data plans: Here’s the problem – no one working for Sprint has anything resembling a clue about how the new high speed data plans work. There are plans for unlimited data on the handset, but try using it as a modem with that plan, and you’ll get billed an absolutely disgusting amount per KB. There’s supposed to be a plan that lets you get a whole 40MB/month (you’re joking, right?) of modem usage and unlimited handset data, but no one at the Sprint store could figure out how to apply it. On top of that, all of Sprint’s marketing materials are piss poor at distinguishing plans that apply to the old standard Vision as opposed to the new PowerVision. Then apparently there’s a plan that gives you unlimited data on the phone when used as a modem, but you can’t use the phone for voice calls. Who would want that? Until Sprint’s marketing and customer service departments can extract their heads from their collective nether regions, I’m just sticking with the basic unlimited PowerVision handset data plan and having to smack myself every time I think about trying to use it as a modem.

Comments

Comment by Ash on 2006-01-29 21:08:19 +0000

Man.. I gotta get me one. That’s all I gotta say.

BTW, I think its funny that EV-DO is nicknamed PowerVision at Sprint. So, what technology are you using when you write Notes with your a900? or… if you were to fill out Forms, lets say? Or, in … Ok ok I’ll stop with that. But seriously. I think the naming-droids in marketing are in the shop for servicing…

Did I mention I wanted your phone!??

Comment by Ash on 2006-01-29 21:11:29 +0000

Also… Sometimes I feel like they make the plans confusing intentionally so that you get the old hucklebuck when you actually use the bandwith you’d *expect* only to be shot down by the automated Sprint text message czar and his cease and desist order. Then you already have the phone and you are forced to upgrade your plan. You should blog about it and we’ll have 9488432 people DIGG it.

Comment by Will on 2006-01-29 21:29:48 +0000

You cannot have my phone. You should, however, get one. I can’t stress that enough. And you’re right, I’m positive that they make the plans confusing on purpose so that people either end up paying monthly for services that they never use or get charged extra fees for services they thought were included.

Comment by Neal on 2006-01-30 11:30:46 +0000

I started crying before you got done with the bluetooth point.

Points that get a hearty “I concur!”:

  • Phone companies are schizophrenic about data plans – “Check out our neat-o internet access! But don’t use it!”

  • I never thought that a phone company would make a non-crippled bluetooth phone. My understanding of cell providers so far has always been justified by the theory that they hate us. At least, that’s the model that their actions reflect. So they’ve made a bluetooth phone that can transfer files and act as a network connection for a laptop? Maybe they just didn’t understand what they were doing.

Comment by Will on 2006-01-31 08:28:35 +0000

Yeah, it’s funny but my first thought when I read that the phone could use bluetooth for files and as a modem was “Oh man, someone at Sprint screwed up”. Like the dude that normally cripples the bluetooth is was on vacation or something. And I think you’re right that they hate us. Probably not all of their customers, though. I bet they really like the ones that sign up for expensive plans and never really use the phones for much more than voice. It’s the geeky customers who get minimal voice plans and want to get every last bit of bandwidth out of their data plans that they must hate.

Comment by Seth on 2006-04-10 06:43:46 +0000

Perhaps young William has abandoned his blog because the Internet is so much more fun on his phone…

Hope all is well, looking forward to your return.

29 Jan 2006, 03:14

Take the Goldshire exit to Stormwind. Go 0.5 mi

Behold, the nerdiest use of the Google Maps API yet: a Google Map-ized view of the World of Warcraft. Impressive. But I don’t think it will really be complete until I can get turn by turn directions from Lakeshire to the Swamp of Sorrows, or search for trade good vendors near a specific zip code. Does Azeroth even have zip codes? They should probably get on that. One thing I hadn’t realized before was how completely ugly Azeroth looks from the air. It’s like a patchwork quilt made by someone’s colorblind grandmother.

24 Jan 2006, 14:51

Magical Mystery Tour

And now, a video tour (50MB, QuickTime) of our house dorkily narrated by yours truly.

Comments

Comment by Brett on 2006-01-25 05:27:58 +0000

What, no Rush? I’m disappointed?

Comment by Will on 2006-01-25 07:25:41 +0000

Crap, it does need a soundtrack, doesn’t it? Looks like your video remains the Most Rockingest New Home Video of all time.

Comment by Ash on 2006-01-25 09:12:58 +0000

Whoa, that’s awesome. So its taking kind of a long time to download, Jeebus… 50MB!! I’ll have to try it again while I’m at home. Looking forward to coming over and geeking out in the new pad, man. As soon as I’m done with the *exam*, anyways.

Comment by Sarah on 2006-02-06 16:55:17 +0000

It’s huge!

21 Jan 2006, 15:46

New House Day!

Last night was the night that we finally got possession of our house. We met the former owners there, did the walkthrough, got the keys and then ran through the house giggling like schoolgirls. The last part was after the old owners had left though. Well, mostly. I think we still can’t believe that it’s actually ours. We just kept walking around through all the rooms trying to take it all in. The plan had been that we would “camp out” there last night, but, well, we didn’t realize that you had to set up water service. We’d set up electricity and gas but hadn’t even thought about water. Yeah, we’re still kind of new at this homeowning thing. So as soon as we realized there was no water, that kind of put an end to the camping trip. I mean, that would have been a little too close to actually roughing it. I did take a bunch of pictures before we left though and hopefully I’ll get them up on Flickr later on.

Comments

Comment by Tobin on 2006-01-22 21:36:23 +0000

CONGRATS!

Comment by Will on 2006-01-23 07:56:56 +0000

Thanks!

Comment by Nathan Hessler on 2006-01-23 17:38:41 +0000

Congrats! Glad to hear things are going well for you. 😀

Comment by Carrie on 2006-01-24 02:40:25 +0000

Yay home-ownership!