Bose headphones

I received many wonderful gifts for my birthday, but these in particular have helped me at work in a way nothing else has.

I listen to music constantly as a program–it helps me concentrate and eliminates all other distractions. 

They really do work as well as I expected–maybe even better. I work in a pretty noisy environment–the hum of airconditioning, computers, and people is constant. These take it all away. I don’t get ear fatigue because the volume is lower than I usually had it, and the cuffs fit around the ears, not on them. The A/C sound is completely gone, and people sound like they’re far away, even if talking right next to me. I’ve heard things in many songs that I’ve never heard before, especially at the end of some tracks when the last vibrations of an instrument are fading out–you can hear every last bit, and it’s wonderful!

 

Riverdance

Leticia and I took in Riverdance over the weekend. I’d seen the video and listened to the music countless times, but seeing it live on stage is a completely different experience. If the tour ever comes to your area I highly recommend it. The foot work is simply out of this world and the music is a lot more fun live (isn’t it always?). I can’t say I have a favorite part–it was all incredible.

Getting the real view under a CPreviewView (MFC)

I had an interesting problem at work the other day. In this MFC application, there are a number of views that can be printed and we support the Print Preview function.

However, in one of these views we rely on getting the view from the frame window in order to handle command updates. This is accomplished with code like this:

 pWnd = reinterpret_cast< CBaseView*>(GetActiveView());

However, when you’re in print preview mode, GetActiveView() returns a CPreviewView, not the underlying view (CBaseView). If you look in the source of CPreviewView, you’ll notice that it has a protected member m_pOrigView, which is indeed the one I want. However, there is no way of accessing that value. (I briefly toyed with the idea of directly accessing the memory via its offset from the beginning of the object, but as this software has to run in unpredictable environments, and it’s a horrible idea anyway, I let that go…)

 If you try this:

pWnd=(CBaseView*)pWnd->GetDescendantWindow(MAP_WINDOW);

Where MAP_WINDOW is the ID of the real view that I want, it won’t work (it may work in the general case, but it doesn’t work in my case).

I had two options, just return NULL and tell the higher-level functions to not do those certain command updates when the returned view is NULL. This should be done anyway, so I implemented those checks.

However, it still bugged me that I couldn’t get access to the real view. At last I hit on the idea of going through the document (this uses the Doc/View framework).

 I used this code and it did exactly what I needed:

CDocument* pDoc = GetActiveDocument();
if (pDoc!=NULL) {
    
POSITION pos = pDoc->GetFirstViewPosition();
    
CView* pView = NULL;
    
do {
            
pView = pDoc->GetNextView(pos);
            
if (pView != NULL && pView->IsKindOf(RUNTIME_CLASS(CBaseView)))
                        
return (CBaseView*)pView;     } while (pos!=NULL);
}

 

Rhythmic Programming

Has anyone else ever had the experience of typing code in such a way that you build up an actual rhythm, patterns, a definable velocity punctuated by occasional flourishes? 

I found that happening today. I’m coding up a well-understood pattern in this application and so I can type quite a bit in long spurts. I find that I’m almost typing in “sentences” as I go…it’s very interesting…kind of odd…

Unsupported Frameworks…

Programming with a framework that you’ve developed can be annoying, when you compare it to the ease of IDE-supported frameworks. MFC is a nice framework primarily because Visual C++ has so much built-in support for it.

My little framework has no such support (and I have no ambitions to build in IDE support for it) and that can make it frustrating to do all the repetitive stuff (making the initial window, message handling, for examples).

Another thing that MFC does that I want to avoid is make extensive use of macros. Macros are evil in my book. I’ve been bitten. I know they can be useful in limited circumstances, but MFC accomplishes a lot of its magic with macros. And unfortunately, that’s why it can sometimes be a problem–it becomes magic instead of straightforward code.

Esha

 

We miss our sweet Esha. She has really left a big empty spot in our house and in our hearts. This is how we will remember her; sitting in her favorite place; watching over the front garden.

2 Feb 1996 – 15 May 2006

 

 

Windows Media Player 11

The best media player just got better.

At work, I just downloaded the new version of Windows Media Player 11 in beta. From what little I’ve used it, it’s a HUGE improvement.

One potential thing I slightly miss is that I can’t view albums in the left-hand “browser” and the tracks in the right-hand “content” view. This allowed me to easily move tracks to differently-named albums during editing. But maybe there is a way to do it, or a completely different technique altogether that works just as well.

Also, the readme notes that there are potential problems with IE7 Beta 2, which I have at home. I’ll give it a try anyway and blog my results.

 

Flightplan

We just watched Flightplan on DVD, and I have to say I thought it was a pretty good movie. It was interesting how it made you feel by taking place completely on an airplane (albeit a very large one). There were some weak moments, but all in all it kept me interested.

Programming as a hobby

People are often amazed when I tell them that programming is not just a job–it’s also my hobby. I know that it’s one of the main reasons I was immediately considered for the job I have now. After looking at my cv, my now-manager headed to my web-site and saw that I had done a number of personal projects.

It’s the whole reason I think I have excelled beyond everything I’ve learned in school in the last few years. It’s one of the reasons I’m learning so much practical knowledge. Working on my own projects lets me do fun things at my own pace (I still try to apply some pressure to get things done). I always try to do things I’ve never done before.

I learned a TON making BRayTracer–about program organization, unit testing, optimization, user interface design, architectural levels, and a whole lot about .Net. There are still so many things I want to add to it so I can learn more.

It’s not something you can do just in an attempt to prove to future employers that you’re hard-core. You have to love it. There are a lot of other fun things in life. I just happen to love writing code, and I try to spend a lot of time outside work doing just that.

All other things being equal, somebody who programs as a hobby will be a better programmer than one just in it for a job.

Finding time is always difficult, though. Work is stressful, and sometimes you need to get off the computer. Still, I’ve got some cool utilities planned, a pocket pc game, and who knows. I’m keeping track of ideas, and I’ll just have to start small and work on one at a time.

What’s Wrong with this code? – 2 – Answer

In the last post, I showed some code that had a very simple problem.

The problem is that when you call HIWORD, it converts the 16 bits into an unsigned short, which then gets passed as an int padded with zeros–not sign extended (it’s not signed). It will NEVER be less than zero. The solution is to cast it to a signed short before calling the function or change the function parameters to be signed short instead of int.

Â