Tuesday, October 19, 2010

Objective-C, you crazy.

I defined a class similar to this

@interface ProgressiveOperation : NSOperation{
ProgressiveOperationStatus operationStatus;
}

//some methods, etc
@end


it's just a handy little asynchronous operation to plug into the NSOperationQueue. It expects a delegate of a certain protocol to notify the UI that stuff is happening. It seems to work nice. Here's an example of a class that extends it for some trackable asynchronous functionality.


@interface WebRequestWrapper : ProgressiveOperation{

}

@property(readonly, getter=responseBufferType) WebRequestResponseBufferType responseBufferType;
//some methods, etc
@end


There's a lot more to this class, but it runs an NSURLConnection, updates progress as data comes in, and other nice things. One piece of functionality surrounds that mysterious property. WebRequestResponseBufferType is an enum that defines either file or memory. You see, i have a need to stream the response data directly to a file when my app receives lengthy ammounts of data from the server. This request wrapper can either save the response data to a memory buffer (as recommended by apple) or directly to a file. If you are curious, in the connection: didReceiveData: method, i write the data directly to an NSFileHandle instance. It's very fast and minimizes memory impact. I'm not really sure why Apple doesn't want you to do this as IOS devices are generally memory starved and I find this useful. That's another topic though.

I further extend this class to provide wrappers for specific urls that my app requests. some of these are small requests that go to memory, some are large data updates that go to a file. Because the getter is not synthesized, an subclass can just implement the getter to return the value that makes sense for it. I felt that the memory buffer model should be the default, so my implementation for WebRequestWrapper looked something like this.


@implementation WebRequestWrapper

@synthesize responseBufferType;

-(WebRequestResponseBufferType) responseBufferType{
return WEbRequestResponseBufferTypeMemory;
}

//methods and stuff
@end



Now, if you are an obj-c programmer, I'm sure you see what I did wrong. There's no need to synthesize a readonly property with a user supplied getter. Let me assure you, there is a fair bit more code in this class that masks this. Also my use of the user supplied getter was added after the class had worked with a member variable that was sometimes fiddled with by subclasses. Maybe it's the .NET speaking, but I rather like the pattern of defining an abstract property to provide these kind of configuration values to superclasses.

What happened when I tried to compile this code is where things got really weird. I expect it was generating 2 identical responseBufferType signatures in the class, but the compilation error I received said that operationStatus didn't exist. WTF? it didn't tell me that any other member from the superclass was missing. It didn't complain about a redefinition of the method. The compiler appears to have cherry picked a member at random and said it didn't exist.

This was harder to figure out than the time i wrote

#define NumTableSections 2;

Thursday, October 14, 2010

Why isn't 3D TV "worth it"?

It turns out 3D tvs are not selling very well. This isn't really a surprise to anyone since nobody wants one. If you ask people why they don't want a 3D tv they will give some general excuses about how it's just not worth it. It's the reason why it's not worth it that i find interesting.

People liked HD. People looked at HD content and saw that it was better. Our eyes are higher resolution than a tv screen (probably even higher than a retina screen depending on the individual) and a higher resolution image appeals imediately to us. People also like the wider aspect ratio. Humans have a field of view that is wider than it is tall. A widescreen display fills more of our field of view with what we are interested in.

People also have depth perception. We live in a three dimensional world. We should see 3D as another step closer to reproducing a vivid immersive experience. Obviously, people don't think it's a step worth thousands of dollars. I don't think it's just the economy though. I think there is a deep rooted reason why 3D just isn't that compelling.

Our brains are very good at extrapolating depth information from a 2D image. When we watch TV, we don't need to analyze the image to determine the spatial relation between everything in the scene. We know Knight Rider is driving right at us. We know Don Draper is standing right next to his secretary. We get 99.9% of the information in a scene from a 2D image. The third dimension adds so little extra information that it's not worth having.

I think our brains don't even like consuming 3D content. Technically, they don't. Our retinas are essentially 2D. They are spheroid in shape, but covered with a 2D array of sensors. Essentially our brains recieve a 2D image from each eye. We rapidly compare differences in the images and deduce depth information from it, or do we?

It's actually really easy to fool our depth perception. A room with one end slightly wider than the other will appear longer or shorther than it actually is. In an Ames room, it's often impossible for us to tell what's going on. If our brain comparing 2 images was all that gave us depth perception, we wouldn't be tricked. Someone at the other end would generate the same delta in the two images as someone standing 20 feet from you. it would require the same focal length as someone standing 20 feet from you, but your brain will tell you that they are a tiny person standing 10 feet from you. The trick works because lines you expect to be parallel are not. Data from the 2D projection of the scene overrules the 3D information.

It's just as easy to trick your brain into thinking it's seeing 3D content when looking at a 2D plane. Essentially TV does this all the time, but certain works really take advantage of our brain's extrapolation of depth. Again, the information coming from two eyes should overrule the illusion, but it's almost impossible to not be fooled. Most people have to concentrate to see a flat image.

Under certain situations people find it advantageous to force a 2D view of the world. Weapons are far easier to aim with one eye. landmarks are easier to line up when surveying. If you close one eye and try to walk around the room chances are you will be more bothered by the loss in your field of view than a lack of depth perception. In fact, the only time i ever hear people complain about not having depth perception (i have friends with bad astigmatism) is in regards to 3D movies and how they can't see the effect.

So how much of this is learned and how much of this is instinctual? In school, some of my teachers would recant stories of people in primitive cultures being unable to make sense of photographs and drawings because they never learned to see in 2D. That would point to our preference for 2D television being more a learned behavior than an inborn view of the world. Those stories are at odds with some other evidence though. There are numerous conflicting anecdotes of primitive people fearing a camera stole part of the subject's soul. Clearly those people recognized what the photograph was.

We know people represented the world in 2D long before there was television. Cave paintings are good evidence that people who never watched tv could work out how to project items onto a 2D plane. People have made paintings for a long long time. Prior to the advent of vanishing points and a mathematical understanding of perspective, painters made crude attempts at reproducing it. They seemed to understand that it was possible to represent the depth of a scene in a 2D plane. The instinct was there if the technique was not.

Maps are another very interesting 2D projection. People find them easier to use because they discard a useless third dimension. Even in 3D video games, players are often provided a 2D map to navigate by. It's almost like it's easier to consume the 2D content.

I really think our brains are wired to store and recall the world in 2D. How many of our memories can we zoom around in and reconstruct the scene from any angle? It's REALLY hard. I think 2D content on tv is more than just convenient. I think it appeals to our brain as it comes in the tasty form of instant memory. It's like a window into the world the way our brain likes to think of it.

Of course maybe we just like 2D content because we grow up watching TV. I don't really know. It sounds like the people making 3D TV's should be asking if 3D content can ever really be compelling.

Tuesday, October 12, 2010

Foursquare Saves The Day

I have never been what would be considered a strong supporter of social media. I regularly denounce facebook. My blog has a pathetic number of posts. I was slow to take up twitter. Even my ICQ number is 7 digits. Yet social media continues to drag me kicking and screaming into it's embrace.

It's not that i'm a naysayer or a doubter. I believe that communicating with people is a powerful tool. It's just that I am a cynic and a skeptic. When someone says, "You have to try this new way of talking to people by only using 140 characters! It will change your life forever!", I am skeptical.

Because people I respect are telling me this, I have developed a social networking attack plan. When enough of my peers are urging me to try some new social network, I will sign up and resolve to give it at least 2 weeks of regular usage. In the case of Twitter, I found a lot of value. After a couple weeks, I made new contacts. I discovered people with my interests, and i found a way to get information from people who i was interested in.

It was with that strategy that i approached Foursquare. After a couple weeks my feelings were as follows:

  • Foursquare is painful to use. The gps accuracy was spotty, it seemed slow.
  • It forces me through needless clicks. why do i have to click check in, then check in again?
  • It's too chaotic. The same place may be entered more than once.
  • People seemed to resent foursquare messages on twitter so i didn't connect it. It didn't feel social.
  • When i did have fun with it (adding a bathroom in our building and competing for mayor of it) people would delete the place.


After my 2 weeks, I felt secure in declaring Foursquare stupid. Then, something happened. I checked in at a local bar and found out i could get a free beer for my first checkin. Suddenly Foursquare looked different. Regardless of accuracy or if the system could or could not be gamed, I could get a free beer. Maybe I'm not going to make Foursquare friends or feel like i'm part of a community, but a free beer is a pretty tangible benefit.

I decided to stick with it. I gained a couple mayorships. I aquired some coveted badges. I earned my swarm badge naturally. I didn't have to attend some geeky nerd party where everyone agreed to check-in for the expressed purpose of getting a swarm badge (ok, I got the swarm badge at the Game Developers Conference. It's probably the ultimate nerd party). Yet I still felt like Foursquare was a pointless exercise.

After months, I hadn't gotten any more free beer, and I still didn't feel like Foursquare was doing anything for me. Facebook places came into existence and has, for me at least, seemed faster, more accurate, more social, and more streamlined than Foursquare. I can't even believe that I am praising a facebook feature as more streamlined than something else, but there you have it. I view that as even more evidence that Foursquare just isn't cutting it for me.

My wife called to alert me to some suspicious charges on one of our cards. We have experienced credit card theft in the past. It's hard to describe the agonizing sinking feeling you get when you see your money diverted for mysterious and nefarious purposes. The charge in question was for $38.70 at Popeye's. I don't even like Popeye's. It seems like it might be hard to buy $40 of food at Popeye's. The thought that some glutton was running around clogging their arteries on our dime was even more sickening.

We all know that it's important to keep good financial records. In fact, because of our credit card theft experiences in the past we REALLY feel it's important to keep reciepts and records of all our transactions. HA! That lasted a couple months before we realized that it's just not practical. If you can keep all that information handy, good for you. I can't. My wife can't either and she's WAY more organized than I am.

At this point, we are pretty certain that we didn't spend $40 at Popeye's, but there is a tiny nagging doubt in the back of my head. Before we call the credit card company and dispute the charges and cancel our cards, I want to quell that doubt. I think that if I knew what I was doing around the day the charge was placed, maybe it will jog my memory and I'll recall something that will prove I couldn't possibly have been to Popeye's, and i will feel confident in disputing the charge.

It occurred to me to check Foursquare. I bring it up on my iPhone. I start scrolling down the list and lo and behold! I checked in at Popeye's!

For a second, I imagine an incredibly sophisticated criminal who can steal my credit card, and check me in on Foursquare. This is the first thing that pops into my head. It's possible my friends are right when they say I think like a criminal. However I see that Popeye's is NOT Popeye's famous fried chicken, but a nautically themed restaurant on the picturesque shores of Lake Geneva, WI. I recall that my wife and I DID enjoy a nice, but pricey $40 lunch there.

Foursquare actually provided a beneficial service to me. It wasn't social, but it was useful. Facebook, while easier to check in on, doesn't provide a nice list of check-ins. at least the Facebook iphone app doesn't provide that. And Facebook is notoriously abysmal at providing historical data. Foursquare had a nice list. Thankfully it looks like the two are integrating and maybe in the future I can enjoy the convenience of the Facebook checkin with the organized reporting of the Foursquare history list. All that and I can feel like pulling out my iPhone at dinner is just being responsible with my financial records!

Foursquare, you've proven yourself to me once again. I'll continue to use you (for now).

If you work on a crime show or movie and would like to hire me as a consultant about how criminals could mask their tracks through Foursquare, I think I have some good ideas.