What does “legal” mean in programming?
Asked by
v2.meshfix
When programmers say that a character is illegal or that a particular way of overriding a method is legal, what exactly do they mean? Does "illegal" simply mean the programming language does not allow it, or can it refer to something else?
Answers
It’s similar to calling an incorrect move in chess “illegal.” A knight moving in a straight line breaks the rules of chess; likewise, code is illegal when it breaks the syntax or rules defined by the programming language. For example, using an unsupported character in an identifier or overriding a method with an incompatible signature may be rejected.
Reply to this answer
People sometimes use “legal” to mean syntactically valid, meaning the code follows the language’s grammar and can be parsed or compiled. Other times they mean that an operation is allowed by the language’s semantics or type system. In either case, “illegal” generally means the language tools reject it or it does not behave as a permitted operation.
Reply to this answer
In programming, “legal” usually means permitted by the rules of the language. An illegal character, statement, or method override violates those rules, so the compiler or interpreter may reject it, or the program may fail when it runs. There are no actual legal consequences—it’s just terminology borrowed from everyday language.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions