Re: Why not use path-based API? (was: Loading image resources)
Re: Why not use path-based API? (was: Loading image resources)
- Subject: Re: Why not use path-based API? (was: Loading image resources)
- From: Quincey Morris <email@hidden>
- Date: Sun, 14 Sep 2014 08:23:31 +0000
On Sep 14, 2014, at 00:57 , Aandi Inston <email@hidden> wrote:
> Why? Really, why? Certainly there are APIs where we have to use URL's and
> we have to convert the path into a URL, but where a non-deprecated
> path-based URL exists, what current or future obstacles do you foresee? The
> URL doesn't seem to be more predicable or persistent, for example.
It’s not an absolute rule, and it’s certainly possible to defend the use of path APIs, but here are some of my reasons:
1. NSURL-based APIs were introduced *in order to* replace path-based APIs, so using the new APIs maybe helps to future-proof your code. IOW, sometimes Apple gives us hints as to what continents are moving in the API geoscape, and sometimes they do this by replacing APIs with new ones that more or less seem to do the same thing — until later they don’t.
For example, although Cocoa generally requires *file* URLs for non-internet things, it’s possible that in the future we’ll need to locate resources that don’t have a traditional path.
2. I think some path-based APIs had quirks, for example about handling paths that started with a tilde, or other environment-related issues. Generally, NSURL-based APIs are regular in their behavior. However, I don’t have any examples of this difference at hand, and I could easily be wrong about this point.
3. Some NSURL-based APIs improved or corrected the methods that they replaced. For example, the new APIs follow standard conventions for returning errors.
4. Some things can only be done with NSURL-based APIs. For example, sandboxed access to files chosen by users.
Because of #3 and #4, you’re going to be using NSURL at least some of the time, and mixing the two API styles gets messy fast. If you have to pick one, NSURL is the one to pick.
Here are some of the reasons for using path-based APIs:
1. You’re writing a command line utility that’s (e.g.) POSIX-compliant or crosses to other UNIX platforms. In that case, its probably more consistent to stick with paths, unless you have some other reason to deal with URLs.
2. You’ve got existing code that uses path-based APIs, and you can’t justify the time it would take to convert.
Because the above is too long to be useful in response to posts on other issues, I decided to reduce it to “You should use URL-based equivalents generally.”
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden