I also never seen any language doing interfaces like Go. Go does it just right. I find that this is pretty impressive as a feature on its own.
I also never seen any language doing interfaces like Go. Go does it just right. I find that this is pretty impressive as a feature on its own.
OCaml has used structural subtyping since the beginning for its object layer. C++'s templates also use structural subtyping on type arguments. Pierce also covers the subject in TAPL.
> I find that this is pretty impressive as a feature on its own.
There are advantages and inconvenients to structural subtyping (compared to nominative): it's more flexible and has much lower overhead, but it's subject to false positives (structurally equivalent but semantically unrelated objects) and tends to have much worse error reporting. Not to mention structurally typed systems still usually have and need nominative types in their core, for "non-object" types.
class A { public: int do() { return 1; } };
class B { public: int do() { return 2; } };
template <typename T> int do(T t) { return t.do(); } do<A>(a)
do<B>(b)
Can I take any arbitrary type with an "int do()" method and use that with do? Like: do(Arbitrary)It should work without the template parameter: do(a), do(b)
"Can I take any arbitrary type with an "int do()" method and use that with do?"
Yes.
It's not the case here, so it just works.
Which is why "you have never seen a language doing interfaces like Go", everybody else calls it what it is (structural typing/structural subtyping)
> I no that Go's interfaces are nothing like anything in C++
Well you may "know" it, but your knowledge is wrong.
What did you specialize in? It's pretty easy to hit upon co-routines, if you have an interest in Scheme or even Haskell. But I can imagine, it's much harder if you are into, say, the innards of database schemas. (Just a random example.)
Disclaimer: The above is definitely true for coroutines in general, but I don't know much about Go and whether its coroutines are truly unique.
To add to the list, they're implemented in Python using yield statements
As someone else mentioned, you need to get deeper into programming languages, not operating systems. Scheme has call/cc which can be used to build co-routines. Someone needs to clue in the nodejs crazies as well, callbacks are not the way to design a language. ;-)
Programming advances so slowly because all of the training required to become familiar with it eventually becomes a blind spot.
For more effective use of lightweight processes, I'd probably reach for Erlang or Occam.
In fact, mixing threads and an event loop with async IO is probably a good way to make everything blow up.
This paper by the authors of Lua has some good historical background:
http://lambda-the-ultimate.org/node/2868
They also poke fun at Python in some ways because the coroutines are fairly limited. Python got them sort of ad hoc with yield in Python 2.4 and send() in Python 2.5. I think Python is by far the most popular language with any kind of coroutine. Coroutines aren't very popular or well understood.
GO puts it as a first class citizen in the language. Other languages might call it Actor, light weight thread, fiber, task, etc. It's popular in embedded systems to implement cooperative threading using coroutine due to its simplicity and low overhead in resource utilization.