mobiletuts: Learn Objective-C (Series)

I picked up a new MacBook Pro from in April (2011) with the intention of learning Objective-C to write iOS and Mac software, but made little progress with any of the tutorials I found, until I found this series on mobiletuts:

I think the thing that kept me away from understanding Objective-C until now was the strange look of the significantly different syntax used in Objective-C, as compared to languages I’m familiar with like C#, Java, JavaScript, and C/C++. Objective-C syntax is derived from Smalltalk, in which one sends a message, as opposed to the more common Simula-derived languages, where one calls a function. (More detail on this concept can be found on Wikipedia here: Objective-C: Messages).

In other words, code like this (C#) looks familiar:

public interface SimpleCar : Object
  // Public Accessors
  public String Make { get; set; }
  public String Model { get; set; }
  public int Vin { get; set; }
  // Not really necessary, since we already have an accessor...
  public void SetVin (int newVin); 


…while this (Objective-C), until recently, looked incredibly foreign and confusing:

@interface SimpleCar : NSObject {
  NSString* make;
  NSString* model;
  NSNumber* vin;

// set methods
- (void) setVin:   (NSNumber*)newVin;
- (void) setMake:  (NSString*)newMake;
- (void) setModel: (NSString*)setModel;

// convenience method
- (void) setMake: (NSString*)newMake
         andModel: (NSString*)newModel;@end

Unfortunately, despite sincere interest and significant motivation, most of the Objective-C guides I came across were too dense, too verbose, or not particularly interesting. So, my MacBook got a ton of use as my primary home computer (I’m an ASP.NET software engineer by day, and I use Windows exclusively at the office, but I do love me some OS X…), but Xcode gathered dust in my dock, and I went about exploring alternatives that used a more familiar syntax – like the Qt SDK (C++), MonoDevelop (C#), and NetBeans(an impressive array of different languages).

Now that the back story is out of the way, here’s why the mobiletuts Objective-C series turned that all around and actually got me to *enjoy* developing with Objective-C:

  1. It’s very simple.

    While I do have an extensive background in software engineering, I appreciate guides that break concepts down to their simplest parts and rebuild them slowly, with no assumption of the reader’s background (other than interest in the topic). For most of you who already know your way around another language and who are familiar with the Terminal, the first lesson (Day 1) will seem almost too basic, but stick with it, because you’ll find that the author, Dan Walker, really knows his stuff. His approach reminds me of a quote from commonly mis-attributed to Einstein: “If you can’t explain it simply, you don’t understand it well enough”.

  2. It starts with what you know.

    I didn’t fully realize this from reading other sources about Objective-C, but it really is a strict superset of C. The benefit of this fact, for developers familiar with Simula-derived languages (C#, C++, Java, etc.) is that you can start writing Objective-C code in a syntax you’re familiar with (C), then sprinkle in bits of Objective-C syntax slowly, while you become more familiar with its Smalltalk-derived syntax. For instance, this code is valid, and compiles successfully in Xcode – Notice the use of Objective-C syntax within a familiar C-style method. (This clip is from the Day 3 post.):

    #import <Foundation/Foundation.h>
    int main (int argc, const char * argv[]) {
      NSString *testString;
      testString = [[NSString alloc] init];
      testString = @"Here's a test string in testString!";
      NSLog(@"testString: %@", testString);
      return 0;
  3. It’s actually interesting.

    Dan has a great conversational style to his posts that make them very accessible and compelling, while slowly introducing increasingly complex topics. In Day 1, he explains how to open the Terminal app and invoke gcc from the command line, and by Day 2, he’s provided a great synopsis of  the benefits of concepts like encapsulation, abstraction, and inheritance.

I’m nowhere near an expert on Objective-C, since I literally (yes, literally) started reading this article yesterday, but I feel confident enough in what I’ve learned from this article to start poking around in Xcode and trying to refactor some of my existing code into a working Objective-C implementation. I hope this article helps you as much as it’s helped me, and please, let me know what you think by posting in the comment section below.

Happy coding! =)

Quick Update: CSS/JS Auto-Minification in ASP.NET

I’ve been trying for weeks to write up a good technical article about a recent CSS/JavaScript minification handler for ASP.NET (ASHX/HttpHandler) that I whipped up, but our current release has been so busy, I haven’t had enough time to really put it all together.

Just wanted to post a quick update for everyone who mentioned they’d like to hear about it that I’ll be posting more info as soon as I can. =)

In the meantime, here are links to some of the articles that helped me construct the custom handler in the first place:

And, my own pride and joy (this damn code took me forever, only because I had to do all sorts of research and testing with Regex in C#), the function that will fix relative paths in the combined CSS files by replacing them with absolute paths based on your application root:

/// &lt;summary&gt;
/// CSS Only: Replaces relative paths in url(...) properties within the specified script.
/// &lt;/summary&gt;
/// &lt;param name=&quot;scriptBody&quot;&gt;The pre-combined script, passed from CombineScripts().&lt;/param&gt;
/// &lt;param name=&quot;scriptPath&quot;&gt;The relative path where scripts are located (ex: ~/CSS/).&lt;/param&gt;
/// &lt;param name=&quot;applicationPath&quot;&gt;The absolute application path. (ex: /ApplicationRoot).&lt;/param&gt;
/// &lt;returns&gt;&lt;/returns&gt;
private static String FixRelativePaths(String scriptBody, String scriptPath, String applicationPath)
 scriptPath = VirtualPathUtility.AppendTrailingSlash(scriptPath);
 String relativeRoot = VirtualPathUtility.Combine(applicationPath, scriptPath);

 Regex cssUrlReference = new Regex(&quot;(?&lt;=url\\()(.+?)(?=\\))&quot;, RegexOptions.Singleline);
 Regex invalidPathChars = new Regex(&quot;[ '\&quot;]+&quot;, RegexOptions.Singleline);

 MatchCollection urlMatches = cssUrlReference.Matches(scriptBody);
 foreach (Match m in urlMatches)
 String oldPath = Regex.Replace(m.Value, &quot;[ '\&quot;]+&quot;, &quot;&quot;);
 String newPath = VirtualPathUtility.Combine(relativeRoot, oldPath);
 newPath = VirtualPathUtility.ToAbsolute(newPath);
 scriptBody = scriptBody.Replace(m.Value, newPath);

 return scriptBody;

I’d love to read your comments and/or questions about this code, so please feel free to post your thoughts in the comments on this post.

I’ll try to get you the full meal deal on this code as soon as I can. =)

jQuery fadeIn/fadeOut IE cleartype glitch

Thanks to Benjamin Michael Novakovic for this fix!

While using the jQuery  javascript library today at work, I noticed a glitch under IE7. When fading a html node with the .fadeIn() and .fadeOut() functions in jQuery, IE drops the windows Cleartype rendering; which results in very ugly text. This problem appears to be very common, but no one has a nice solution for the problem.

The most common way to solve this problem is by removing the filter CSS attribute. In normal javascript, it would look like this:


and in jQuery, it would look like this:

$('#node').fadeOut('slow', function() {'filter');

via Benjamin Michael Novakovic » jQuery fadeIn/fadeOut IE cleartype glitch.

the hamstu » The Typography of Code


Cool post with a lot of great history and font samples!

As a self proclaimed programmer/designer I enjoy not only the logical and practical things in life, but also the beautiful and well designed. And I find the greatest pleasure when these things converge to produce something extraordinary.One such thing is Typography. Typography is the art of language, the visualization of the spoken word. A medium by which non-verbal communication is made possible. And though I profess no expertise in this art, I have come to deeply appreciate it’s power and ability to convey the same message in so many different ways. Each with a unique feeling and style.

The Messenger

In 1956 Howard Kettler designed the typeface Courier. It was made for IBM’s new (and revolutionary) line of electric typewriters. Originally called “Messenger”, Courier is one of the earliest fixed-pitch (also known as Monospace) fonts, meaning each character takes up the same amount of space on a line; allowing for easy tabular alignment and legibility.

Courier was a hit, and as many made the transition from typewriter to computer, this classic typeface wasn’t far behind. It was included in all early Apple computers, and while creating the core fonts for Windows 3.1, Microsoft hired Monotype Typography to give Courier a makeover. And so Courier New was born, as a thinner and cleaner version of it’s former self.

via the hamstu » The Typography of Code.

Lifehacker: Top 10 Useful Bookmarklets

Another great article from Lifehacker about bookmarklets:

Having a good set of bookmarklets on your browser’s toolbar is like having a web-savvy Leatherman handy—you can take them anywhere, use them in many situations, and they just simply work. A bookmarklet is a little different than a plain old bookmark—it’s a snippet of JavaScript that can perform all sorts of magic on the web page you’re currently viewing. You add bookmarklets to your bookmarks collection to get all sorts of things done as you surf the web. Let’s take a look at some of the best bookmarklets available, which can help you search and email, download videos, and work out some of the web’s kinks.

To start using a bookmarklet, make sure your browser’s bookmarks toolbar is visible. Then, drag and drop the bookmarklet link (enclosed in square brackets below each item on this post) to your bookmarks toolbar. When you’re on a page you want to use the bookmarklet? Just click its name on your toolbar.

(via Top 10 Useful Bookmarklets)

@TheKeyboard: Form Validation with jQuery

Great article about jQuery Form Validation from

Now that I have to actually design interfaces for other people, I am learning the finer details of Javascript. Specifically, I’m using JQuery as my library of choice. I won’t go into why I’m using, just go to the site and see it for yourself. One of the things I’ve had to build recently is a playlist editor for the IPTV project. I decided to be user-friendly for once, and make it Ajax-powered. So this meant a lot of work creating small little actions in my Zend Framework code to accept form posts, etc. Still cleaning things up, but I wanted to share some of the coolness from using a jQuery form plugin .

So, never having really done any Javascript form validation (I know you’re shocked) I unleashed my inner “programmer” to go and hack away at it so I can figure it out, then call back my inner “developer” to make the code elegant and compact. It took me all morning but I figured it out thanks to Google and just hacking away at it. One of the neat things about Javascript is that it supports the ability to dynamically define functions in your code. With it’s extensive use of callbacks, jQuery leverages this to the hilt. I believe this is what the Ruby crowd refers to as “blocks and closures”. Please correct me if I’m wrong. Okay, so here’s some code that illustrates how I was doing validation of the form:

(continued via Form Validation with jQuery)