Some languages like C and C++ require defining the names before using them, though the definition could sometimes be only a header specifying something is a struct or function without the body. Some languages don't. And many interpreted languages are mixed, that you could refer to anything in the definition, but the code must be called after the referred entities are also defined completely.
What are the exact criteria for designing the syntax to make referring before definition possible? And is it possible to have a middle ground, that forward declarations are only required in the situations that it is absolutely necessary?
In the best case, function bodies are just strings, and definitions are scanned before evaluation, making this trivial. In the worst case, you could define new syntax in the code, which may change the position of the end of a function, making this obviously impossible. But where do they meet?
A special example is Bash, where functions are in the mixed way, as they are just called using their names as strings and there isn't a mechanism to track down where they are defined, but aliases must be defined before using in a function, because you could alias unpaired braces or other grouping constructs. It looks like a middle ground, but is greatly simplified because of the fact that Bash is not object oriented. In object oriented languages, object definitions may carry a syntax change from a class elsewhere.
alias x={
. You could get similar things if you are going to support two different kind of regexes using different escapes, in grammars like JavaScript, and only distinguish them by the function call. More practically, in C++, the keywordtypename
is sometimes required in random places in templates even with SFINAE. I wonder why it is the case. $\endgroup$