Telling clang to be quiet

When using Xcode I’m a big believer in clearing out not just the error messages that I get but also all the warnings. 99% of the time if I ignore a warning it usually results in something crashing or a weird bug expressing itself. BUT there is that 1% of the time when Xcode produces a false positive and you get a warning that isn’t and all you want to do is make it go away. Today was such a day and thankfully I found how to tell clang to ignore the warning.

I have some code:

[component performSelector:componentSelector];

clang really doesn’t like this code. The problem is that ‘componentSelector’ is a variable and clang doesn’t have a enough information about it so it raises a flag about possible memory leak. Now, I know, since I wrote the code, that ‘componentSelector’ is good and won’t cause a memory leak so to silence the warning I add the following:

#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[component performSelector:componentSelector];

this is a very nicely specific flag telling clang to ignore the performSelector leaks warning. I’d really rather find away around this, ie making clang happy, but thus far no luck so it’s the ignore flag till I do.

The Literals are Coming, the Literals are Coming

It’s just days before WWDC and the rumors are flying about what Apple will introduce. Will it be iOS 6? new iPhone hardware? MacBook Pros? how about Mac Pros? One addition that isn’t actually a rumor but pretty much a confirmed fact is the addition of literals to Objective-C and the arrival of the Apple LLVM compiler.

The cat escaped the bag back in March when Apple checked in code to the open source clang trunk, over at LLVM.org, adding capabilities to make literals possible. Along with checking in the code came some very nice documentation that details what literals mean for developers. The Big Nerd Ranch Weblog followed the release by Apple with a slightly shorter explanation on literals.

If you have the time I would definitely recommend reading the LLVM.org article. The short version on literals is that Apple is bringing some of the comforts of Ruby to Objective-C by extending the responsibilities of the ‘@’ symbole. The slightly longer version is the Apple is adding syntactical sugar to NSNumber, NSArray, and NSDictionary.

For NSNumber Apple has simplified the process of creating them. You can now prepend a number with the ‘@’ symbol and presto, you’ve got an NSNumber object. There isn’t an equivalent way to get your number back out of NSNumber but this is definitely a good start.

For NSArray and NSDictionary Apple has added a bit of magic too. Now you can create an NSArray by putting your array inside a ‘@[]’ and an NSDictionary by putting your dictionary inside a ‘@{}’. Unlike NSNumber Apple added a nice way to get data back out of both NSArray and NSDictionary. The secret is ‘[]’. You put square brakets after either your NSArray or NSDictionary and then put your index, either number or object, inside the square brackets.

If you’re feeling particularly adventures you can download the current build of both llvm and clang from LLVM.org. Unfortunately at the moment Xcode doesn’t have these new features but wait a moment, well at least until Monday, and you’ll have Objective-C with Literals.

clang, It’s not just a Objective-C compiler frontend

One of the things I discovered while investigating building my own programming language was the fact that clang is much more then your typical front end to the llvm compiler. It turns out that clang can do all kinds of useful things for you if you’re trying to build your own C/C++/Objective-C IDE. Closer inspection of clang reveals that it can do all kinds of wonderful things like code completion, pointing to specific lines where you have coding mistakes, and much more. It’s a fantastic treasure trove of tools.

If you’re interested in learning more I would highly recommend taking a look at Doug Gregor’s LLVM Developer Meeting presentation titled “libclang: Thinking Beyond the Compiler” (slides/video) It’s a great presentation and it will get you on your way to building your own IDE or at least giving it some serious thought.

A Little Insperation

Every now and than I come across some good inspiring video. Not too long ago I came across this video of the winner of the Moth GrandSLAM. The main guy talking is Moran Cerf, an Israeli, and he gives a very engaging talk about his background and the story that led him to becoming a researcher.

All in all this is a great video and well worth the 10 minutes.

A Little bit of Mobile History

For the longest time I’ve been a fan of mobile computer. It started with devices like the Newton and RIM and now I’m building mobile apps for Android and iOS. Along the way I’ve had the fortune of watching history being made. One company that seem to have a very bright future was Palm.

In the beginning Palm was revolutionary for all the things it didn’t do. While the Newton tried to be a portable computer, Palm focused on phone numbers, calendars, etc. It didn’t try to do handwriting recognition but instead invented a new, simpler, letter set. With the introduction of the Palm V the Palm got sexy. Palm had the good sense to pair up with IDEO and the result was a thin PDA that people wanted to own.

Between then and now something happened. Actually quiet a bit happened. At one point an acquaintance moved his family out to CA so he could work for Palm. When I spoke with him about what was coming down the pipe he went on and on about the web and building on the web. At the time I didn’t quiet understan what he was going on about but then I saw webOS and the light went on.

I was impressed, the concept/implementation made sense and a moment later the company was snapped up by HP. I thought that HP saw the light too but the next moment HP decided to kill webOS and just as quickly webOS decided to open source webOS. Now, it’s all dead. The webOS team migrated to Google and it seems that the open source webOS is on the fast track to NO WHERE.

I got the chance to write some code for the HP TouchPad and it wasn’t half bad. It seemed like a fun platform that basically needed more work but had lot of potential. The Linux base made an interesting platform and I was looking forward to understanding webOS better.

All of this is a very long way of pointing to a rather interesting article written by the guys over at The Verge called Pre to postmortem: the inside story of the death of Palm and webOS. It details the ins and out/ups and downs of Palm/webOS. It’s well written and worth the time.

Writing your own Programming Language

Every now and then I get the urge to write my own programming language. One of the problems I have run into time and time again is “How do you write an Object Oriented Language?” I’ve found lots of books on writing C like programming languages but very few actually talk about implementing the object oriented part of the language. When I talk to people that should know this kind of thing often the response is “Well that’s easy. You just create these structures and magic magic magic and you’re all set.” It’s the magic, magic, magic part that I want to understand.

More recently, and I don’t mean last week or last month, I got back onto this kick of writing my own language again but something different happened this time. I came across a book called Object Oriented Programming in ANSI C written by Axel-Tobias Schreiner back in 1994. While the book is long out of print it seems that a PDF of the book is available.

The book is an interesting especially if you want to understand the interworking of object oriented programming languages. It’s especially interesting when you notice that the way in which the book describes implementing object oriented programming is remarkably simular to the way in which Objective-C is implemented.

Some useful Cocoa/Objective-C links

Just to kick things off, here are two very useful links for Cocoa/Objective-C developers:

For anyone interested in developing their own programming language, the LLVM site has a fantastic tutorial to develop a language called ‘Kaleidoscope‘. Well worth the time to learn the ins and outs of LLVM and all its parts.