4 ms·
Github's language detection is actually open-source — you can have a look at what it does here: https://github.com/github/linguist https://github.com/github/lin
by matthewmacleod 12y ago
Github's language detection is actually open-source — you can have a look at what it does here: https://github.com/github/linguist https://github.com/github/linguist
Linguist uses a number of different 'strategies' to identify the language – in the case of C vs. Objective C, it uses a pretty simple heuristic (https://github.com/github/linguist/blob/master/lib/linguist/heuristics.rb#L83-L90 https://github.com/github/linguist/blob/master/lib/linguist/...) to disambiguate C/C++/ObjC where required (such as in header files, which can't be disambiguated by file extension.)
In this case, the content of the file can't be reliably disambiguated, so I imagine it'll probably fall back to the Bayesian classifier. Interesting that the classifier identifies it as Objective C though!
- Intermernet 12y agoThanks for the link! Time to do some reading.
- pbhjpbhj 12y agoI'm not a programmer so bear with me. They have a cadre of samples in the project, searching on "#pragma once" shows no examples of Objective-C (that I can see) using that line but does show C/C++ examples with it. Is that the input to the classifier? The heuristic you linked appears to default to identifying as C; that regex doesn't look like it has anything to make the else-if return the sample as Obj-C. I'd have expected the fact that most other files on the project were C to be the dominant factor that - without any other positive result in the classifier - would weight the files as being C. Presumably this data isn't used in classifier though? Interesting.