I often see the terms "early binding" and "static dispatch" used interchangeably, and I also often see the terms "late binding" and "dynamic dispatch" used interchangeably.
Do these terms mean the same thing?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.
Sign up to join this communityI often see the terms "early binding" and "static dispatch" used interchangeably, and I also often see the terms "late binding" and "dynamic dispatch" used interchangeably.
Do these terms mean the same thing?
Binding is a more general concept than dispatch.
"Binding" means "resolving an identifier to something", whereas "dispatch" specifically means "resolving an identifier to a subroutine", and is most often used when talking about method dispatch in OO, but also e.g. Haskell type classes or methods of Abstract Data Types.
As was pointed out in the comments, "early" and "late" are relative, however the meaning is usually clear from the context in which the term was used, and almost always means "before runtime" and "at runtime".
Sometimes I've heard "static dispatch" and "dynamic dispatch" to refer to exactly how the language locates the method to be called: "static" using a fixed data structure and "dynamic" using a list that has to be run each time.
"Binding" generally refers to bringing separately-compiled subroutines together into an executable. I think of "early binding" as linking against .obj
files, and "late binding" to refer to .DLL
or .so
files.
However – bottom line – the terminology can be ambiguous. You need to be sure what you are actually meaning by the terms you're using, and that you also understand the other party's meaning!
It’s not always clear what someone means by these terms, but generally:
With static dispatch you know which code you want to call and the same call will always call the same code. With dynamic dispatch, you don’t know before the call what code will be called. Take C++ virtual functions. The same virtual function call can call different code, depending on the class of an instance.
With early binding, your program knows where each bit of code is when it is loaded into memory. You can have static dispatch and early binding: you don’t know yet which code is called, but you know where each code that could be called is. Late binding happens for example if you load a library only when it’s needed. You might know that you want to call the sqrt function in the math library, but you don’t know where it is until the math library has been loaded into memory, and someone has examined its table of contents to find where the sqrt function is. Usually this is implemented so that the second call knows where the function is.