2

Maybe I have misunderstood this concept. But is it common, when developing the backend to an app, mobile or web. To first write it in a high level programming language such as php, python, javascript to quickly develop a working prototype with fewer lines of code. And then if performance becomes a priority rewriting the app in a low level language such as C or C++?

  • 1
    Script languages are not what I would call a higher level language. And I wouldn't call C++ a low level language either. – Christophe Jan 4 '18 at 17:02
9

If an application needs to be optimized for performance, you don't rewrite the whole thing in a different programming language. Instead, you profile the application, find its "hot spots" (the code where the program is spending most of its clock cycles), and rewrite only the code in those hot spots. Generally, those hot spots will comprise 10 percent or less of the overall code.

In practice, it is uncommon to change programming languages mid-project, because languages are commonly chosen for their applicability to the problem domain. Web applications are written in web languages because they run in browsers and web servers, and because most of your time is spent waiting for networks and databases, not crunching numbers. Games are not always written in such languages, because there are languages that are better suited to the gaming domain.

  • A game might be written in two parts, with a high level language doing the "what meshes to draw with which textures", and a low level language doing the actual drawing, etc. This may be presented as solely the high level language with a "3D graphics" library – Caleth Jan 4 '18 at 16:41
  • @Caleth: Sure. This is just the broad brush strokes. – Robert Harvey Jan 4 '18 at 16:48
  • Oh I agree. My comment was more an example of the "pick language based on the problem domain" process having "surprising" results – Caleth Jan 4 '18 at 16:55
  • @Caleth Don't worry about the horse going blind,just load the wagon. – quintumnia Jan 4 '18 at 19:27
3

It's certainly not uncommon to write a prototype implementation when in an exploratory phase. I would bet the vast majority of such prototypes are written in the same language as the language used for a rewrite (which often never comes). Similarly, the language used for either part is likely determined by the local culture of the company implementing the code rather than "performance". No one is going to use a language they are not familiar with to write a prototype just because someone says it's "good at prototyping", at least not for critical functionality. Language choices are almost always predicated on familiarity.

As Robert Harvey states, usually programs (or really systems) are rewritten piece-meal, not all at once. Usually there are "hot spots" that can be rewritten in the same language or potentially a different language that will provide the needed performance gains. A whole rewrite for performance reasons would typically be after all the obvious "hot spots" were addressed, and an attempt to optimize the current code. Rewrites may also happen due to changes in the project's culture.

There have definitely been several public projects that have been rewritten from "high-level" languages to "low-level" languages, but it's often not clear what the motivations are and rarely are they solely performance. They may not even include performance. It's not clear how often this actually happens overall though. Again, culture likely has a dominant influence. For example, one of those examples is a project Paul Graham wrote in Common Lisp that was used by Yahoo for years but was eventually rewritten in C++ and Perl at a point when Paul Graham was not involved with the project.

If a rewrite was to be done with performance as one of the major goals and the current language is a language whose primary implementation is an interpreter, then assuming a new language is chosen for performance, it is likely to be any language whose primary implementation is a (potentially JIT) compiler, not just C or C++. This includes Java, C#, Go, Rust, O'Caml, Haskell, even JavaScript nowadays. Again, such a choice is likely to be more driven by familiarity and culture than any objective metric.

  • To avoid that “rewrite that never comes” it can be handy to pick a language no one wants to work with for the prototype. Makes it more likely that the prototype will be thrown away... of course, at the risk of a terrible backfire. – RubberDuck Jan 6 '18 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.