Planet Cocoa

September 02, 2010

waffle

iTunes 10 Notes

  • Slimmer.
  • The column headers bear a startling resemblance to those really old bevel buttons from the early days of Mac OS X, or for current applications where the developer has something against push buttons.
  • I’m not sure I like the “all greyscale, all the time” icons. Sure, the icons are simpler, but some of them are still small, and the color was a better cue.
  • The Now Playing window does the QuickTime X thing. Borderless, floating controls.
  • It looks like the balance of power continues tipping. Info.plist now enlists an NSPrincipalClass, ITNSApplication, meaning that it uses the Cocoa startup path. (Very curiously, I can’t find that class by dumping iTunes.) Still chock full of Carbon, but it seems they’re going to do this over several versions.
  • Every time someone uses the phrase “Join the conversation” to coax someone else into joining a “social network”, a marketing executing gets a boner, poking out the eye of the nearest adorable animal. I suppose when they introduced Ping by showcasing Lady Gaga, I shouldn’t have kept thinking they could actually do it better or differently than everyone else.
  • The buttons in the bottom bar should look a bit more like buttons. It’s okay for the ones that are binary indicators to look like that, and that makes one of them (shuffle has three states); three if you’d also so enhance the buttons to slide out the artwork square and the Genius sidebar.
  • Flattening artwork view (show stuff as you have the space, not just “always”) is something they should have done from the beginning.
  • I know what the handle on the volume slider is trying to pull off (a brushed metal button) but it uses just the wrong grey tones so it looks like some sort of dusty baseball instead.
  • The source list feels choppier to scroll than the track table itself.
  • The display up top now fits both the artist and album onto the second row if there’s roomalways instead of having them alternate: iTunes LCD showing artist and album on the same row
  • Things like iOS updates are now asynchronous, which is to say non-modal. The progress shows up in the display up top instead of in these infernal modal dialog boxes. (Peter Hosey, friend of the waffle, shows that sanity spreads slowly by confirming that the “rebuffering stream” box is still modal.)
  • You can no longer change the zoom level while playing video inside the iTunes window. It’s “scale to fill the window proportionally” or bust. I suppose the separate/”now playing” window’s new look is supposed to be enticing enough.

by Jesper at September 02, 2010 09:19 PM

September 01, 2010

waffle

New Song

“This is a new song that we’re working on called Coldplay 2.6. This has a lot of features, it features seven different kinds of chord, including a new one that even our closest rivals have no idea about, which Jonathan Ive’s designed. It’s the chord of “i-minor”.” — Chris Martin

by Jesper at September 01, 2010 07:17 PM

September First Live-Claiming

I will be “live-claiming” my claim chowder during the event. Check back for updates.

  • 128 GB iPod touch. ✘
  • Goodbye, iPod classic. (See above.) ✘
  • Wi-Fi syncing. ✘
  • Nice knowing you, iPod shuffle. ✘

by Jesper at September 01, 2010 06:48 PM

Live Streaming Impressions

It’s better than the old QuickTime streaming. It cut out surprisingly few times. But those are the kindest things I can say about it.

  • Sometimes, the previous segment would repeat.
  • Sometimes, it would shift up or down in quality and also skip back or forward. (Skipping back was worse because it pretty much guaranteed that you’d skip forward sometime soon and miss about twenty seconds.)
  • Sometimes, the whole image would flicker about 1Hz. A few times this would cut out on its own after a sufficiently long wait, but you had to reload the page, and the video would inevitably sync up with the freshest stream playlist, which means that if you were behind, you would without mercy skip the delta.
  • If you had a sufficiently low quality stream, you couldn’t go into full screen. You could go into full screen on a good quality stream, drop to low quality, exit full screen to check on something and then be unable to go into full screen until you caught a good quality headwind again.

So it is better, and I hope they continue doing it, but it’s not good. The errors pretty much all seem endemic to the technology and could hardly be fixed as such by providing more, faster and better servers, but if they did that and it held up, most errors wouldn’t be triggered to begin with.

It’s possible that at Apple’s scale, nothing works acceptably. But they made a bet on using what they had including the server farm side of the equation, and they’re going to have to live with the consequences.

by Jesper at September 01, 2010 06:36 PM

Oh Darn

Paul’s angry:

If you’re among the majority of Apple’s customers–that is, you own a Windows-based PC and at least one of the company’s iOS-based devices or iPods–you’re out of luck if you want to see today’s Apple music event live. To do that from a PC-type desktop, you need to use a Mac. (Apple is also streaming its event to iOS-based devices if you don’t mind the small screen and performance issues.) Why shut out the PC? Because they’re Apple, that’s why.

I’m sure he was real angry with every single company that used their own video format or streaming for the past 15 years too.

I mean, it’s not like a third party or an individual developer could cobble together an implementation of HTTP streaming from a few pages of published specifications, or as if they used a video format that was already common and implemented (while not open and free in every sense of those words). And far be it from Apple to use an approach that so stands on the shoulders of existing standards that you could actually kinda sorta still see it.

We can only hope that they will aspire to the bettered heights of Microsoft, which has on its latest attempt on streaming video managed to get it down to the design and upkeep of a CLR several years prior and direct access to the developers of the original technology for a useful alternative implementation. Which, I must admit, is an improvement on “tough titty, we license this shit”.

by Jesper at September 01, 2010 04:47 PM

Apple to Actually Live Stream September First Event

What the… Is it 2004 again? About fucking time. I could never forget them for giving up on it the last time around.

HTTP Live Streaming is in a way very symbolic of the way large sites scale, and of the line of new tools available for web development. QuickTime streaming depended on persistent connections and being fed data. I think eventually they just ran out of servers to serve their audience. HTTP Live Streaming is just about delivering and fetching files at a fast clip (every nth second). There are some very fast servers to do that (the web constantly revolves around this working already) and it requires much less involvement, or should I say entanglement, for the server. It’s up to the client to sort out the “session” or “state”, and the server is just a source of data. Rather that than having a tap where the server can’t skip streaming data and the client can’t skip receiving data.

The RFC has all the intimate details.

by Jesper at September 01, 2010 06:41 AM

August 31, 2010

Red Sweater Blog

Fall Conferences

After the announcement earlier this year that C4 was cancelled, I had a hard time getting too excited about conferences. My feelings about Apple’s WWDC are ambivalent: it’s an impressive production and a great opportunity to meet up with dozens or hundreds of colleagues, but it’s expensive and simply lacks the heart of smaller conferences. I go to WWDC every year with some amount of excitement, but mostly as a point of professional obligation. Attending smaller get-togethers like C4, on the other hand, is pure indulgence.

While I don’t think C4 can be replaced, there are other conferences of a similar scale that can help to fill the void. This Fall offers a full calendar of options for folks who are looking for an opportunity to socialize with peers and learn a few new tricks of the trade:

VTM iPhone Developer’s Conference: October 16-17, Philadelphia, PA.
Voices That Matter has been on a run with iPhone-targeted conferences, putting on a show every 6 months or so at different locations around the country. I spoke at the Boston event a year or so ago, and had a great time.

I am attending the Philadelphia event as a speaker alumni guest, and they have also passed along a discount code to share with you: PHBLOGS. If you use this code before September 10th, it combines with early bird pricing for a total savings of $300.

MacTech Conference: November 3-5, Los Angeles, CA.
For all you hardcore Mac and IT nerds who have had enough of the iPhone-only conferences, this is the place for you. This is the inaugural event and seems to have come at least in part as a reaction to Apple’s substantial omission of Mac and IT content from the WWDC event this year.

I’m speaking at this conference and although I won’t say exactly what my topic is, it just might set me up for a world class showdown with my illustrious friend Wil Shipley, who is also scheduled to appear.

360 iDev: November 7-10, Austin, TX.
Hot on the heels of MacTech, 360 iDev is another iPhone-oriented conference that has been skipping around the country. The Austin, TX location is a big draw for me, but I think with so much other activity and the speaking gig just prior in Los Angeles, I will have to sit this one out.

Apple Developer Tech Talks: November-December? Worldwide.
If you haven’t been lucky enough to live near enough and apply quickly enough for these stellar events, you’ve missed out. For the past several years Apple has sent some of its best communicators to put on what amounts to a micro-WWDC: a day of intensive sessions on the latest and greatest Apple technologies.

I attended last year’s New York event and wrote up the experience for TUAW. Assuming Apple puts this tour on again this year, and I’m eligible to attend, I’ll be scampering to sign up. You should, too!

What else is going on in the Apple-sphere this Fall? If I am overlooking something big, please share with us in the comments below. I’ll update the post later with a more “definitive” list of options to choose from.

by Daniel Jalkut at August 31, 2010 10:35 PM

August 30, 2010

Cocoa With Love

Alternative Objective-C object allocation for large arrays

In this post, I'll show you how you can create objects without using the standard instance allocation process (either +[NSObject alloc] or class_createInstance()). I'll also explain why you might do this — the benefits and drawbacks to a custom object creation process.

Introduction to object allocation

The first point to understand when looking at Objective-C object allocation is what is an Objective-C object?

The answer is pretty simple: any block of data that starts with an Objective-C Class pointer can be treated as an Objective-C object. This pointer is normally called the isa pointer and allows the block of memory to be used in the Objective-C message sending system.

Normally, Objective-C objects are individually allocated on the malloc heap using malloc_zone_calloc from within the +[NSObject alloc] or class_createInstance() implementation. These allocation approaches automatically set the isa pointer for the object once it is allocated.

Alternative object allocation

Since any block of memory that starts with an isa pointer can be treated as an object, then there are numerous ways you could actually allocate objects. I'm going to consider just one alternative approach: malloc'ing a single large block of data, treating this single block as a C array of Objective-C objects and manually setting the isa pointer at the start of each of these objects.

The approach is fairly simple. Step one, allocate the C array (using calloc to obey Objective-C conventions):

const NSInteger arrayLength = /* some array length */;
Class someClass = [SomeClass class];
NSInteger runtimeInstanceSize = class_getInstanceSize(someClass);
char *instanceArray = calloc(
    runtimeInstanceSize,
    arrayLength);

Notice that we use the runtime size of the instance, not a compile-time value. This is because the instance size may change if a superclass adds extra instance variables at runtime (see my previous post on Dynamic Ivars). If your class doesn't have a superclass or you're otherwise cavalier enough to ignore this possibility, then you could use a fixed or compile-time size value.

Once the block is allocated, we need to set all the isa pointers:

for (NSInteger instanceIndex = 0; instanceIndex  arrayLength; instanceIndex++)
{
    Class *currentInstanceIsa =
        (Class *)(instanceArray + (runtimeInstanceSize * instanceIndex));
    *currentInstanceIsa = someClass;
}

Then if desired, you can invoke the init method or otherwise initialize each object some other way.

Reasons for using alternative allocation approaches

The reason to avoid standard allocation is generally because malloc_zone_calloc does not offer the memory efficiency or performance required.

I've previously examined how malloc works on the Mac. This post briefly looked at two of the limitations with malloc:

  • malloc allocations have an "allocation resolution" (objects not a multiple of the resolution will result in wasted space)
  • malloc must maintain metadata on allocated objects and this imposes an additional memory overhead

The biggest malloc limitation however is simply the fact that it imposes a per-object CPU overhead on allocations.

Finally, there is one other advantage associated with using alternative allocation approaches: it is lower level. This is not an advantage in all situations — low level implementations can be fussy and prone to errors. But low-level C implementations can be easier to join with other low-level C implementations, so if much of your program is already a low-level C implementation, it may end up being an advantage to have low-level access to your object's allocation.

Drawbacks to alternative object allocation

Alternative object allocation should not be used lightly. First of all: it is simply more work as a programmer, so you need to be sure it's work the effort.

But the biggest problem it creates is the fact that individual objects cannot be retained beyond lifetime of the larger block in which they're allocated. To address this, you must either

  • Give the containing block a global lifetime (never released) like a singleton or other permanent instance
  • Carefully manage all retains and releases to ensure that no object is retained beyond the containing block's lifetime
  • Make retains illegal (use a retain implementation that throws an exception).

This limitation can be justified but only if the efficiency benefits are significant. On the iPhone, you may be able to justify it for a few 10s of thousands but on the Mac, your block should contain hundreds of thousands before you'd bother.

An example: loading the "/usr/share/dict/words" file

To illustrate how you can use alternative allocation, I'm going to show a traditional Objective-C approach for reading, parsing and storing the contents of the "/usr/share/dict/words" file as an array of NSStrings. I will compare the time taken and memory used by this approach with an approach that uses the alternate allocation approach.

The traditional Objective-C approach:

words = [[NSString
        stringWithContentsOfFile:@"/usr/share/dict/words"
        encoding:NSASCIIStringEncoding
        error:NULL]
    arrayBySeparatingIntoParagraphs];

where arrayBySeparatingIntoParagraphs is an NSString category method that uses getParagraphStart:end:contentsEnd:forRange: to divide the NSString into lines.

The alternative approach uses a custom NSString class, allocated as described in the "Alternative object allocation" section above. This NSString stores a fixed length 24 character ASCII character string (24 characters is the maximum length of a line in the words file). The string storage is not actually a C string; if the stored string is 24 characters long, it isn't null terminated.

@interface CustomAsciiString : NSString
{
    char value[CUSTOM_ASCII_STRING_LENGTH];
}
@end

The allocation itself happens in the init method of a custom NSArray subclass.

@interface CustomAsciiStringArray : NSArray
{
    NSInteger count;
    char *stringArray;
}
@end

This custom array subclass is used to provide NSArray-compatible access to the C array of CustomAsciiString.

The array of CustomAsciiString is actually referenced here as a char* because at compile time we don't presume to know the allocated size of the CustomAsciiString so we'll need to offset into the array by bytes (i.e. chars).

The code for all of this is too big to include here but you can download the CustomObjectCreation.zip for the complete code.

Results

There are 234936 words in the dictionary with a maximum length of 24 characters and an average length of 9.6 characters.

The "traditional" Objective-C approach took 3.12 seconds to load, parse and store the file in the string array 20 times. Memory usage after the final iteration (all other iterations were released) was 16.5 MB.

The "alternative allocation" approach took 0.49 seconds to load, parse and store the file in the string array 20 times. Memory usage after the final iteration was 8MB.

Final result: 6 times faster using half the memory.

Potential issues with the methodology behind these numbers

Based on these numbers, the "alternative allocation" would appear to be more than 6 times faster and more than twice as memory efficient.

This isn't an "apples to apples" comparison though.

The "alternative allocation" approach is storing ASCII strings (which are half the size, character-for-character compared to typical unichar NSStrings). However, this is largely compensated by the fact that every one of the ASCII strings is 24 characters long — significantly more than twice the average length of the strings, so the useful memory allocated here is actually greater. Even if you double the ASCII string length to 48 characters, the memory usage is only 13.4MB — still 20% less than the traditional allocation approach. The "alternative allocation" approach is also allocating a fixed 250000 entry array (even though only 234936 are used).

The parsing used by each approach is radically different. However, this is related to my earlier statement that lower-level allocation lends itself to integration with lower-level parsing and handling. I have not attempted to make the parsing more comparable between the two approaches because I believe the different parsing approaches are correctly matched to the different allocation approaches.

The biggest problem that I would have liked to address better — but I don't really know how I would — is that simply reading memory usage from getrusage is not a highly precise way of determining memory used by the test. The getrusage results count allocated memory pages whether they're truly in use or not. It also can't separate memory that may have been allocated by the runtime for different purposes. Due to the difficulty of measuring memory, I've had to assume that getrusage is sufficient but there is certainly a margin for error in the numbers.

Conclusion

You can download the CustomObjectCreation.zip (20kB) which contains all the code used in the test project for this post.

For very large arrays of Objective-C objects, it is certainly more efficient to allocate them yourself within C-style arrays. It is faster (on the order of 6 times faster) and more memory efficient (between 20% and 60% lower memory usage).

However, it is not something you should do for all arrays. There's a lot of extra code — any part of which could introduce issues — and it introduces object-lifetime issues but for very large arrays, the advantages (especially in CPU or memory constraint scenarios) could be worth the effort.

by Matt Gallagher (noreply@blogger.com) at August 30, 2010 06:49 AM

August 29, 2010

waffle

Why TV

I just made a few bets on what will be announced at Apple’s September 1st iPod event. Curiously absent was any mention of “iTV”/Apple TV take four billonth, because I find no such joy in predicting its future.

Steve Jobs made it clear, as we all knew in our hearts, that the TV-related infrastructure is the worst clusterfuck you could wish for in terms of providing a coherent experience, and that there was no way around it short of demolishing everything and starting over.

This will eventually happen. There will be no such thing as channels, or prime time, or programming blocks; no such thing as physical disks hosting DRM and insufferable unskippables; no such thing as a stack of devices, some of which exist as standalone products to enable an architecture where you can pick your level of quality and ambition, but most of who cover up the lack of expertise and customer respect inherent in most consumer electronics companies; no such thing as seven remotes, six HDMI ports, five different sorts of audio outlets, four dozen cables running back and forth across your wall, three standards of digital television reception to choose from, two different boxes for viewing and recording different programs and one confused user in the middle of it.

The TV market is fucked up at every level. The TV itself doesn’t work, the standards are wild and varying, the extra boxes you need don’t even talk to each other, the networks sell your eyes for change to advertisers and that’s only the consumer end of it. Paving over it means starting from the shows and figuring out what can be added to them. If you could pick TV shows a la carte, you could have either no ads for a large fee, few ads for a small fee or the same deluge of ads for free, but the ads would be better targeted. You could tick a box and receive experiments; watch a pilot and tell the producers what you liked about it. You could tick another box and allow for an extra few programs each week that your friends recommend.

It’s not clear to me that Apple is willing to do this, or that they want to do it right now. The alternative is a cheaper version of the Apple TV. Maybe it could get better software, sure. Maybe it could turn into a gaming platform and a new console, okay, even if every cut of A4 to date lacks muscle when compared to the crop of consoles that are currently on the market, and that will be due for replacement in a while. You’re not going to see any substantial improvement in anything that matters about Apple TV unless they start paving. If you’ve already made the bet, great, it’ll get better. If you’ve been waiting for a shift in pricing, great, you’ll be able to afford them. They could sell twice as many and it wouldn’t do a whole lot.

The TV as we know it, along with every single ancillary construct save for shows and the production thereof, is dying out. The writing’s on the wall. There will come a system to throw everything out that needs throwing out, and that will arrange the pieces that are left in such stunning and efficient simplicity that we will wonder how we ever put up with what was there before. But it’s not a “media center” like anything you’ve ever seen, and it sure as hell is not the Apple TV. The Apple TV is to this revolution was the MiniDisc player was to digital music; still playing the same old game in the same old way, strapping inline skates to the horse, and maybe it’ll make a few people a bit happier, but it’s not what the world wants.

by Jesper at August 29, 2010 04:56 PM

Forecasting the First

  • 128 GB iPod touch.
  • Goodbye, iPod classic. (See above.)
  • Wi-Fi syncing.
  • Nice knowing you, iPod shuffle.

by Jesper at August 29, 2010 02:57 PM

August 27, 2010

Clickable Bliss

Philly iPhone Conference

Voices that Matter is holding an iPhone conference here in Philly this coming October. I plan to be in attendance. If you are interested in coming there is a coupon code you can use for an extra $100 off, plus some prize drawing if you register by the end of this month (August).

http://twitter.com/VTM_iphone/status/22273907958

Reg now:Early Bird saves you $200, August reggies in drawing for $100 AppleGiftCards & $100 Twitter discount: PHNTWIT http://bit.ly/VTM_Fall

Should be a fun two days.

Also, if you are just getting started with iOS programming you might want to also attending the Big Nerd Ranch course the day before.

http://www.bignerdranch.com/classes/ios_seminar

I did one of these way back when when I was first starting out in Cocoa (it was the day before a Mac Hack) and it was incredibly helpful.

by Mike Zornek at August 27, 2010 05:19 PM

Dex, a pokémon browser for iPhone now available.

Dex Icon

Last week my first little iPhone app hit the store. It’s a pokémon browser that let’s users:

  • Browse pokémon via the national or regional dexes.
  • View a pokémon’s type including its dynamic defensive type effectiveness.
  • Play pokémon cries.
  • Jump to popular online pokédexes including Bulbapedia, Serebii and Smogon.
  • Browse types to see their attack and defensive effectiveness.

This is a free app that is currently supported via iAds.

Download on the App Store

Visit product page on Clickable Bliss

The next few blog posts will share some thoughts on the whole development process but I thought it would be best to get this blurb out first. If you have some time to check out I’d love to get some feedback.

by Mike Zornek at August 27, 2010 03:50 PM

NSBlog

Friday Q&A 2010-08-27: Defensive Programming in Cocoa

Welcome back to another word-laden edition of Friday Q&A. About a year ago, I wrote a post on defensive programming. That post covered defensive programming in a general sense, and Scott Gould has requested that I write one specific to various standard Cocoa practices, which is what I will be talking about today.
(Read More)

August 27, 2010 03:19 PM

August 24, 2010

Alexandre Gomes

Disabling multitasking on iOS 4 apps

If you’re using the iOS 4 SDK then by default your app will be assumed to support multitasking even though you actually need to add support for it and you might not have done that (e.g. updating an old application). While multitasking seems nice it isn’t always the best scenario for your app, specially when [...]

by alexmipego at August 24, 2010 04:06 PM

PrEV

iOSDevCamp 2010

I will write up the whole weekend but a lot of people wanted to see the demo we did on Sunday so I've made a quick screenshot video showing the two animations that we demo'd on stage at iOSDevCamp.

For those that do not follow me on twitter here is a brief recap. Andrew (my oldest son) and I went to iOSDevCamp last weekend. He won the "Best Upcoming Developer" award for his Unreal Model Viewer iPhone/iPad app, this is a screencast of the demo we gave on Sunday. If you ever have the chance you should make it to one of these, its a ton of fun!

your browser does not support the video tag

by objc at August 24, 2010 04:35 AM

August 22, 2010

waffle

What the iPad is For

Finally, vision: Inkling, iPad textbooks, designed by people who fucking get it.

by Jesper at August 22, 2010 07:05 PM

With Roland Emmerich Attached to Direct

Angry Birds: soon to be a major motion picture.

Someone shoot me. Or preferably, shoot the birds. In fact, shoot the birds at something else, if you believe something positive will come out of that.

by Jesper at August 22, 2010 05:50 PM

August 21, 2010

Jon's Blog

Pixen: Where am I?

Well, it has been almost a year since I posted about my adoption of Pixen. While I haven’t made the progress I had hoped in that time, there is some to report. My current GitHub repository builds on 10.6 only and only with the 32-bit Intel architecture. I’ve gotten the build down to 3 warnings with all of the options I’ve enabled but the clang static analyzer still finds over a hundred issues with the code. There are also several bugs still present that I’ve been trying to narrow down. And, unfortunately, several major parts of Pixen must be rewritten nearly from scratch to build against the 64-bit APIs. Overall, this has turned out to be a much more complicated project that I’d hoped. Pixen consists of over 25,000 lines of custom code, and that doesn’t count 3rd party libraries, of which there are several. There are an assortment of custom classes used throughout the program, including custom UI elements and even the basic image type is custom. Combine this with very little in the way of documentation or comments and my new job, and I just haven’t had the time (or expertise) to delve as far into the code as necessary. So I apologize to anyone hoping for some Pixen progress.

There is still hope however. Pixen: we can rebuild it, we have the technology. Over the coming weeks, time allowing, I’ll be adding a list of several major issues that need to be addressed for Pixen to move into 2010. These will be posted on my GitHub page, so feel free to comment with any suggestions. I always welcome additional insight into the Pixen code. Even if you don’t implement features or fix bugs, pointing me in the right direction so I can try to do so myself would be great. I’ll be focusing on any bugs that pop up (I already have at least one) and the transition to the 64-bit APIs. One of the biggest changes I’d like to see, even if I don’t do much with the foundation of the program, is a refreshed UI. I am not a designer by any stretch of the imagination, so if anyone is interested in submitting UI ideas or artwork, especially the UI icons, I would greatly appreciate it.

Thanks for reading.

by Jon at August 21, 2010 11:43 PM

Ahruman's Webthing

Almost elegant cave man debugging

Recently, the Twitternets pointed me at Vincent Gable’s blog post, The Most Useful Objective-C Code I’ve Ever Written. It is indeed quite useful; given a semi-arbitrary expression, it prints out the value, using @encode() and macros to minimize drudgery.

However, it’s limited to a fixed set of types. As Vincent points out, this could be avoided by parsing the @encode() string rather than recognising specific strings. As it happens, I had a partially working parser. It is now wholly working and added a convenience macro similar to Vicent’s, and you can find it here. It handles most structs, unions and arrays automatically. It’s still not entirely general, though, in part because of compiler limitations:

  • Bitfields aren’t supported. This is basically because I haven’t bothered. I’m not clear on whether the encoding actually provides enough information to handle these properly, though.
  • Altivec and SSE vector types aren’t handled, because @encode() completely ignores them – if you have a struct { int a; __m128 v; int b; }, the encoding is {?=ii}, as if the vector wasn’t even there.
  • Aggregate types with non-standard alignment (#pragma pack) are not supported. Again, the compiler doesn’t encode the necessary information.

The latter two cases could easily lead to crashes if left to their own devices. My solution is to first parse the entire type without reading any data, to ensure that the amount of data the parser will consume matches the size according to sizeof(), then reparse if the size matches.

There are probably cases it doesn’t handle. Bug reports would be welcome. Also, it doesn’t handle PPC-64 and ARM, because I don’t have suitable machines to extract alignment information on and I can’t be bothered to read actual documentation.

Update (2010-08-22): Added support for _Complex types (encoded as 'j'; a complex double is encoded as jd and stored the obvious way, as two doubles in a row).

Update (2010-08-23): Fixed alignment calculations for nested structs when alignment is not determined by first member.

by Jens Ayton at August 21, 2010 07:43 PM

August 20, 2010

Fuel Collective

Where is Swatch 2.0!

It’s on it’s way! But before it gets here, let’s talk about it (behind it’s back!). What has changed? Well, we completely redesigned Swatch to use a more “Mac Like”, cleaner, easier interface. There are now 6 ways to select the color you want, Loupe, CMYK Sliders, Color Wheel, HSB Sliders, RGB Sliders, and manually entering the color.

What else? We have added support for CMYK, new output templates for Mac and CSS3 developers, fixed all the bugs that were in Swatch 1.x and much more. You can now synchronize the Swatch library on the run with your colleagues by saving the library to a network share or Dropbox as well.

We can’t wait to share it with you August 23, 2010 at 12:00 CST.

Love,
Fuel Collective

August 20, 2010 07:26 PM

August 19, 2010

Surfin' Safari

Kenneth Russell is now a WebKit reviewer!

Kenneth is one of the members of the WebGL working group and has been contributing to its implementation in WebKit for over a year. He is beginning to branch out by working on GPU acceleration for more areas in WebKit’s rendering.

Please join me in congratulating Kenneth on his reviewer status!

by David Levin at August 19, 2010 03:19 PM

waffle

Portal 2 Date

February 2011 already? Normally when Valve puts down a year, they intend the last day of quarter, oh, five. Not that I’m complaining.

New trailer. Mind re-blown at 6:37. I’m not so sure I’m going to have much of one left when this game comes out.

by Jesper at August 19, 2010 06:51 AM

August 18, 2010

waffle

Apptitude

According to Wired, Apple VP and head of App Store process Phillip Shoemaker sells his own fart apps, including a pee app, and why wouldn’t he? It’s a perfectly legitimate product. For some reason, he chose to sever the links that made this revelation possible shortly after the Wired piece, which seems a bit more odd. Apple PR issued a statement, which I will attempt to de-PR-speak in situ.

Phillip’s apps were written, submitted and approved before he became an Apple employee.

At Apple, we don’t pee on our hands.

His experience and perspective as a developer is one of the valuable things he brings to Apple’s developer relations team.

Yeah, Phil’s our token fart guy.

Apple’s policy allows for employees to have apps on the App Store if they’re developed and published prior to their start at Apple.

Our platform is so open and our approval process so fair and transparent, we don’t even need to use it.

Seriously, though; what? Even if you subscribe to the idea of curation as the ultimate avenue, where’s the need to block people? If objectivity played any part, self-serving motives would be void. Unless it doesn’t, and writing the rules down and following them blindly would expose your thirst for control at the cost of actual utility and usefulness.

Or unless the whole concept is morally bankrupt and doesn’t actually fly anyway; it just happens to work acceptably because success hides problems, and because you can continue to hire Ministry of Truth personell until the problem seems to go away because now everyone’s complaining in unison instead of one and one on queue, which seems like a bigger story.

Oh, I see, it’s because of the Android App Market and its one lack of oversight. That’s why we can’t have shiny things, by which I mean adult treatment. Also, I heard someone stuffed a ballot once. This democracy thing obviously doesn’t work, wanna go via feudalism or straight to a totalitarian military state?

It grates.

by Jesper at August 18, 2010 08:36 PM

Surfin' Safari

Announcing…MathML!

If you’ve been following check-ins for the last year or so, then you already know that some dedicated contributors have been working on a MathML implementation in WebKit. I am very pleased to announce that the implementation is now turned on by default in the WebKit build and in WebKit Nightlies! Big thanks to Alex Milowski, François Sausset, and everyone else who has worked on MathML in WebKit.

Check out Riemann’s Zeta Function, as rendered by WebKit:

Riemann's Zeta Function in MathML

Download a WebKit Nightly and check out the demo for yourself. And as always, we encourage you to get involved and file bugs.

by Beth Dakin at August 18, 2010 12:52 AM

August 17, 2010

Alexandre Gomes

Adding In-App-Purchase Support: Avoid AppId Troubles

So, I’ve decided to add In-App-Purchase support for one of my apps. I’ve researched about the subject a few times but it always seemed quite a bit of code for a lazy-driven project until I found a quite nice tutorial that at the bottom included a utility library that packaged everything you need to do [...]

by alexmipego at August 17, 2010 11:38 PM

waffle

Break the Circle

Every once in a while, something happens.

  • Deborah Adler remade pill bottles from the ground up, stripping it down to the important information in a bottle that’s easier to read, handle and manage. The US Target chain bought the concept hook, line and sinker, and implemented it as ClearRX.
  • Another US chain, Best Buy, tossed the idea of working hours and implemented ROWE — the Results Only Work Environment. Jody Thompson and Cali Ressler developed and managed the scheme from experiment that no one wanted to end to division-by-division rollout to breakout ROWE implementation startup. Their book is called Why Work Sucks and How to Fix It and you don’t need to accept its angle for it to turn your idea of work, shame and effort on its head.
  • Ricardo Semler did the same thing in his family company Semco more than a decade prior and has since gone far further. Profit sharing abounds; you set your own salary; everyone can, and are encouraged, to read and understand the finances, and their hiring process is open. He, too, writes books, like The Seven-Day Weekend.
  • The Spanish bank BBVA together with the IDEO design firm spent two years redesigning the ATM from the bottom up to look nice, make sense and cater to how people would like services to work, not machinery to look. Pilots have commenced.

It’s not that every single concept like this will succeed. It’s not that even those achingly few who do matter and who do get the chance will succeed universally, or work perfectly. It’s that if it wasn’t done at all, we’d be lost.

Yeah, the ATM imagined is probably less user-friendly to a blind user than a current generic ATM — mostly because of the “giant touch screen” deal. But it will eventually get there, and in the meantime, nearly everyone else draws the benefits of the new approach. Yeah, adapting to a new way of working is going to take effort and determination as well as concerted effort to keep tabs on your progress and avoid stranding your co-workers. But if you do it right, knowing the status of the current project goes from being cheaply available by interrupting someone else (assuming they’re there physically) to in the hands of everyone, all the time, and you won’t have to worry about work being an obstacle for your life.

There are times when the bumps in the roads outweigh the progress being made. But it is foolish to assume that that’s every time, and to avoid trying.

by Jesper at August 17, 2010 09:10 PM

August 16, 2010

waffle

First They Ignore You, Then They Laugh At You

Sony PSP ad targets iPhone gaming.

When the target is the Sony PSP, hasn’t basically everything else already won?

by Jesper at August 16, 2010 05:49 PM

August 15, 2010

Gus Mueller

Prototyping UI Elements with JSTalk

Today I'm going to talk about prototyping custom controls (like buttons) in JSTalk. Why JSTalk? Because it looks like Objective-C, and you're using AppKit classes, and it's super easy to tweak and redraw.

Let's say you're browsing the web, and you come across some fancy web 2.0 button, and you say to yourself "Hey- I wonder what the code would look like for that if I used NSBezier paths?". Well thanks to a new JSTalk plugin I recently wrote, "Image Tools", you can code up your drawing routines in JSTalk and get something like this:

buttons

Tweak a single variable, and change it to this:

buttons

Here's how to get the plugin. First, grab a recent build of JSTalk, even if you have it installed already. Open up the archive, open up the plugins folder, and drag and drop the "ImageTools.jstplugin" file onto JSTalk Editor. This will then launch the editor, and prompt you to install the plugin. Go ahead and do so (this is the new bits, just added today).

Next, download this sample code: nsimage.jstalk. Open it up in JSTalk, and run it. You should get a window with two fake buttons, just like in the images above. Tweak it, and rerun. It's a lot faster than making a new project, adding classes, building, running, etc.

Now let's take a closer look at the code. If you're already a Cocoa programmer, there are a few things to point out:

+[NSImage imageWithSize:] - this is a category that is loaded as part of the Image Tools plugin. It's nice to have.

[JSTImageTools viewNSImage:inWindowNamed:] - JSTImageTools is a class which helps you view your creations. Just pass it an NSImage and a window name, and it'll pop up. In addition to viewNSImage:, there is also viewCIImage: and viewImageBuffer: which takes an JSTOpenCLImageBuffer. You can find samples for both of these in the Image Tools sample directory. However, I'm going to go ahead and show the CIImage sample, since I think it's pretty neat how short it is:

var filter = [JSTQuickCIFilter quickFilterWithKernel:"""
kernel vec4 foo(vec4 colorA, vec4 colorB) {
    vec2 dest = destCoord();
    vec4 ret  = dest.x  100.0 ? colorA : colorB;
    return premultiply(ret);
}"""];

[filter addKernelArgument:[CIColor colorWithString:"0.0 0.0 1.0 1.0"]];
[filter addKernelArgument:[CIColor colorWithString:"0.0 1.0 1.0 0.5"]];

var img = [filter outputImage];

[JSTImageTools viewCIImage:img inWindowNamed:"test" extent:CGRectMake(0, 0, 400, 200)];

That code will give you this:
CIImage

The kernel is nothing earth shattering, but it's super easy to get up and running to test your ideas in matter of seconds. I even ported the Color Wheel generator to it.

So in summary, JSTalk is now a great way to prototype UI controls or do image processing with Core Image or OpenCL. It's almost like Logo, but for Cocoa programmers.

August 15, 2010 10:19 PM

waffle

I Hreta Conucrercny

Mike Acton writes wonderfully on concurrent data structures.

About two years ago, I had a breakthrough at work. We’d been designing a big system that revolved around doing something necessarily sequential but making as much use of parallelism as possible. (The general mutational operations were sequential, but the base data access needed not be, and multiple jobs could run in parallel.) We’d been making due mostly with locks. I had read up on immutability and “change-the-world”, and it sounded like a lot of work.

But at a certain point, it finally did click that an object reference is “pointer-sized”, and that there are enough interesting atomic operations that you can do neat things with lockless data structures. The .NET 4/Parallel Extensions thread pool uses a mostly lockless work-stealing queue (which breaks ordering but keeps all cores fed; you can opt out). Every single Grand Central Dispatch primitive is implemented in terms of a lockless data structure (they’re also all queues, if I’m not mistaken).

What I learned, eventually, was that you can do an awful lot just by atomically swapping a pointer. The point is that mutating the data after that screws everything up. That’s why immutability was a big deal. I wish I’d had something like Mike Acton’s sketches to help guide my thinking back then, and I’m eager to see what else I can learn now that I do.

by Jesper at August 15, 2010 08:33 PM

August 14, 2010

waffle

Getting Tired

So let’s say I write a bit about how I’d like to see certain TV shows.

Let’s say I write a little more about how I’d like to see certain TV shows.

Let’s say I write a bit about how the only way they’ll let me see certain TV shows is by downloading them from the Pirate Bay, because they won’t sell them to me.

Let’s say some people take offense and claim that I shouldn’t do that regardless because it’s not conducive to my cause.

Let’s say that I agree and jump through some hoops to get a friend to send me a US iTunes gift card so that I may register a US iTunes account, so that I may still illicitly download and watch stuff, only this time I’m paying someone related to its production, which is fine because it’s also the thing I groveled about not being able to do in the first place. Everything else, I already had.

Let’s say that this works fine, aside from constantly switching between the Swedish and US iTunes or App Stores.

And then, finally, let’s say that in the fucking middle of watching something, this beauty shows up: [iTunes alert: 'This movie cannot be played because a display that is not authorized to play protected movies is connected.']

I didn’t connect an “unauthorized” display; I haven’t even connected an external display to this computer ever. And if I open it up in QuickTime Player, one of a few magical apps that they allow you to play this in, it works fine. I’m getting yelled at by unnecessary technology that was invented to force me to do what I was planning to do anyway, to stop me from doing what they forced me to do because I couldn’t do what they wanted to force me to do, and which I would now like to force them to do since they’re not planning on doing it.

So let’s say DRM works, or accomplishes something positive for any involved part, or is in any way worth the investment of time or money.

Let’s also say unicorns exist, while we’re at it. Maybe they can ride that unicorn to 1 Infinite Loop, and sign a few papers, and at least open up TV shows for distribution in Sweden.

Or even if they wouldn’t, maybe they could actually fix this magic technology to properly restrict me from seeing things I’m allowed to see but only in situations where I’m clearly not allowed to see them, which usually has nothing to do with which acronyms the attached displays support, unless they’d actually make it about that in order to piss people off.

I think I’ve said it before: You did this to yourselves.

by Jesper at August 14, 2010 09:48 PM