Coder Social home page Coder Social logo

Comments (1)

Neverlord avatar Neverlord commented on June 17, 2024

The usual way of coding in message oriented programming is always pattern -> behavior. And what you do is to hide the pattern.

If you are worry about, that your message format might be change in the future, just use a structure instead of "structured tuples" where you're using atoms for context informations.

See the announce_example_1 from libcppa (stripped):

#include <utility>
#include <iostream>

#include "cppa/cppa.hpp"

using std::cout;
using std::endl;

using namespace cppa;

struct foo 
{
    int a;
    int b;
};

bool operator==(const foo& lhs, const foo& rhs)
{
    return    lhs.a == rhs.a
           && lhs.b == rhs.b;
}

int main(int, char**)
{
    announce<foo>(&foo::a, &foo::b);
    send(self(), foo{1,2});
    receive_loop
    (   
        on<foo>() >> [](const foo& val)
        {   
            cout << "foo("
                 << val.a << "," 
                 << val.b << ")" 
                 << endl;
        }   
    );  
    return 0;
}

If foo changes in the future, it does not affect "old" code and if it does (e.g. if you access a member that's deleted from the class), your compiler will tell you. This is what you meant by "type safety", I guess.

The downside of this is, that you can't match against member values of foo, because the C++ type system does not allow for something similar to case classes like Scala. If you try to emulate case classes in C++ you end up coding hundreds of lines of precompiler statements, making your source code just ... bad (this is why I discarded acedia, btw.).

The structure you're using has to fulfill two requirements: it has to provide operator== and you have to tell libcppa how to serialize it (this is what announce does).

from actor-framework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.