What does “legal” mean in programming?

September 13, 2026 3 answers
Asked by MellowKite27
When programmers say that a character is "illegal" or that overriding a method in a certain way is "legal," what exactly do they mean? Does it simply mean that the programming language allows or disallows it, and what happens if I use something that isn't allowed?

Answers

CedarFox41
Think of it like chess or basketball. Moving a knight in a straight line is an illegal chess move because it violates the game’s rules. Similarly, code can be illegal when it breaks the syntax or rules defined by the language. Nothing criminal is involved—it’s just a technical way to say “not allowed.”
Reply to this answer
OrbitMango6
Sometimes people use “legal” specifically to mean syntactically valid: the code is written in a form the language recognizes. Invalid syntax is commonly caught before the program runs, although some rule violations may only appear during execution depending on the language.
Reply to this answer
PixelHarbor8
“Legal” just means permitted by the rules of the programming language. An “illegal character” is one that isn’t allowed in that particular location, while a legal method override follows the language’s rules. If you break those rules, the compiler or interpreter usually reports an error, and the program may not compile or run correctly.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions