Adding a feature to the crawler today, I ran across this line:
if (!(entry.IsGood && entry.LastStatus != StatusCodes.SpeculativeAdd))
Now what idiot would write something like that? Oh, wait. I’m the only one who’s ever worked on this program.
There are two serious problems with that conditional. First, it’s incredibly difficult to keep the truth table for that expression in my head. Every time I look at that expression, I have to figure out again what it means.
The second and more serious problem is that once I’ve fixed the meaning in my head, I have to figure out if that’s what I really meant to say. And that entails looking through other code and documentation. If I’m lucky I won’t lose my tenuous hold on the expression’s meaning before I tie all the ends together.
I should know better than this. I do know better than this. I cannot imagine what I was thinking when I wrote that expression. What bothers me is that it seems to work, as the code has been in production for months. But it’s going to take me 30 minutes or more to prove that it’s really doing what I want it to do. Believe me, it’s tempting to say, “Well, it seems to work,” and just go on.
The simpler expression is:
if (entry.IsGood == false || entry.LastStatus == StatusCodes.SpeculativeAdd)
The cognitive load is much lower. And, yes, I’m fully aware that a very loud contingent of programmers will scream bloody murder about my choice of entry.isGood == false rather than !entry.isGood. Get over yourselves. In my 45 or so years of writing computer programs for a living, I’ve discovered that I and many others find the former easier to read and understand, especially in unfamiliar code or when scanning code looking for the cause of an unexplained bug. Too many programmers miss that exclamation point on a quick read. Terseness isn’t always a benefit.
Keep your code simple. Otherwise the maintenance programmer who comes by six months later will not be happy with you. And it’s likely that you will be that maintenance programmer.
Something today reminded me of the time my older brother was practicing the song Hava Nagila on his trumpet. I guess I was 9 or 10 years old. A catchy tune, that. I of course had no idea what the title meant or what the lyrics were, but when he started playing the refrain, I started bouncing around the room singing:
Have a banana have two bananas have three bananas walk around the room once more!
As I recall, we both thought that was the funniest thing ever, and we laughed for what seemed like hours. It’s such a strong memory that I often smile whenever I see a banana.
When I got back into ham radio in 2003, Debra bought me a Yaesu FT-90R dual band mobile radio for the truck. I’ve used it quite a bit over the years and have been really happy with its performance until recently.
I noticed a couple of weeks ago that the plastic or vinyl covering on the microphone cord is coming apart. It’s falling apart at both ends, revealing the individual wires. I’ve taped it up temporarily, but in the near future I’ll need to replace that cord. That’s disappointing, as the radio is less than 10 years old and it’s not like I’ve been using it excessively. For sure, being in the truck all the time during the hot summers can’t be especially good for the cord, but I’ve seen much older radios handle that for many decades. It looks to me like Yaesu used substandard materials for their microphone cords.
The microphone cable is a relatively minor problem. This past weekend I discovered a much worse problem: the squelch stopped working. If I turn the squelch up so that I don’t have to listen to the background static, I’m unable to hear transmissions from others. Sometimes this manifests as total silence, and other times it’s an intermittent reception. It sounds like somebody is turning the speaker off and back on a few times per second. It makes the signal almost intelligible.
As it so often turns out, I’m not the only one who’s experienced this problem. In fact, it appears to be relatively well known. Evidently the problem only manifests when the frequency step is set to 5 KHz. Or perhaps if it’s set to anything except 10 KHz. It’s interesting that one site says that the problem is more prevalent on UHF (440 MHz), and others say that the problem is primarily on 2 meters.
I’ve experienced trouble on both bands.
Apparently this is a software problem rather than a hardware problem. The only solution I’ve seen is, “don’t use the 5 KHz step.” That’s easy enough to change from the radio’s options menu, but then I won’t be able to access some repeaters. This morning, for example, there was an emergency situation (toxic fuel spill) and hams were called out to help with notifying residents. The coordinating repeater frequency is 441.625. If I forego the 5 KHz step, I would not be able to hear or transmit to that repeater.
The problem appears to be heat related. Some have said that a second cooling fan helps, and still others have recommended removing the radio’s case and cleaning out any accumulated dust. I’ll definitely try cleaning the thing, but I won’t be installing a fan in the truck to blow across the radio or, as somebody suggested, change the air conditioning ducting.
I’m a bit disappointed, because I really like this little radio. It’s small and yet powerful, with a good signal and a good receiver. Some people complain about the fan noise, but I rarely hear it. But if my only options are to live with no squelch or not use the 5 KHz step, I’ll have to find a new radio for the truck and either sell this one or keep it for an emergency backup.
I wonder what dual band mobile rigs are going for these days . . .
Debra and I bought a new TV last week, along with a computer and other accessories required to launch us into the wide world of Internet TV. Installation went pretty much as expected, with only minor problems, and now we can get all the online offerings on our new 42″ LCD television. Including, I might add, Podly TV. I’m working on a series of blog entries that outlines what we got and how we set it up. I’ll post here when it’s ready.
The biggest problem we had was with the Internet connection. It would be exceedingly difficult to get an Ethernet cable from the router to the living room where the television is. I figured that wouldn’t be a problem, as we do have wireless and we’ve been able to use it in the living room. And although I did get a signal when I hooked everything up, it was very weak and unreliable.
To solve the problem, I first went and bought a new wireless router, since somebody convinced me that it would produce a better signal than the old Linksys WRT54G that I’ve had for years. It didn’t. And although I’d heard that it’s possible to use the Linksys as a repeater, I certainly couldn’t figure out how to do it. Besides, I don’t know how well that would work with such low signal strength, and there wasn’t a good place in between to place the repeater.
So I took it back to Fry’s and exchanged it for a Hawking HAWNU2 adapter, which I connected to the computer in the living room. The adapter is your basic USB network adapter with a directional antenna (they claim 13dBi gain) and a built-in power amplifier. That thing works like magic. My signal strength went from almost nothing (I didn’t have a measuring tool at the time) to three or four bars (out of five). The wireless signal was strong and reliable.
This morning, I learned of cheap wireless extenders. Specifically, how to build a parabolic reflector that dramatically improves wireless signals. The Linksys has two little “rubber duck” antennas that are omnidirectional. The joke in the ham radio community is that vertical antennas (which these are) radiate equally poorly in all directions. The idea of the reflector is to turn those vertical antennas into directional antennas, increasing their effectiveness by directing more of the signal to where we want it. In my case, directing the signal that would go across the street to the new houses being built so that it goes instead to my living room.
If you can download and print an image, and have even a little skill with a glue stick and a knife or scissors, you can make one of these antennas. Or even two or three, if your router has more than one antenna on it.
I downloaded the image, printed two copies, and glued them to a manila folder.
Then, using my trusty Stanley No. 199 utility knife (also makes a great wood carving tool, by the way), I carefully cut out the pieces.
A couple of notes here. First, I didn’t do the cutting on that nice laminate. I used a scrap piece of wood for backing. Also, the six horizontal lines on the bottom piece are intended to be cut so that the tabs on the other piece can fit into them. But just slice along the center of the line. Don’t actually cut out a hole, because then the tabs won’t stick in there. Also, it’s probably best if you wait until after the next step before cutting those slices. Finally, cut vertical and horizontal on the “+” signs on the top piece and then push a pencil through them to open the holes. The antenna will slide through those holes.
More fun with the glue stick. Cover the back side of the lower piece with glue and then attach a piece of aluminum foil. Cut along the outline and slice the horizontal lines:
Then, fold the top piece and fit the six tabs into the six slots you cut in the rectangular piece. As an added precaution, I used some packing tape on the back to hold the tabs down. Here are the two reflectors, ready for installation:
The Linksys router sits on the top of a bookshelf, about six feet off the ground. Here are pictures before and after installing the reflectors.
So how well does it work? I measured the signal strength in the living room with NetSurveyor before I installed the reflectors. The beacon quality fluctuated between 48 and 50%, and gave a beacon strength value of between -61 and -59 dBm. It rated the signal quality as “Very Good.” With the reflectors installed, beacon quality is between 52% and 55%, with a beacon strength value of -59 to -55 dBm. Again, signal quality is “Very Good.” So the reflectors seem to work, but the change isn’t terribly large.
Just for comparison, beacon strength here in my office, with the router just a few feet away, is -46 dBm, quality is 70%, or “Excellent.”
The measurements above were taken with the Hawking directional antenna installed.
If I disable the directional antenna and remove the reflectors from the router, the signal ranges from non-existent to “Poor.” When I installed the reflectors, signal strength was consistently “Very Low,” but it was reliable. Strength was about -87 dBm.
Conclusion: the reflectors work, but not nearly as well as I had hoped. They do make the difference between no signal and a weak but usable signal, but I was hoping for something better. I think more experimentation is required: either two slightly larger reflectors, or one much larger reflector that sits behind the router rather than attaching it to the antennas. Until then, the USB directional antenna remains connected to the computer in the living room.
In How constant is a constant?, I explained how constant values are hoisted from the .NET assembly they’re defined in and at compile time “baked in” to the assembly that references them. The result is that constants are forever. If the value of that constant ever changes then the referencing assembly will have the incorrect value unless that referencing assembly is recompiled.
C# 4.0 introduced Optional Arguments, a feature that has existed for years in many other languages. With optional arguments, you can write a method such as this:
Remember, though, that the default values you supply for your optional arguments are constants. If you change the default value to, say, “goodbye cruel world”, that changes the constant in the defining assembly, but the previous value is still stored in any programs that referenced the older version. You’ll have to recompile those programs in order to get the new default value.
I updated my WordPress installation the other day, and also the Atahualpa theme. The updates installed without a hitch, but the updated theme breaks some of my posts. Specifically, those that have images.
For example, my Bears! post has two images. The size of the first one is set to 780 by 429 pixels, and that’s the size it displays if your browser window is wide enough. If you narrow the browser window, the image is automatically scaled to fit. In Chrome, the scaling appears to be correct.
The results with Internet Explorer 8 aren’t anywhere near as pretty. IE narrowed the image, but for reasons unknown to me decided to maintain the original height. Nice. It’s like a circus fun house mirror.
I spent a little time with the browser’s developer tools (debugger) trying to trace the styles. Somewhere in the stylesheet there’s something that tells the browser to scale the box. It looks like Chrome is scaling in both directions to maintain the aspect ratio, but IE is only scaling the width. I don’t know enough about CSS or this particular stylesheet to say who’s interpreting the CSS incorrectly.
Fixing the error should be fun. My experience with CSS and WordPress themes is that trying to edit somebody else’s theme is like trying to modify an APL program. “Good luck.”
When announcing the U.S. involvement in the U.N.-approved action in Libya, the President stressed that we would not be sending ground troops. Now, we have a diplomat on the ground discussing possible humanitarian and financial assistance to the Libyan rebels. I suspect that soon there will be U.S.-based aid organizations in Libya, funded in large part if not entirely by the U.S. government.
That’s mostly good, I suppose, but when members of those organizations become casualties you will hear many in this country crying out for us to “send in the troops.” I’m not convinced that President Obama (or any other President in recent memory, come to think of it) has the strength to say no to those cries if it looks like sending in the troops will help him win re-election in 2012. The same goes for every Congressman and Senator who will be standing for re-election.
I supported President Bush and Congress when we sent troops to Afghanistan. I thought the idea was to remove the Taliban, who openly assisted the terrorists who carried out the 9-11 attacks, and to dismantle al Qaeda by arresting or killing its leaders and support network. For reasons that aren’t clear to me, we’ve not been wholly successful in that. However, I still believe that supporting the action was correct.
I also supported us going into Iraq because I believed in the President’s assessment that there was a clear and present danger. I also thought that we had a plan. It turns out that the “clear and present danger” was most likely inferred by selectively paranoid interpretations of incomplete intelligence reports, and our “plan” consisted of “kill the bad guys and gather everybody else around the campfire to sing Kumbaya.” I was wrong to support our involvement in Iraq.
I won’t say that our action in Iraq has done nothing positive, but the most important and visible outcome is that we created a power vacuum in the region and there’s only one country with the power to take advantage of it: our good friends in Iran. The Iranian leaders curse us publicly, but I have to believe that in private they thank us every day for removing any possible regional threat to their power. We’re the best friends the Iranian leaders ever had.
We should not be getting more involved in Libya. There is even talk of providing arms for the rebels. Of course, with those arms will almost certainly come “advisors” to show the rebels how to use the weapons. But I suppose those aren’t considered “ground troops,” any more than humanitarian aid workers are. Right? I predict that, if the conflict in Libya draws out, those “advisors” will soon be augmented by other special-purpose personnel who are also, ostensibly, “non-combat troops.” Interesting, though, how often those “non-combat troops” are carrying weapons and actually firing them. Must be one of those definitions of “non-combat” that I’m not aware of.
Let the people of Libya figure it out for themselves. Yes, Gadhafi and his henchmen are slaughtering civilians and armed rebels alike. The same has been happening throughout Africa, Asia, and parts of South America since I can remember, and rarely do we do anything about it. It’s a tragedy, but it’s not our place to stop it. The U.N. seems to think that they have the responsibility to prevent these kinds of atrocities, but the organization is so hampered by politics and bureaucracy that it’s amazing they ever get anything done, even as ineffectively as they do.
If it is our place to stop these kinds of atrocities, then we should stop them: quickly and decisively. Otherwise, we should stay the hell out of it because when we go in pussyfooting around, we invariably make things worse than they would have been had we stayed out of it. Since we don’t have the political will to take decisive action, we should keep the troops–all the troops–at home.
President Obama, now that you’ve shown the world that you have the balls to commit troops and drop bombs, show us that you have the brains to bring the guys home before you get us stuck in another conflict from which we have no good way to extricate ourselves.
I just spent an embarrassing amount of time wondering why my Web application wasn’t displaying things the way I thought it should. When in desperation I made a totally outrageous change to the stylesheet and the display didn’t change, I finally figured out the problem. In my stylesheet, the class name was newVidPreviewImg. In the JavaScript code, it was newvidPreviewImg.
Yes, I had a case problem. My mistake, true, and I’ll own it. But I’ll also say that making names case-sensitive is perhaps the dumbest design decision I’ve seen in CSS–a language that’s chock full of idiocy. The entire language, if you can call it that, is so full of exceptions, limitations, and inconsistencies that it’s pretty obvious the thing is the result of a failed design that was repeatedly patched to handle special cases rather than redesigned to make logical sense. It’s a kludge of the highest order.
Case sensitivity in file names or in programming language identifiers causes an incredible amount of confusion. Development environments that include features such as Intellisense lessen the impact, but don’t eliminate the problem completely. When you’re coding HTML, for example, and you write something like:
<div class="myCoolDivName">
There’s nothing that checks your CSS stylesheet to make sure that “myCoolDivName” is in fact defined. If the name is instead “myCoolDivname”, you’re in for a bit of confusion. The same kind of thing happens in JavaScript.
I’ve yet to see a good argument in favor of case sensitivity in identifiers. Certainly, a programmer would be foolish to define two identifiers in the same scope that differ only by case. It can only cause confusion and lost productivity, especially when you’re working with tools that can’t tell you that you’re making a mistake.
There are many programming language features that, over the years, have been found to be more trouble than they’re worth, and they’ve been eliminated or restricted. Modern languages, for example, restrict the use of the goto statement to prevent you from jumping into the middle of a function or a control structure (you can’t jump into the middle of a loop, for example). C# disallows the shorthand if (a = b) (combined assignment and conditional) because it’s entirely too easy to mistakenly type that construct when you really meant if (a == b) (simple conditional, without assignment).
Case sensitivity is one of those “features” that should not have been included in the C# language, and I suspect it would not have been if the designers weren’t concerned with making it easier to port existing C and C++ code. At least C, C++, and C# have the benefit of a compiler that will tell you when you’ve referenced an undefined identifier. Try working in JavaScript, where identifiers are defined on first use and they’re case-sensitive.
Case sensitivity: evil incarnate. I would suggest that you avoid it if at all possible. It can only hurt you.