• Struggling with graphics

    One area of writing code that I've never been good at is graphics. I partially attribute this to my lack of artistic ability, but also my distaste for advanced math. For the last day, I've been working on a problem to rotate some buttons and move the buttons at the same time. Rotating the buttons is easy:

    self.myButton.transform = CGAffineTransformRotate(flashTransform, degrees * M_PI/180);
    

    Moving the button turned out to be hard for me. I tried all kinds of translations and transforms, but came up with nothing. The transforms are matrix math and that just makes me want to turn the other way and run. I searched and searched, tried different things, stayed up late and still couldn't solve it. This morning I was chatting with a colleague and he suggested just to do the rotation which I knew how to do and then move the buttons. OK, that seemed simple and I know I had tried it. Turns out you can't move a view using the frame property if there is a non-identity transform on it; however, you can set the center which is just as good, but requires a small extra step. You have to convert the origin point you want to the center.

    CGPoint center;
    center.x = newOrigin.x + self.button.bounds.size.width / 2;
    center.y = newOrigin.y + self.button.bounds.size.height / 2;
    

    Definitely not hard to do, but it tripped me up. The other thing that tripped me up is that in order to resize the button, you have to use the bounds and not the frame if a transform is applied. So with those 2 hints, I was able to finish my task in about 15 minutes. Hopefully next time I won't be so thick header about this.

  • What is "work product"?

    Up until fairly recently, my job was mostly writing code and it was quite easy to measure how I did each day by how much code I wrote. On days that I didn't write much code, I didn't think I was all that productive. Work product was simple to define; it was the code that I produced and the applications I wrote.

    This past spring, my role at work (and possibly my career route) has changed such that writing code is now only a small part of what I do. I'm now overseeing some projects, designing how things work, and provide guidance to other developers about the projects I oversee. I can no longer measure a successful day on how much code I write as some days I don't write any code (or even documentation)! This is a huge change for me and is making me come up for a new definition of "work product". My success is now basically measured on the success of others; if I help other projects succeed, then I can be considered successful as well. However, that still doesn't help me with my definition. What is my daily "output"?

    While code is not tangible, there is at least a clear definition. My "work product" is now thoughts and conversations; that's a pretty big change that is going to take some time for me to become comfortable with it.

  • Interview technique - crash logs

    I periodically have to interview people and I find that I struggle to come up with ways to adequately determine a candidate's technical knowledge. While they can present their resume and what they've done in the past, it is hard to tell how they really think. I don't ask questions that I couldn't answer myself as I don't think that is fair. Many people ask basic computer science questions that I'd probably get wrong as I don't have a computer science background; so I tend to ask questions to see how a candidate would handle a situation.

    So far I've had mixed results in weeding out the good from the bad. One skill that I think is of utmost important for a developer is debugging. You might be saying that all developers do that, but some are far better at it than others. Debugging is one of my best skills and I've had a ton of experience at it inheriting other people's projects. With that in mind, I came up with one technical test that could actually tell me if a candidate could debug and that skill goes a long way in development.

    Now you ask, what is the question? The other day as I was poking through crash logs, a few stood out at me. Take a look at the following logs and see if you can spot why the apps crashed:

    Thread 0 name:  Dispatch queue: com.apple.main-thread
    Thread 0:
    0   libsystem_kernel.dylib            0x35cab054 semaphore_wait_trap + 8
    1   libdispatch.dylib                 0x342961c0 _dispatch_semaphore_wait_slow + 184
    2   libdispatch.dylib                 0x342961f4 dispatch_semaphore_wait$VARIANT$mp + 32
    3   libxpc.dylib                      0x3200e89a xpc_connection_send_message_with_reply_sync + 206
    4   SystemConfiguration               0x374f5be6 _reach_server_target_status + 938
    5   SystemConfiguration               0x374f6d56 __SCNetworkReachabilityServer_targetStatus + 14
    6   SystemConfiguration               0x374dfaee __SCNetworkReachabilityGetFlags + 198
    7   SystemConfiguration               0x374e0f7a SCNetworkReachabilityGetFlags + 190
    8   MSNBC                             0x000cb9ec 0x1000 + 829932
    9   MSNBC                             0x0006f998 0x1000 + 453016
    10  MSNBC                             0x0006abfa 0x1000 + 433146
    11  MSNBC                             0x00014d54 0x1000 + 81236
    12  MSNBC                             0x0006ab6e 0x1000 + 433006
    
    Last Exception Backtrace:
    0   CoreFoundation                    0x3567188f __exceptionPreprocess + 163
    1   libobjc.A.dylib                   0x37a18259 objc_exception_throw + 33
    2   CoreFoundation                    0x356713b3 __NSFastEnumerationMutationHandler + 163
    3   EmSea                             0x001f9c2b 0xe2000 + 1145899
    4   EmSea                             0x00199bed 0xe2000 + 752621
    5   EmSea                             0x00223453 0xe2000 + 1315923
    6   EmSea                             0x002239c9 0xe2000 + 1317321
    7   Foundation                        0x351b6c29 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke_0 + 17
    8   Foundation                        0x3510e6d9 -[NSURLConnectionInternalConnection invokeForDelegate:] + 29
    9   Foundation                        0x3510e6a3 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 199
    10  Foundation                        0x3510e5c5 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 61
    

    On the first one, the hint is that the app failed to launch in time. I'm going to use these crash logs as a test to see if a candidate can tell me what went wrong. Neither app is mine and while I can't see the code, I can immediately spot the problems.

    In the first crash log, the app calls SCNetworkReachabilityGetFlags on the main thread. This call is a blocking call which means it won't return until it is done; this call can take a significant amount of time to return and should never be called on the main thread, especially at app startup.

    In the second crash log, it isn't as obvious. What the developer has done is something like:

    for (NSString *string in someMutableArray)
    {
        if ([string isEqualToString:@"Yuck"])
        {
            [someMutableArray removeObject:string];
        }
    }
    

    The array is getting modified while it is being enumerated. The fix is pretty simple.

    NSMutableArray *deleteArray = [NSMutableArray array];
    for (NSString *string in someMutableArray)
    {
        if ([string isEqualToString:@"Yuck"])
        {
            [deleteArray addObject:string];
        }
    }
  • Review: LaCrosse Technology Wireless Weather Station

    Everyday my son comes in first thing and asks "what is the weather going to be?". He wants to know so that he can pick his clothes. Granted, we live in San Diego, so the weather doesn't change drastically one day to the next, but I always answer him. We were in Costco several weeks ago and I saw an inexpensive weather station, so I picked it up and decided to give it a try.

    I setup it up and put it on my desk. The temperature for both indoor and outdoor seemed accurate enough, but the forecast was pretty far off. The box said that the forecast was 70-75% accurate based on the relative humidity. That may be true in other places, but we live about a mile from Mission Bay and tend to have some moisture in the air at least in the mornings. The station said about half the time that it was going to rain. It hasn't rained in months, so either it knew something I didn't or it was useless.

    After a week or so of getting annoyed at it because it had rain clouds on the display when it was perfectly sunny out, I took it back to Costco. I love the concept of a weather station, but I think the next one I look for will only give me readings and not try to predict. I investigated some Internet connected ones, but the reviews were pretty bad, so I haven't done anything.

    Pros

    • Nice display.
    • Works as an alarm clock.
    • USB charging port on back.
    • Displays indoor and outdoor temperatures.
    • Easy to setup.

    Cons

    • Forecast is completely inaccurate.

    Summary

    Don't waste your money on this; I think the cheap weather stations do a terrible job predicting weather at least here in San Diego. If you want the readings for the weather, get a device that lacks the forecasting feature as it is just annoying because it is so inaccurate.