1 Feb 2017

Reusable Programming Languages

Many programming languages claim to make your code more reusable, but languages themselves can be reusable. In the sense of using languages that work in multiple different situations, rather than just one.

If you're building a backend, there's a benefit to building it in the same language as the frontend. If the frontend is an iOS or Mac app written in Swift, consider writing the backend in Swift as well [1]. That way, you can reuse abstractions between the client and the server. If you're building a notes app, you'd have classes like Note, InlineImage, Attachment, SharingList, and RevisionHistory, which could be coded once and reused between the client and the server.

If you were to build your server in a different language, like Ruby, you'll end up reimplementing these abstractions. Reimplementation doesn't add value — it takes time, introduces inconsistencies and bugs, and increases your maintenance overhead going forward. Besides, there's the effort in learning a new language, keeping up with its evolution, understanding and internalising best practices and coding conventions, understanding the standard library, understanding third-party libraries, learning a new IDE, and so on. Whatever the benefits of another language you could use, it probably doesn't outweigh all these costs [2].

So, if the frontend is an iOS or Mac app written in Swift, consider writing the backend in Swift as well. If your frontend is an Android app written in Java, consider writing your backend in Java. And if it's a web frontend, consider writing your backend in Javascript, in Node.js.

What if you have more than one of these frontends, like an iOS app, an Android app and a web app? Then consider writing your server in one of these three languages — Swift, Java or JS — as opposed to a fourth language like Ruby.

Backends are just one example. As another example, I recently needed to write a script to automate a repetitive, manual task. I chose Ruby over say, bash or some other language, because the time I invest in learning Ruby would later help me build a Rails web app, if needed. And that's something I might do.

Invest in programming languages that you can reuse in multiple contexts, like mobile and backend, or web and backend, or scripting and servers.

[1] Once Swift on the server is production-ready, hopefully before the end of 2017.

[2] If you're sure it does, go ahead and use that language, of course. This might be the case if you're, say, a Rails and Ruby expert, and fumbling your way through Swift or Java to build a mobile app. Maybe you'd then find it quicker to build your backend in Rails than in Java.

1 comment:

  1. Or write your backend in Common Lisp, and use the MoCL translator to generate the common code in C for use on iOS or Android. https://wukix.com/mocl