Lost in Translation

ducaale profile image Mohamed Dahir ・2 min read

When consuming content, I believe it is best to do so in its original language. The reason being that many important but subtle details are left out in the process of translating that only make sense in the language that it is being translated from.

Programming languages are no different. From the moment of their inception, they are designed to be used in a specific way. Trying to retrofit a feature into a language in an ad hoc way will lead to a code that couldn't be described by anything short of an abomination. Take, for example, lambdas which were not supported before java 8. To emulate them, one had to resort to using anonymous classes which were awkward.

button.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        Toast.makeText(context, "button is clicked", Toast.LENGTH_SHORT);

Could you imagine how much pain someone has to endure to nest several of those? Fortunately, lambda support landed in java 8 letting us write more sane code.

button.setOnClickListener(v -> {
    Toast.makeText(context, "button is clicked", Toast.LENGTH_SHORT).show();

Another example is railway oriented programming. There is this wonderful post which explains how to emulate either monad in javascript. The only problem being javascript not supporting either Typeclasses or pattern matching. This forces the author to use classes instead.

While there is nothing wrong about using classes, I think it fails to show the beauty of the concept that was to be explained in the first place.

What I would advise instead is to search for a language where the concept can be expressed more naturally and then putting some effort into learning it. This will give you more context to why a given feature exists in the first place.

Posted on by:


Editor guide