Live data from Hacker News

Windows 10: Code that uses 'os.StartsWith(“Windows 9”)'

searchcode.com

11–20 of 37 posts

Re: Windows 10: Code that uses 'os.StartsWith(“Windows 9”)'

#12
I don't find this search reliable at all. There are a lot of completely unrelated results. I couldn't find any related match on the 2.000+ Python results, for example. Same with C++. This is being publicized as "proof" of the rumor but it's not representative at all.

The Windows C/C++ API returns a structure with version numbers [1], same with the C# one [2]. Other languages just wrap the native C API call, GetVersionEx.

The most troubled framework is Java: because of some strange design decision, you can only get the version as a string (see [3]), and that makes impressively easy for programmers to screw up version checks. However, as other commenters have said, those apps could run on compatibility mode and Windows would solve the issue itself instead of completely changing an operating system's name.

1: http://msdn.microsoft.com/en-us/library/windows/desktop/ms72... 2: http://msdn.microsoft.com/en-us/library/system.environment.o... 3: http://stackoverflow.com/questions/228477/how-do-i-programma...

Re: Windows 10: Code that uses 'os.StartsWith(“Windows 9”)'

#13

There are no good reasons to check for an OS version anyway. Checking for the platform, ok. Not the version. That can be handled with feature detection.

There's one good reason - sometimes feature detection lies. Or the feature you are looking for is implemented nonstandardly (brokenly).

Re: Windows 10: Code that uses 'os.StartsWith(“Windows 9”)'

#14

Earlier quoted context omitted.

This "convulted version checking method" is the default way to do it with Java, I'm not sure if there's any other programming languages that do it as well.

Source for that?

Yeah, the OP[1]. A lot of the returned results are Java code, alternatively there's also [2].

[1] https://searchcode.com/?q=if%28version%2Cstartswith%28%22win...

[2] http://docs.oracle.com/javase/tutorial/essential/environment...

Re: Windows 10: Code that uses 'os.StartsWith(“Windows 9”)'

#15

There are no good reasons to check for an OS version anyway. Checking for the platform, ok. Not the version. That can be handled with feature detection.

I generally agree, but I'd amend that to "there are few good reasons". When an API is present but buggy, sometimes there's no good way around a version check. It can still be regarded as a last resort.
Post reply on HN