HN2new | past | comments | ask | show | jobs | submitlogin

Yeah, I found that line hideous - ridiculously unintuitive and hard to read compared to the equivalent in say, ruby.

Maybe the whole essay would have been better framed something like: "Objective C: not quite as bad as Java!"



Just curious, for comparison: what would the equivalent be in Ruby?


    filteredArray = [allRecords filteredArrayUsingPredicate:
        [NSPredicate predicateWithFormat:@"someField == %d",   someFieldFilterValue]];
in ruby:

    all_records.select {|r| r.some_field == some_field_filter_value}
in clojure:

    (filter #(= % some-filter-value) all-records)
in haskell:

    filter (\someField -> x == someFilterValue) allRecords


Let's be fair, in Objective-C, this could be actually more like

  NSIndexSet *indicies = [allRecords indexesOfObjectsPassingTest:^ (id obj, NSUInteger idx, BOOL *stop) { return [obj someField] == someFieldFilterValue; }];
  filteredArray = [allRecords objectsAtIndexes:indicies];
rather than what the article had in mind.

EDIT: oh, someFieldFilterValue was an integer, wasn't it. Fixed.


my_array.select { |item| item == somefiltervalue }

At least that's one way to do it in ruby.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: