Hacker News new | ask | show | jobs
by nix 5570 days ago
People forget that you can just use C for the simple stuff. Many of these Objective-C classes are slow, verbose, buggy, and poorly documented compared to the equivalent open source C libraries. In many cases the C API is just as nice - maybe slightly less fancy, but polished from years of actual use. Why use ASIHTTPRequest or NSHTTPRequest when libcurl is mature and fast and cross-platform? What do you really gain by wrapping Objective-C around your regex or date handling? You'll find out when you start profiling (or porting to any non-Apple system).

The Objective-C language (Smalltalk in C) was a nice idea (in the 80s...) but newcomers to iOS should be aware that the non-UI parts of the Cocoa/UIKit libraries are garbage compared to what C programmers have built over the past thirty years. I've had to replace enough of the ObjC libraries I've used with plain C that I just start with the C code now.

2 comments

If you want to talk about tested and battle-hardened code, make sure that you really have the older API :)

Foundation (and, by extension, NSHTTPRequest and NSURLConnection and such) is a few years older than cURL is. Foundation is really an implementation of the OpenStep API designed by Sun and NeXT. in 1993. cURL was released in 1997.

What do you lose by having a higher level of abstraction that is more flexible? Do you have raw profile data that shows that libcurl is significantly faster and performs better?

Newcomers to anything should be aware that old biases die hard and people on the internet should be taken with a grain of salt.

What do you gain by wrapping Objective-C around your regex?

Me being vastly more productive. Extract all the http like URL's from a string and print them:

  for(id match in [searchString componentsMatchedByRegex:@"\\bhttps?://[a-zA-Z0-9\\-.]+(?:(?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\\\]*)+)?"]) {
    printf("URL: %s\n", [match UTF8String]);
  }
I dare you, I double dog dare you to do the same thing in three lines of code with C and PCRE.