Which Language Did They Paste?
heuristic language detection
Part of: AI Code Reviewer
People paste code without saying what language it is. The reviewer needs to know, because the static checks in the next lesson are different for Python and JavaScript, and the prompt reads better when it names the language. You could ask the model, but that costs a call and it can still guess wrong. A few pattern checks get the common cases right instantly and for free. Count signals instead of trusting one. No single pattern proves a language. A line ending in a semicolon could be JavaScript, Java, or C++. new Thing( appears in JavaScript and Java. So instead of one test per language, give each language a short list of signals and count how many lines match each one. The language with the highest total wins. Each signal was picked because it is common in one language and rare in the others. Ties and empty scores. Two cases need a decision up front. If every score is zero, the snippet might be prose, a config file, or a language you don't support, so return unknown and let the model handle it with no language hint. If two languages tie, break the tie with a fixed order so the same paste always gets the same answer. Reviews that change between runs for no reason erode trust fast. It
Challenge: Guess the Language