Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I agree the second example is more understandable, but I think most of that benefit comes from named parameters (a language feature), not the naming convention itself. That is, were the naming up to me, I would prefer:

  NSString *filtered = [unfiltered replace:@"verbose"
                                   with:@"explicit"
                                   options:CaseInsensitive
                                   range:Range(0, [unfiltered length])];
Of course, I'm making assumptions about what those parameters mean. But I find this much more clear, assuming the intentions are what I think they are.


In Objective-C, those aren't named parameters, like you might find in Python, or faked in Ruby or Groovy. They are called 'Keyword Messages'. In your example above, the method signature is replace:with:options:range:, compared to say a C++ style replaceWithOptionsRange. It's simply a way to interleave arguments in the message send itself, inherited from Smalltalk.


When you use the word "replace", to most people, that signals that you would be changing the current object in place, not returning a new object based on the given one.

On the second line, you didn't mention at all what is passed in.

For the last two, removing the NS prefix would work if Objective-C had some kind of namespacing support. Currently it doesn't, so the NS prefix is kinda needed.


New object versus mutating the current object depends on convention - in Python, there is a "replace" function on the native string type that returns a copy (http://docs.python.org/library/stdtypes.html#string-methods); in C++, std::string::replace mutates the string in place.

I'm not sure what you mean by not mentioning what is passed in. Keep in mind: I have never programmed in Objective-C. I am going on intuition alone.

No namespace support is a bummer - it means you're going to end up with long identifiers all over the place.




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

Search: