C++ Challenge: SimpleServer API

This week I’ve prepared a little challenge in C++ programming. The example is not extrodinarily complex, but not completely simple either. The purpose of this example is, to challenge myself a little to get to know boost::asio networking, and to contemplate about how simple APIs for prototyping could look.

So the challenge is to create a class, that allows prototyping simple network servers, by implementing a convenient base class. The interfaces and base classes are already layed out, including an example that send the reply “Hello” for any incoming connection.

The specification is a bit open, and is not so much concerned with corner cases. So using the simplest solution possible is probably the right thing to do.

Ok, here we go for the boilerplate: read on, I will add a few explanations below.

#include <string>
#include <functional>
#include <iostream>

class IConnection
{
public:
    typedef std::function<void(const std::string& str)> send_function;
    virtual void receive(const std::string& str) = 0;
    virtual ~IConnection() {}
    IConnection(send_function send_) :
        send(send_) {}
protected:
    send_function send;
};

class IConnectionFactory
{
public:
    virtual IConnection* create(IConnection::send_function send_) = 0;
    virtual ~IConnectionFactory() {}
};

class HelloConnection : public IConnection
{
    public:
        HelloConnection(IConnection::send_function send_) :
            IConnection(send_) {}
        void receive(const std::string &str) {
            std::cout << "Received: " << str << std::endl;
            std::cout << "Sending Reply: \"Hello\"" << std::endl;
            send("Hello");
        }
};

class HelloConnectionFactory : public IConnectionFactory
{
    public:
        IConnection* create(IConnection::send_function send_) {
            return new HelloConnection(send_);
        }
};

class SimpleServer // <-- IMPLEMENT THIS CLASS!
{
    public:
        SimpleServer(int portno, IConnectionFactory *connection_factory) {}
        void run() {}
};

int main(int argc, const char *argv[])
{
    SimpleServer server(1234, new HelloConnectionFactory);
    server.run();
    return 0;
}

So, it goes like this: IConnection is the virtual interface for implementing a connection. That is, for every new connection, a new instance of an IConnection implementation is spawned, that is bound to that connection. When the connection is closed, the instance is deleted.

The IConnection receives a function pointer as argument, so that it can send replies. You can see how this is supposed to work in the example: “HelloConnection”. That example simple prints the received string on stdout, and sends “Hello” back.

SimpleServer is the class that you need to implement, here you can have all the bookkeeping, and you are probably going to need some internal connection class, that handles  each socket created, etc.

Anyways, I will probably be implementing the SimpleServer myself this week, so I might be able to post a follow up with a solution.

But anyways, this task is simple enough, that a veteran C++ programmer should be able to do it. And it is definitely intended as a practice to work one ones programming skill, so go ahead and try it.

Post your solution in the comments, or send them via email: richard.spindler@gmail.com

If you send via mail, I will add your solution to a follow-up post. :-)

Have fun,
Cheers
-Richard

Posted in Programming | Tagged , | Leave a comment

Managing C++ libs with CMake ExternalProject and Git

Writing modular software, you might sooner or later come into the situation, that you have some functionality, that you want to share between different projects. Let’s say, to have built a couple of convenience classes and function that you want to reuse.

There are different ways to skin the cat, one of them might be using a dedicated C++ dependency manager like Biicode. Or a general package manager for your platform of choice, like apt-get on Debian and Ubuntu, or Homebrew on OSX.

Usually you will start with putting your module or library into a git repositry, if you haven’t done that already. For Code that I want publish publicly, I usually choose my github account.

Now for creating a homebrew package, or a debian package, you either need to create some project description, a bit of boilerplate, and need some platform like launchpad to publish packages. Or in the case of biicode, you need an additional account at another platform, and you have to install another tool.

However, there is another approach, that uses software that you probably already have, and that is CMake and Git.

CMake has a functionality called ExternalProject_add, which can use, to automatically check out a git repository, and build that as part of the normal build process.

Of course, the same functionality would be possible with git submodules, but honestly, I always found this part of git rather cumbersome, and unnecessarily complex, for what I want to do.

So, I’ve created two small examples, that show how to create a small library, and link to it through CMake ExternalProject_add:

The first one is the library: cmake_simple_lib

And the second one is the project that uses the library: cmake_simple_demo

I hope you find that useful.

Cheers
-Richard

Posted in Programming | Tagged | Comments Off on Managing C++ libs with CMake ExternalProject and Git

The decline of the hierarchical Organization in Popular Culture

Being a fan of the popular Space Saga “Star Trek”, and especially of the “Next Generation” Enterprise with Captain Jean Luc Piccard, I cannot help but notice the stark discrepancy in tendency to currently popular Television Series.
Star Trek and the Star Fleet is largely based around a huge hierarchical military organization. The chain of command is clearly defined, the captain receives orders from Star Fleet, the first officer respects orders by the captain, and everyone else respects orders from the first officer and the captain and so on. But it does not stop there, there are further roles within the organization, that supplement the strict hierarchical order. There is the doctor and the counselor, both of which are below the captain, in the chain of command, but never the less can override the will of the captain as experts, should they decide that the captain is incapable of fulfilling his obligations because of a medical or emotional condition.

In a way, the structure is laid out almost like a game of chess, where different roles have different advantages and disadvantages that can override each other in complex scenarios, making strategic games possible, and interesting.
I regard Star Trek as a historical artifact, that allows us today to take a peak into a system of cultural thinking an expectations that has changed not so long ago. A TV-Series is in a way a reflection of the society that created it, and a reflection of the society that were its primary consumers.

And in comparing the series to todays popular television shows, I cannot help but notice quite a stark contrast. So I keep asking myself, what has changed. What has changed in the perception of society in the perception of writers and producers, as well as consumers that made such a change inevitable.

Of course, there are series that contain plots that are concerned with hierarchical structure, and military organizations, Game of Thrones being the most prominent one that comes to my mind. But the topic of this series is never to indulge in the intricacies of a hierarchical organization, but rather to wreck havoc in every possible way of backstabbing and killing leaders and moving hierarchies around.

This is in stark contrast to the Star Trek series, where the concept of the structure of Star Fleet is never questioned as such. It is accepted as a de facto institution. The game is about how to work within the confines of this structure, and seldom and only in far and in between edge cases to question Star Fleet structures as such. So that does happen, but it is the exception, rather than the rule.

And if a series is not about wrecking havoc and creating intense drama and violence, it goes of into the other end of the spectrum.

Take all of the popular sitcoms, like Friends, How I met your mother, Big Bang Theory, The office and probably some more. These Series feel more like a kindergarten of childish innocence. The characters trapped in a Hell of Douglas Copelandian Nihilism. Nothing is serious, everything is wrapped in layers of self-depreciating sarcasm and cynicism. The Brave new World, everything is fun and games, and nothing is serious or important. The topic is no longer about creating great things, and exploring unknown territories, but rather it is about cuddling up in a warm and safe nest, and exchange pleasantries with ones fellow inmates. Every screwup can be shrugged of with a joke, and every tragedy with an outbreak of over acting dramatization, often about not much more than spilled milk.

Contrast this with seriousness of uncomfortable conversations between the leading officers of the Enterprise. Where they spend time pondering how their next move will be perceived, and whether it is moral and ethical to proceed in a certain path. Whether it is a viable tradeoff to insult the feelings of an adversary, or even if stall or a bluff is an appropriate response. None of those Strategic meetings are taking place in modern TV.

Is it that people have changed, that desires and goals have changed, or maybe it is our perception. The idea that we are no longer seeing us as serious and important in the things we do. That in fact the seriousness in which Jean Luc Piccard and his mates acted were overacting devoid of any resemblance in the real world, where all is actually fun and games.

Well, that is probably for everyone to decide for him- or herself.

Posted in Allgemein | Comments Off on The decline of the hierarchical Organization in Popular Culture

Group Ritual Design

What makes a good climbing group? In a way it is the process of working together as a group, that actually creates the group, or that contributes to group learning.

But the same is true for any good work group. People work together on a challenge and through the challenge they learn how to work together.

Designing these kind of experiences is usually difficult. It is easier and can happen in situations that are arranged in a play. Like for example a climbing garden, there is a predetermined Course, with constructed obstacles, that are clearly designed to be challenging, but not too difficult or dangerous. There is a guide, and there are safety lines installed, that are controlled and solid.

The experience of going through that obstacle course is similar of a challenging group experience, but because it is prepared and limited in time, it is safe for the participants.

Developing an unlimited challenge is more difficult, because first of all it needs to be decided whether it will take place within the professional part of the participants time, or within his leisure time. If it takes part in his professional time, some argument of economic viability needs to be constructed. And for the leisure time project, the activity needs to be at least attractive and stimulating enough, to be considered of value to the participants.

What makes the process attractive could be rewards in the form of respect and validation within the social group.

What is needed to get at least some group coherence is a form of interaction. Those interactions could happen during regular meetings, while practicing together, a play or an act. The interactions could also happen through phone or email, when the topic is more of an abstract matter.

There is also the question of how much time should be spend in interaction. For some kind of sports on an amateur level, one or two hours each day can be enough. In the workplace 8 hours is considered adequate, however, not all of this time is usually spent in interaction.

What is also important, is the have the right intensity and variation of interaction. When the goal of the group interaction is to learn or improve a skill, then intense practice is needed, but also eventually alone time for the participants, where they can reflect upon their progress, and then again collective gatherings of reflection might be helpful as well.

The meetings and gatherings are conducted is a matter of ritual, and ritual can either be accidental and informal, or structured and preplanned. Both are valid approaches, and both can fail or work in different ways.

Usually when it is a physical meeting, it happens in a room, and there is a date and time, when the gathering happens.

The room already provides a setting, there might be chairs, suggesting the meeting will be conducted sitting, the chairs might be arranged in a circle, or facing a conductor in the front. This already sets a mood. Or the chairs me be stacked in a corner, suggesting that the participants themselves should choose an arrangement. There might be a carpet and sitting-cushions, inviting the participants to take a seat on the floor.

There are very different modes of acquiring status within a group, in some groups the publishing of a written paper is an adequate form of expression. The paper has to conform to a certain writing style, and it has to fit into a template, that is set up for the occasion.

In other groups the mode of expression means taking part in a competition, pitching one member of a sports-team against a member of another team in a duel.

And all those group interactions and modes of operation are codified into some set of ritual, and as the popularity of groups or rituals spreads, rituals get copied and adopted. Like the Gene-Pool, they become part of the Meme-Pool.

Popular Memes multiplying, mutating, and unsuccessful ones disappearing.

Posted in Uncategorized | 2 Comments

A primer for an abusive relationship

As I am going to a variety of recruiting processes these days, I happened upon one interaction that stroked me as particularly odd.

Many software companies have some kind of programming puzzle as part of their screening, sometimes before the first meeting, sometimes during the meeting. Most of the times it is a perfectly reasonable task, and I understand the necessity to find out of somebody has actually a basic knowledge of computer programming.

And as I solved one such programming puzzle, (and a quite intense one, it took me the better part of a day, to implement the solution according to my interpretation of the criteria) I submitted my proposal dutifully, and expected one of the following replies.

Either:

  • You solved the problem almost up to our expectations, there are a few minor issues that we disagree with, but we will invite you for a meeting anyways.

or:

  • Your solution was pretty good, but not es meticulous as we would have liked, therefore we are not going to invite you for a meeting.

Both of those answers I would have seen as fairly reasonable.

However, what I got as a reply, was something along the lines of: Your solution was quite ok, but there is one other thing that we would have liked to see, we won’t tell you what that would be, but we give you another chance to resubmit a revised solution.

Keep in mind, that this was quite a complex task, and coming up with the initial proposal took me almost a workday.

So I will tell you a few things that this replay contains for me.

First of all, I see a communication-pattern, that is an indicator of abusive behavior, and that pattern is telling people that they did something wrong, but not telling them what they did wrong.

So maybe, that was an oversight, maybe they thought of themselves as very generous for giving me another try at their puzzle. However, what I see is an organization that likes to assign blame, and prefers not to advance an interaction, but would rather hold back information and stall the communication. And either they do this intentional to include some test of submission into their screening process, or they are not aware of this dysfunctionality and are ignorant of patterns of abusive behavior.

I am not sure what is worse.

And exposing this kind of interaction already early in their screening process, will prime employees that go through this application in a certain way.

There appears to be no respect of a workers time, solving the task took me a day, and revising the solution, probably might have took me another day, and even then, I might not have thought of the issue that they would have liked to see. So they are willing to have a potential employee work for two days on a task, without an effective feedback loop.

And they knew it would take a day, because they announced that before sending me the task.

Telling people that they did something wrong without identifying what they did wrong, primes for insecurity. So anybody who goes through this process, will be prepared to endure quite some abuse, because everybody else probably did not go through all that.

Maybe this is the kind of employee they are looking for?

In any case, that should not have happened, what I guess went on, is that the programming puzzle is from engineering, and they gave it to HR, then HR forwarded the solution to engineering, and the evaluated it and send the aforementioned reply.

At this point however, HR should have spotted the tone of the answer and could have decided to alter the statement to be less of a hint of an abusive organization.

In the best case, HR was to inexperienced to spot the problem with this reply. And therefore I got an insight into the engineering part of the company, that should have been shielded from the outside.

However, when these are the communication patterns in engineering, I am in doubt whether I would like to work with such people.

What would you think?

Cheers
-Richard

Posted in Lifestyle Skills | Tagged , , , , | 3 Comments

How the Fossil DVCS solves the privacy problem of cloud based applications

If you do not know what a DVCS (Distributed Version Control System) is, just think of Git, the popular source code management system used by the Linux kernel.

But it is quite different from Git, and seems to solve a couple of problems, that always left me a bit unsatisfied when dealing with Git. In fact, it seems to give me the same nice and warm feeling I got from using the Darcs DVCS back in the days.

I will start out with a couple of issues I had when using git that I experienced recently.

1) For many developers today, when they say they are using Git, they are in fact using github.com a service that has Git in its core, but provides a number of additional services. A nice webinterface, a ticket tracker, a wiki and probably more that I am not yet aware of. However, while the product and concept is well executed, it is still a hosted solution, and while you are using it, you are dependent on an external company to provide this service.

2) I’ve been trying to replicate a similar service that github.com provides on my own machines, and experimented with software like indefero and phabricator, but those solutions leave quite a lot to be desired. InDefero for example provides both a wiki and a ticketing system, but now I have the following problems: I have to provide a MySQL Database for the wiki content, and the ticket system, that needs to be maintained, updated and backuped. Which is kind of a headache, especially considering the nice solution that Fossil is providing.

3) There are various variants of git based wikis that I’ve tried, but installing them and keeping them running is almost always a nontrivial issue.

4) Overall, using git without relying on 3rd parties to manage various aspects of the deployment, is almost impossible, or creates quite a lot of busy-work. I only quite realised that when I came across the ingenious solution that Fossil came up with.

So lets see what Fossil does that makes it so nice. It is quite simple:

Fossil stores Tickets and Wiki data within the repository. And not only that, it comes with an integrated web interface, to conveniently use this ticket system and wiki. And said web interface can be easily made available on a public website.

These choices enable a couple of convenient side effects. Whenever you have a checkout you automatically can easily use wiki and ticket system offline, and once you push to the shared repository everything is update again. Great for using it on the road without internet access. Also, makes keeping a backup of the complete project way easier.

Makes for a much more resilient and independent tool, way better suited for the lone hacker and his small crew. Hosting is trivial, you can setup a private server, or use any kind of virtual server hosting.

In fact, I like that concept so much, I am already thinking about what kind of webapps could be “unclouded” with such an approach as well. Using a distributed versioned database that keeps a complete local backup and only needs to resync periodically to the master host.

Maybe it would be possible to extract some of the Fossil infrastructure and bake it into a general web framework. Or build something similar for different kinds of webapplications.

Have fun,
Cheers
-Richard

Posted in Uncategorized | Comments Off on How the Fossil DVCS solves the privacy problem of cloud based applications

A new way of thinking and risk assessment

If you haven’t started reading the ribbonfarm blog I strongly urge you to consider reading it, because I find it to be on of the most pleasurable blogs right now. Venkats writing is very precise, and he manages to explain even very difficult concepts clearly and easily understandable.

But he is not the only lonely writer to be working on these ideas. There seems to be quite a trend of going into systems thinking and finding ways to incorporate risk and probability into every day decision making.

"The Black Swan" by Nassim Nicholas Taleb started that discussion in popular literature, followed by "Antifragile", by the same author.

But also "The World Until Yesterday" by Jared Diamond devotes a chapter to discuss the topic of risk assesment. And then most recently, Scott Adams published his book: "How to Fail at Almost Everything and Still Win Big", which goes on to discuss the idea of systems thinking on a more practical level.

And to be frank, I feel that I can apply this kind of thinking at a lot of situations. It is as if everywhere I look systems thinking could improve something or indeed does improve things for me already.

Have fun,
Richard

Posted in Discipline and Knowledge, Lifestyle Skills | Comments Off on A new way of thinking and risk assessment

Engineering Managers Should Code

Hi Everyone, in this post I just want to direct your attention to the following article at Dr.Dobb’s:

Engineering Managers Should Code 30% of Their Time

Of course I really like the article, and I agree to that statement. And I want to keep this as a reminder for myself on this blog. 😉 And I also think it fits really well with some of the articles that I have written recently.

Have fun,
-Richard

Posted in Uncategorized | Comments Off on Engineering Managers Should Code

Building a virtual Software Company

Roles and Infrastructure
So let’s build a virtual software company. That is, a company that creates and sells software. While this kind of effort might be possible to do alone, to make it a bit more interesting it will be designed as a collaborative effort.

One idea of collaboration is to pool resources, and exploit the removal of redundant effort. This will be one motivation of that idea, but the other part will be that of a learning/teaching opportunity. Knowledge transfer if you want to call it that.

So in a highly structured effort which software development is, lets define a few roles, that might be worth considering.

Plumbing
Sets up Servers, installs operatingsystems, configures the routers. Eventually DNS, Firewalls, etc.
However, as cloud services, vservers, etc. are somehow a commodity, I’d prefer to keep these tasks to a minimum or outsource them entierly by using some service.

Mail Master
That role will be neccessery, even if it is decided that the company will use an external service for email. But someone has to add new teammembers, so this role will be admin for Email. The role could include setting up an email server on some virtual machine. Eventually the company will be sending out some kind of newsletter to customers, so somebody needs to take care that mail gets out. If a Newsletter Service is used, that role will include configuring that service.

Additionally, that role will likely include setting up and maintaining test-email accounts at various freemail providers, to make sure that mails go through to them unharmed, if custom email systems are deployed.

Web Master
That role will essentially do the same thing for web as the mail-master does for email. It will include setting up webspace, provide ftp-accounts, eventually installing and setting up apache, etc. If some kind of external Hosting Provider is used, and that should be done, this role will take care of manning the web hosting control panel.

Eventually the Web Master will also make sure that there is webspace available for having some kind of testing stage, when web application changes are rolled out.

And if the kind of software that the company is providing is web based, then there will be close collaboration with the next role.

Devops
Development operations is kind of the glue between web master and programmers. Devops basically provides and maintains tools for programmers. This role will be doing nightly builds, will make sure test suites are run, will make sure git repositories are available. They will be packaging applications, upload them to the file area, etc. They will also install the applications that the programmers create. They will maintain the tools to continously collect code metrics.

They will install development tools on virtual machines, and set up images for build servers.

Web-Programming
This role will be doing the actual programming, and that is for web applications. This means both, public facing widgets that are on the web site, signup-forms, databases, cms-tools, crm-tools. The application that is being sold, and internal tools that will support other parts of the business, may it be a company adressbook, wiki, or whatever.

The job of that role is to commit stuff to a git repository. Whatever is being used as development environment is up to the individuals, as long as coding conventions are followed, unit-tests are maintained, etc.

App-Programming
While related, the advent and wide spread adoption of smart phone app markets has probably made it necessary to have some of those as well, so this group will be working on that. Devops will be creating packages and submitting them to app-markets. App-Programmers will submit code and tests to git.

Design
This role will make sure that programmers do not lose focus. Here Application workflows will be created, and layouts will be sketched out, and later refined. This role will probably work closely with programming. Much of this role will also include making sure that the programmers go all the way through and implement clean validations for forms, that everything is pixel perfect and not thrown together.

Last words
And finally, don’t get me wrong, every role will be programming, mail-masters, web-masters and devops won’t be doing their tasks by hand, they will be creating scripts and control panels to streamline whatever they find themselves doing. May it be shell-scripting or automating a service via an API.

The idea here is to have some “easier” tasks, that youngsters can get their hands dirty, while creating some automation that will allow them to move up from their roles and graduate into more interesting fields.

Posted in Uncategorized | 4 Comments

Using magical practices to work with large code bases

A large and legacy code base, can sometimes be like a collection of mystical documents, they are riddled with number magic, cryptic references, mysterious rituals and descriptions. Some are are guarded and governed by old masters, that are grumpy and quick to dismiss any newbie asking for access to their code. They answer in muffled mumbling, and are easy to anger.

Also, the habits and customs with which the guardians of the old code work with the code, interpreting it continuously, rewriting it, trying to understand it, very much matches which how I would expect a magical order to be working through old manuscripts trying to recreate ancient rituals.

However, many of the maintainers of old code do not necessarily indulge into this kind of self reflection about their work. They tend to be governed by fear, from failures in their code, from changes in certain “mythical” parts, from confrontation by their superiors, or by the choleric masters of certain rooms. The strategy to deal with those challenges is often a form of rationalizing, which includes denying how emotions and relationships might influence the code. Communication is often channeled into ineffective rituals, including meetings with no results, and throwing around jargon that aims to hide, what needs to be said, because of lack of a common vocabulary. The value of deep and completely open communication in such endeavors is often completely neglected, and there exist no mechanisms to facilitate such communication.

Part of this phenomenons is often a very deep focus within the programming community on “rationality”. The programming community prides itself on its reliance of “facts” is composed largely of atheists, and in general people who keep a high nose, in respect to religious, mystical, esoteric practices. Everything that carries even a scent of “softness”, is immediately thrown into the corner with hocus pocus and fairy tale magicians.

Those prejudices are unfortunate, because some of the techniques of working with mystical and old manuscripts and ancient rituals, might be quite well suited to deal with old and difficult to understand code.
There might be complicated code bases, that deal with legacy functionality and complex algorithms, that are quite well understood by their teams, and those teams might dismiss this quite “esoteric” approach. And maybe for those well oiled and effective teams, it might not make any sense indeed.

However, there are teams, where I believe much healing needs to be done, misunderstand needs to be cleared up, and honesty as well as understanding needs to be fostered. Often this also goes along with a feeling of exhaustedness, mistrust, and aggression. Team members tend to withdraw, and build walls around them. And in such cases, I believe magic practices and experiences might come in useful, to help resolve those situations.

I also believe, that industry practices, which are often described in books and are believed to be easy to apply by practicing the theory often fail to work. Which is because the required self transformation does not take place. Those industry practices often even fail to mention the necessity of transformation, rather the indulge into detailed descriptions of their “rituals” and artifacts. And therefore they fail to create a conscience for spiritual development in the industry.

This actually is a common pitfall of many industrial and developed nations in which the dominant mainstream consciousness is based around the notion of consumerism. The consumer-culture, that often promises happiness and success, to be tied to objects and artifacts that can be bought. Like to better computer, or the faster bicycle, or any kind of more effective product. However, the fact that growth results from discipline and from transformation of the inner self, and not from buying arbitrary artifacts is seldom communicated and highlighted.

Even advice that goes into building teams and software companies always starts at the point of selecting people based on their psychological qualities and their ability to work and communicate together. It start with the notion that some people simple are mature enough to engage in the art, and some are not. Without elaborating on how people, who might not yet have the required maturity might acquire it. It deals more often also with the suggestions of how to remove “poisonous” team members rather than how to inspire them to grow. Sure, some people might effectively work against such efforts and sabotage them, but those that can be reached, should be.

And here comes in what I believe magic (or magick) could do for the development of programming as a craft and art form. Especially, because something that is seen as “wishy-washy” and arbitrary and be members of the programmers community, and especially because it would evoke quite an emotion and foster discussion. In a sense it is a provocation. It would rattly things up.

And therefore it would require quite some questioning and reflection about ones art.

What I failed to mention in this article is mentioning some concrete techniques. This is intentional, and the entire point, what I suggest should not necessarily and even could not be learned by reading an article on the Internet. It should be developed, and learned in communities, by reflection, coaching, mentoring, and self discovery. We are just at the starting point of this journey. How could I know where it ends?

Take care,
Cheers
-Richard

Posted in Uncategorized | 4 Comments