Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

And CSP is trivially implementable using the Actor model. What's your point?


Depends. I would argue that e.g. Go's CSP approach is not implementable on top of Akka, since actors there are not allowed to block on reception of single message. They will always get messages pushed, so the blocking Go concurrency constructs can not be built on top of it. It's obviously slightly different with Erlang, where Actors can block.

I think the basic Actor definition does only say that Actors need to send messages to others, but not whether they can block on reception of selected responses. So it might be a bit undefined.


Lack of blocking support in runtime cannot prevent you from implementing waiting. Either through higher-order event driven code or just plain busy-waiting style message exchanging until you receive your message.


Busy waiting won't work, since there will potentially never run another thread that changes the thing you are waiting for (that's why e.g. in JS everything needs to be async). There might be ways to model things a bit different (like using Promises and other monadic abstractions), but things will never look the same as in a blocking environment.


It's a model, it doesn't matter how it looks.


My point is that you can program with the actor model in Go, if you want to.


You can program with it in C, if you want to.

But Go is clearly not designed with that in mind. It's a language that is very opinionated about how concurrency should work. And so whether it's a good opinion or a bad opinion becomes very important.


The actor model in Go looks like this:

    type actor struct {
        c chan message
    }
    
    func (a *actor) foo(...) {
        a.c <- message{...}
    }
    
    func (a *actor) run(...) {
        for {
            select {
            case msg := <-a.c:
                a.process(msg)
            // ...
            }
        }
    }    
This is perfectly idiomatic Go for a large class of problems. Therefore it's not correct to say that "Go is clearly not designed with [actors] in mind."

To be fair, it is probably correct to say that Go provides CSP natively, and leaves actors to be implemented by the programmer, and that this "hierarchy", that CSP makes a better foundation for actors than vice-versa, is an opinion codified by the language.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: