My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more
Reusing Code in the frontend and backend

Reusing Code in the frontend and backend

Jan Vladimir Mostert's photo
Jan Vladimir Mostert
·Jan 16, 2016

A major selling point for many frameworks these days are the ability to re-use code on the frontend and backend.

NodeJS is quite vocal about this, but they are not the first.

Pyjamas (Python to JS compiler):

Your application's design can benefit from encapsulating high level concepts into classes and modules (instead of trying to fit as much HTML as you can stand into one page); you can reuse - and import - classes and modules.

GWT (Java to JS compiler):

GWT is not an attempt to abstract away the browser from you. Neither is GWT an attempt to prevent you from writing JavaScript when you want to. GWT is simply a way to give us developers some extra leverage in the form of productivity tools and the ability to create higher-level abstractions when it's useful. If you're a JavaScript guru, we hope you'll find GWT is a great way for you to package up your best work and make it easy to reuse.

Scala JS (Scala to JS compiler):

At the Scala Day last week, Sébastien Doeraene presented Scala.js, a Scala to JavaScript compiler. The compiler supports the full Scala language allowing its users to build web applications front to back in Scala and potentially reuse code between the server and the client.

Dart (Dart to JS compiler):

If you want to reuse code between command line and browser applications you should move them into the lib directory of another package my_shared_code where you put only code that doesn't depend on dart:io (for example some entity classes) and import this code from both app packages (browser and command line).

Opal (Ruby to JS compiler), GHCJS (Haskel to JS compiler), SharpKit (C# to JS compiler), Ceylon JS (Ceylon to JS compiler), FunScript (F# to JS compiler) ... they all try to do the same thing, make it possible to re-use your backend and frontend code between each other.

My question, how often do you actually re-use code between your frontend and backend and if so, how much code do you actually re-use? From my personal experience with GWT, there was very little code re-use between the frontend and backend, usually just my validation class which I don't really need in the frontend in any case and sometimes data transfer objects which became obsolete in any case since you can easily go to and from JSON these days.

What is your opinion, Is the whole selling point of code re-use between the backend and frontend overrated?