google / google/codeworld

Creating a new explicit message-passing mode

Open
#383 9 comments 0 reactions 0 assignees View on GitHub
discussion
Dominant language
Haskell
Stars
1.3k
Forks
201
PR merge metrics
No merged PRs in 30d

Description

A new collaborationOf mode could use the message relay server introduced with the gameOf mode to relay user-defined messages instead of Events. A new data type Message should be provided by CodeWorld to the user, like this:

```
data Message = TextMsg Data.Text.Text | IntMsg [Int] | DoubleMsg [Double]
```

Providing both a text payload and a list of numbers payload would reduce the need of having heavy parsing in the client code, while still avoiding having to implement serialization of arbitrary data.
The idea is to have clients being able to send and receive data as simply as possible, so that it does not
require much extra effort from students. My initial use case would be visualizing parallel algorithms to do matrix computations, so having the protocol handle list of numbers without extra work on the client code would be really useful.

The collaborationOf function should be something like this:

```
collaborationOf initial step event picture numParticipants send receive
```

The first part (initial,step,event,picture) would be just like interactionOf. Keyboard and Mouse events would be local to each client, and they would be handled by the local event handler.

The communication between nodes would be handled by the new functions send and receive:

```
send: State -> Maybe Message
receive: LocalId -> RemoteId -> Message -> State
```

The function send should be run by CodeWorld periodically after each update. The function receive would be run when a message is received, similar to how the event handler is run for local events.

The users would be responsible for writing the code for send and receive, just like the others (initial,update,handle,view). If the output of send is Nothing, no message is generated. Otherwise, the
message is sent to the relay server, which broadcasts it to all the nodes. Each node would receive the message along with their own node identifier and the identifier of the original sender of the message.
The function receive would use that information to update the local state as needed.

I think this mode does not require much extra work over the current gameOf, but it would make it more flexible, as it separates events that should be handled locally from those that are sent over the network in a way that is completely controlled by the client code.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.