Hacker News new | ask | show | jobs
by kennywinker 5167 days ago
oh crap, does concat create a new object, or mutate the current one? is it the same as using + or do they handle objects differently....? should I be using << here maybe?

I agree with you that the verbosity of ObjC makes it harder to mentally parse fast, but I also think there is a lot of clarity to it when you read it slow.

Where I see ObjC fall down is more in terms of command verbosity. For example in Ruby,

    File.open("readfile.rb", "r") do |infile|
      while (line = infile.gets)
        puts "#{line}"
      end
    end
...would be ~150 lines of code in ObjC (Dave DeLong: http://stackoverflow.com/a/3711079/196358). Which is not really a failing of the language, actually. It's a failing of the libraries that come with the language.

Apple chose to give you a couple ways to read a file. The easy way is `stringWithContentsOfFile:encoding:error:error`, but the next level of control is way to low level. Dave DeLong's solution to reading a file line by line exposes an api that looks like this:

    DDFileReader * reader = [[DDFileReader alloc] initWithFilePath:pathToMyFile];
    [reader enumerateLinesUsingBlock:^(NSString * line, BOOL * stop) {
      NSLog(@"%@", line);
    }];
Not actually much more complex or verbose than the ruby.