If you call one function that returns an int and need to pass it to another function that expects a char* what do you do?
If you call one function that returns an int and need to pass it to another function that expects a char* what do you do?
To be more concrete, let's say you have the following code (pseudo-Go):
package main
import "example.com/http_server" // v2
import "example.com/utils" // transitively depends on http_server v1
function main() {
var srv *http_server.Server = http_server.New()
utils.ServeHttp(srv)
}
You're going to have a problem, because ServeHttp expects an HTTP server struct from the v1 API, and you're passing in a struct from the v2 API.If you tried to write an adapter for this then (1) you'd need to somehow construct a concrete proxy of a type you don't control, and (2) there's no way to import both the v1 and v2 APIs at the same time in your code, so you don't have a way to declare a conversion function.
That's why APIs with versions declared by dependency edges are impractical.
In Go major versions have different import paths. You can import multiple major versions of the same library:
import (
http_server_old "example.com/http_server"
http_server_new "example.com/http_server/v2"
)In C and C++, it's idiomatic to have different major versions use the same includeable name, with the version resolution handled by the build system.