Archive for category Programming

Weather Station more stable…

The weather station software stopped working a couple of times in the past 24 hours, so I tried another Serial to USB converter I had available. I’m pretty sure the converter that shipped with the La Crosse WS-2316 was the culprit because I could get things working by stopping the software, removing the USB device, reinsert it, and reenabling the software. The symptoms seem likely to be a driver issue with the original adapter. I guess I’ll know if that is true after this new adapter runs for a while.

I wonder if the protocol for the WS-2316 is published anywhere… It would be interesting to see what it provides and perhaps create some different software to process the data. After a bit of searching, it appears there is a little information on the protocol here and here. Maybe if I can find some free time, I’ll try to put together an application to get the data from the unit. I’m using the WUHU software right now, and it works ok, but I’d like to optimize the data I collect for what I am interested in.

4 Comments

A disturbing idea in hiring…

This video on YouTube highlights an alleged issue in American labor. The problem seems to focus on engineers, primarily software engineers.

This is disturbing on many fronts, and I agree with Lou Dobb’s comments at the end of this second video.

No Comments

Yahoo Messenger 8.0 has a really annoying bug

It looks like I’m not the only one that has run into this issue. I’ve had to stop running Yahoo Messenger 8.0. It has a bug in that it steals focus from all applications running, including its own windows. If you minimize it when you are signed in, it pops right back up. Even if you aren’t signed in, the window keeps popping up in front when you switch to another application. I have noticed that when you aren’t signed in, you can minimize the window and it doesn’t appear anymore.

I’ve turned on and off (it was already off) the “keep yahoo in front of other applications” option. It doesn’t help. The odd thing about it is that it seems to be some interaction with another application. It seems to happen less often if I launch YM before other applications, although it has started happening after it has been running for a bit. I tried to submit a defect report through the menu option, but the main window kept stealing the focus from the defect report window. I had to keep clicking in the defect window between each letter I typed (including spaces). It took me over 10 minutes to type a couple of sentences. In the link I mentioned above, someone has been seeing this issue since September, and I couldn’t find anything on the Yahoo site about it. Are you listening Yahoo???! You are losing users over this issue.

Updates:
Yahoo Messenger 8.1 fixes that annoying bug
Yahoo Messenger 8.1 doesn’t fix that annoying bug

16 Comments

Code Gem of the Day…

I ran across this particular “gem” today in some C code:


char * string = Foo();

if (string == NULL)
{
   string = (char *)malloc(1);
   sprintf(string, "%c", NULL);
}

The intent was to guarantee that “string” contains a C string. This implementation is amazingly stupid for two reasons.

  1. It is really inefficient. What they really wanted on the sprintf line is string[0] = 0; The sprintf line, requires a function call, requires the stack be set up with the string parameter "%c", and requires the function decode the string to determine how to interpret the optional arguments. The alternative I propose ends up being a couple of assembly instructions, no function call, and certainly no format string being generated.
  2. It overruns the 1 byte buffer they allocated. sprintf null terminates the string it creates, without regard for the size of the buffer you provide for storage, and without regard for the content of the formatting values. A safer way to do this would be to use snprintf, which allows you to specify how much storage you are providing. Or better yet, use the suggestion above.

The whole function that this code was contained in was poorly written, but this “gem” stood out.

1 Comment

Powerball number generation in C…

Jeff Spencer wrote a comment about my previous posting about powerball odds. He mentioned that he could only generate 27,000 entries. As my post showed, there are several hundred million. I wrote a small C program to generate the actual powerball numbers, minus the powerball itself. In a private email, I told Jeff where he could find this file. The text file is 80MB, so if you are interested in it, let me know.

The C program is pretty simple. Essentially the key is to iterate over all the possible number combinations without repeating any numbers. This can be done by setting up a loop for each of the five possible numbers. Each subsequent number is just a loop from the previous number +1 to 55. It looks like this:

#include < stdio.h >
int main()
{
   int i, j, k, l, m;
   unsigned int count;
   count = 0;
   for (i = 1; i < 56; i++)
   {
      for (j = i+1; j < 56; j++)
      {
         for (k = j+1; k < 56; k++)
         {
            for (l = k+1; l < 56; l++)
            {
               for (m = l+1; m < 56; m++)
               {
                  printf("%u: %d %d %d %d %d\\r\\n", count, i,j,k,l,m);
                  count++;
               }
            }
          }
       }
   }
   return 0;
}

In linux, you can save the above text to a file called powerball.c. Then using gcc, compile it into an application with the command “gcc powerball.c” (leave out the quotes). Execute this and redirect the contents to a file: “./a.out > powerball_entries.txt” (leaving out the quotes again).

No Comments

Bandwidth finally available…

Ok, the pressure has finally lessened a notch. I have a few minutes each day for random web-browsing. I’m even contemplating doing some personal software development on a project that has been simmering in the back of my brain for the last year or so. Whew!

We had a couple of odd things happen in the neighborhood in the last week. The first was rather unfortunate. Someone shot one of the many squirrels in the neighborhood in the back of the head with a BB gun. Unfortunately, the squirrel didn’t die from it. It was half crawling around for quite a while. It ended up getting herded into a recycle bin. Lisa called around to see if there was anyone who would take squirrels, but the animal hospitals weren’t interested, nor anyone else we could think of. The next morning it was dead. I fear for the cats. If there is some person that finds shooting small animals exciting, I think the cats won’t be too far off target. One lady in the neighborhood already mentioned that it had happened before.

The other interesting point was an encounter I had with a guy two days ago. I was sitting in the livingroom when I noticed a guy dragging a bean bag chair down the street. I knew where he was headed — the dumpster near the apartment complex down the street. I grabbed the camera and headed out the door. The lady that manages the apartment complex gets very angry when people leave trash sitting there. She has called the police on several occasions. Once outside, I started taking pictures of him dragging this thing down the sidewalk. He was talking on a cell phone. As I suspected, he stopped in front of the recycle bins, released the chair, and turned around without missing a beat in his phone converstation. He didn’t even notice that I was across the street, taking pictures the whole time. When he was about 10 feet from the chair, I got his attention. I informed him that he couldn’t just leave that there — it was littering. He said he had gotten it from there a few days back. I told him I didn’t care — he was littering. He then started complaining that he was on the phone — could I wait a minute. I didn’t wait. I told him the lady that manages the apartment would be happy to call the police to report the littering incident, and I would be happy to furnish the pictures of him dragging the thing down the street to the police. He then realized that the person he was speaking to on the phone hung up. He trudged back to the chair and proceeded to drag it down the street, while trying to dial a number on his cell phone.

Thus is the high level of excitement in our lives. I have been playing with a bunch of Google applications: Desktop, Earth, Hello, and Talk. While I think Earth is pretty darn cool (although not that stable on my laptop), I think Hello and Talk have a long way to go. The only ties seem to be related to gmail — there is some linkage with the address book held by gmail. First of all, they both have IM interfaces which have different user lists, and behaviors. Talk is very primitive, although the VOIP feature has nice quality in the trivial tests I have done. With the exception of Desktop, I don’t see a compelling reason to run them all the time. The last thing I need is more applications that I don’t use chewing up memory and ethernet bandwidth. My hope is that these products converge into something more useful. Talk does replace the gmail notifier application, which is ok, but I doubt I will end up using it for more than that.

No Comments

Yourself Fitness

Lisa and I bought a copy of Yourself!Fitness for the Xbox at the beginning of January. We both need more exercise in our lives, and with our busy schedule, we never have time to go to the gym. I had read a review of the product somewhere (I can’t seem to find it now), and thought it might be a better solution for us than going to the gym. The gym is twenty minutes away, which is prohibitive given our tight schedules.

The first time you use the product, you enter your name, some statistics, and then proceed to do a “physical challenge”. This involves measuring your resting and active heart rates (after doing some jumping jacks), lower body strength via squats, upper body strength through push ups, and core strength through crunches. The first time I did it, I was able to do all the squats easily. This seems to be a flaw in the design — Lisa didn’t have any problems with this either. Once that evaluation is done, you commit to a workout schedule for each week, and set your goals. The workout intervals are in increments of 15 minutes, with one workout allowed in each day.

I chose 30 minute workouts 6 days a week. In order to make this possible, I began getting up a half an hour earlier in the morning, and working out first thing. This schedule has worked well for me. Lisa is not much of a morning person, so this really isn’t a possibility for her. Each day you go to work out, you choose a focus. This might be weight loss, cardio, upper body, core, lower body or flexibility. The software suggests one for you every day, but you can easily override the choice. You also get to choose the length of the workout, choose the music you want to hear, and specify any optional equipment you might have. This optional equipments includes heart monitor, stability ball, aerobic step, and hand weights.

There are a lot of things I like about Yourself!Fitness, and a few things that bug me. I like the fact that the workouts are customized to your level of fitness, and that they vary each day. I like the variety of exercises, and the cheery nature of the character (Maya) in the game. She has encouraging words before, during and after the workout. There are times I forget that I am working with an animation, and her encouragement seems genuine. She has a lot of different responses that she uses during the workouts, so it doesn’t become too repetitive. I like the fact that the software evaluates your progress at specific intervals, to help encourage you to continue.

There are few things that bug me about the software though. The first thing you see when you begin to interact with the software is the character on half the screen. She sways and twitches in an unnatural way. The lip syncing in this section of the software is not great, and it is bad enough that it is distracting. Even Lisa commented on it, and she hasn’t ever developed software before. There are some glitches in the workout sections too. During the workout, there is a window into the timeline for the workout. It generally shows the exercise you are doing, and the next exercise. Occasionally, during some of the aerobic workouts, a rest period will show up, but when the timeline reaches the rest period, it mysteriously disappears, and you are on to the next exercise immediately. In all instances, this has been another set of the previous exercise, so it isn’t terrible, but it is unexpected.

It bothers me that when a new exercise is being done, there is little to no introduction to it. If you want to know how to accomplish the exercise, you have to grab the controller, and interrupt the sequence. This brings up a new screen that has an animated set of body parts with a voiceover demonstrating how to accomplish the exercise. This is a bit of a hassle, and certainly interrupts the flow of the workout. This is especially true during a “flexibility” oriented work out. The Yoga positions are often difficult, and with little explanation, they are certainly more difficult.

The software asks you after each section of a workout to rate how difficult you found that particular section to be. If you rate it as “No sweat”, the software records this and makes it more difficult the next time you do this type of exercise. Similarly, you can rate it as too difficult, and the software will scale the difficulty down. In addition, you can interrupt an exercise and make it more difficult or easy. I haven’t used that feature too much, relying on the queries to vary the workout. I do this because I find that parts of a section are easy, while other parts are difficult. If I turned up the difficulty in the easy parts, the hard parts are too difficult.

I have also noticed some odd behavior with Maya during workouts. During some of the exercises with hand weights (I can’t remember the instance specifically), the weights actually went into her body, which looked really odd. Also, it seems that the upper section and lower sections of her arms are rigid parts with little blending between them. During some of the workouts, when she bends her elbow, you can see the corners that make up the joint of her upper arm protruding through. The workout equipment does this strange appearing and disappearing act between sets. If a given set uses hand weights, the weights magically materialize in the character’s hands just before the set begins. This includes the stability ball and the step. It would be much better if the character acted in a more realistic manner, getting the equipment and returning to the same location.

The visuals, aside from Maya’s pointy elbows and twitchy behavior in the main menu are well done. There are reflective surfaces, and simple animations in the background. Maya lip syncs during the workouts, which look good at that time. As you complete more workouts, different environments are unlocked, and music as well. In the environments, the sun is always at a fixed location, so the shadows are fixed as well. Maya casts a shadow on the ground. Unfortunately, in most of the environments, her shadow has different characterstics than the shadows rendered into the environment. Her shadow is always softer, and not nearly as dark. It just looks wrong once you see it.

All in all, I like the software. I feel physically better after working out, and it makes the whole day more tolerable. The results so far have been encouraging. I went from 162 lbs on January 8th to 147 lbs this morning. My goal is 135, so I’m heading in the right direction.

5 Comments

Dysfunctional Development Practices

I am working with a team that has been working together for a while. I learned today that one of the “normal” practices for this team is to reboot development machines between code changes. This is done to mitigate the various odd behaviors and crashes they encounter if they don’t. My first thought after hearing this was, “WHAT?!?!” It sounds amazingly unproductive to me. Of course, in my experience I tend to develop code a bit differently than other people.

My development practices tend toward a short “author/build/test” cycle. Short in terms of a function or two. Normally, I would follow the new code flow in a debugger, to make sure things are behaving how I would expect them to. This system allows me to guarantee that my code is solid when I make it available to everyone else, and I have a system that allows pretty rapid development. My guess is that members of this team do a lot more authoring before testing changes. This, in my experience, just leads to more difficult debugging, and less tested code. Especially when in this development system we don’t have debuggers. I guess I should feel lucky that I have printf available to me.

I asked why no one had figured out why a reboot is needed, and was told that the person who could fix the problem doesn’t run into the problem because they develop differently from everyone else. What kind of dysfunctional system is that?

Given the longer “author/build/test/reboot” cycle of this team I may have to modify my own practices. It will be impractical to reboot my machine 12+ times a day. Perhaps I’ll spend some free time trying to understand what the root problem is and fix it for everyone, instead of just complaining. 🙂

1 Comment

NYTimes article on Jobs to India

1 Comment

.NET development experiences

I have recently inherited a project from someone that opted to do it in C++/.NET It is a relatively simple GUI application, which interfaces with some more complex code. I must say that dealing with managed code in C++ is annoying. Mixing GC and non GC pointers is confusing as all get out. I have been relying primarily on the compiler to yell at me when I try to delete something that is managed. I find it irritating that managed object functions can’t be const. This breaks one of my personal programming style guidelines. Another annoyance has been the Properties for some of the .NET provided objects. Take Point for example. It has get_X() and get_Y() but neither are declared const. This means that a function:

void DoSomethingWithAPoint(const Point &p) …

Has to make a copy of p to actually get at the members. I suppose I could remove the const, and make it :

void DoSomethingWithAPoint(Point &p) …

But in my mind, that implies that the function is going to modify the Point. So, I have to really write it as:

void DoSomethingWithAPoint(Point p)

which implies the copy. Most of the time, I don’t need the “expense” of the copy, as the operations are pretty darn simple.

I think the answer in the future is for us to better segment the code and provide a REALLY strict line between managed and unmanaged C++ code.

If I had my druthers, we wouldn’t be doing this in .NET — I have some comfort in the notion that this part of the project will be short lived.

I must say though, the difference between Linux – C++/emacs/gcc development and WinXP – Managed C++, Visual Studio development is quite large. I’m having to switch between them all day long. Hopefully I can reschedule these projects so I can do one and then the other. I’m not terribly efficient working as I am right now.

No Comments