what? how?

Reply to this note

Please Login to reply.

Discussion

how do prototypes differ from interfaces and structures (named ordered lists of variables)

not that much in go a lot in other languages.

The biggest difference would be that they are explict (that's not something I'd assume you see as an advantage) and dynamic.

The biggest advatage (at least for me) is that you can implement protocols on types you don't own. Not by modifying or embedding them.

ok so they are just another silly name for interfaces, but trying to say they are not interfaces

you can do that now with interfaces with generic parameters in Go since 1.24, this "prototypes" thing

it's a relaxing of a rule that you can't define external (not in package) methods on a type, you can now define methods on a type alias

i barely even use generics in Go yet, mainly i just use it to make it so people can call my code with strings but my internal implementations remain in mutable bytes. they won't retract the mistake of making strings immutable

rust's immutable by default is exactly the opposite of how i think it should be done, and the immutables in Go are the biggest pressure on GC because you can't just make them into freelist buffers, they are immutable, they have to be disposed with the GC unless you want to dice with unsafe

also, in Go, effectively declaring a type is creating a prototype, because you can embed them in other types, you can alias them into new types, and now you can even declare new methods on the aliased type

Go lets you do all the things that you need, and rejects all the things you don't, in the overriding prime directive that no construct should be expensive to compile, or execute.

It's little bit apple and oranges because clojure is a dynamic and hosted language. Prototype do not compile. They don't actually need AOT neither. But protocols are way faster because they dispatches on a first argument not on arbitrary one as in case of multimethod.

so again, that's the point, they are just a double indirection like an interface, a static type abstraction, just as it is cheap to resolve a pointer it is cheap to resolve the "fat pointer" of type and variable in an interface

it's just an interface

they muddy the waters by inventing new names for well established concepts

type aliases were a huge step forward.

Go with aliases (2017?) and it's implicit interfaces allows you similar things like protocols. It's not very common in other languages.

Clojure was out there before go (2007) and they also need to distinguish between hosted (jvm) interfaces and clojure's solution to expression problem.

I'm more in FP and go was very hard to use that way. I'm simply like protocols more. And also use go for different applications.