Search code examples
data-bindingdata-structuresprogramming-languageslanguage-features

Beginner question: What is binding?


I was trying to understand the difference between early and late binding, and in the process realized that the concept of binding is nebulous to me. I think I understand that it relates to the way data-as-a-word-of-memory is linked to type-as-a-set-of-language-features but I am not sure those are the right concepts. Also, how does understanding this deeply help people become better programmers?

Please note: This question is not "what is late v. early binding" or "what are the trade-offs between the 2". Those already exist here.

Thanks,

JDelage


Solution

  • Binding in general is associating a name with some value. The value need not be data but can be anything that has a name, e.g. a function or a class.

    As for tradeoff:

    • Early binding makes the value available earlier. So for example compilers may apply optimization based on the known value, like evaluating constant expressions. This may result in better performance, and it requires no runtime support for retrieving the value.

    • Late binding requires the value later, so it provides greater flexibility. It becomes easier to change parts of the code or reconfigure a system.

    The general trend is towards later binding, because with faster processors and better techniques (e.g. JIT compilation) it becomes feasible more often.