[CocoaApp isThisTiger]
Alastair Houghton
alastair at alastairs-place.net
Tue Oct 23 08:24:20 PDT 2007
On 23 Oct 2007, at 14:52, Finlay Dobbie wrote:
> On 23/10/2007, Alastair Houghton <alastair at alastairs-place.net> wrote:
>>> Use Gestalt() and be done with it. It is the correct and most
>>> robust way to get the system version.
>>
>> Though whichever way you do it, it's possible to screw up if you get
>> your comparisons wrong. It slightly easier to mess up if you're
>> trying to scan a version string from a file, of course, but that
>> doesn't mean you can't do it properly. I do note though that one of
>> Apple's guys said that reading that file was wrong and that we should
>> use Gestalt.
>
> The file is an implementation detail. Don't rely on it.
My point was that Rosyna was implying that the reason Gestalt() was
"right" and reading the file was "wrong" was that people messed up
reading the file. But that's not true (sure, it's true that people
stuffed up reading it, but that doesn't make Gestalt() "right" and
reading the file "wrong"). The reason Gestalt() is the best way is
that Apple said so. And in either case, you can still do the
comparison wrong. A common mistake is to do this:
if (majorVersion >= 10 && minorVersion >= 4 && bugFixVersion >= 6) {
// 10.4.6 and above <---- WRONG!
}
because of course the last test will fail for 10.5.0 (and the middle
one, for 11.0.0). Gestalt() doesn't save you from that kind of
stupidity.
And *even after all that*, there are one or two reasons you might
want to use the file anyway; for instance, if you need the build
number, or if you need to identify the version of Mac OS X on a disk
that you didn't boot from. And it *isn't* an "implementation
detail". It's documented all over the place in Tiger, including in
the manual page for the "sw_vers" tool, which is yet another way to
get this information. As for Leopard, well you can look for yourself
I suspect.
>> Any sensible/pragmatic developer---and I think that's most of us---
>> will use a Carbon API *if* they know about it and if it makes their
>> life easier or provides a better user experience.
>
> So, again, use Gestalt. It's the best tool for the job. Whether
> it's Carbon or Cocoa is irrelevant.
**I didn't say you shouldn't use Gestalt**, though I will say (now
that you've said that) that it depends on what you're trying to
accomplish. It might be better in some instances to use uname()
instead of Gestalt(). Or to check the AppKit version number. Or
indeed to do something else entirely. The decision should be made on
the basis of the information you actually want.
Checking the system version to see whether you can call a QuickTime
API, for instance, would be a mistake. But such things have
happened, *over and over*, on all the platforms I've worked on.
The best bet is always to test for features, not versions, because
it's difficult to screw that up and it allows for the possibility
that things might be back-ported in future.
Kind regards,
Alastair.
--
http://alastairs-place.net
More information about the MacOSX-dev
mailing list