首页
Ask HN: Why can't we write a single system in multiple languages?
I hate having to make a choice on language at the onset of a new project. Each language has various great features for certain tasks.<p>I was wondering today why we cannot have some platform which would allow me to call across languages. If we take a basic example and say that I want to have Node/TS and Python files in a single system - what is the most ergonomic / efficient way to do this available today?<p>Why is this concept not more popular? Is this a bad idea?<p>If this is a good idea, what do we need to improve upon what is available today?
4 条评论
PaulHoule超过 2 年前
It is more common today, I think, for people to write the front end and back ends of a web system in different languages than to write them in the same language. For instance the front end might be Javascript or Typescript and the back end could be Go, Java, Rust, Python, C#, etc.<p>The same pattern can be used without the web browser by writing part of the system in one language and parts in another language and having them communicate via a "web service" or similar protocol.<p>Some runtime environments such as the JVM and .NET support multiple languages, so there is no problem with Clojure, Java, Jython and Scala in the same runtime or F# and VB.NET.<p>There are also methods for making calls between different languages in the same address space, particularly I would call out<p><a href="https://cffi.readthedocs.io/en/latest/" rel="nofollow">https://cffi.readthedocs.io/en/latest/</a><p>which is increasingly being used as a model for other languages. That one above makes it very easy to call C functions from Python. When you do this though you run into problems which are sometimes subtle and sometimes not subtle. For instance I worked on a system which combined C++ with Java and used JNI for interoperation. The worst problem I ran into was that you could not use C threads. I also ran into the problem that the gdb debugger would always be catching segmentation faults from the Java runtime because segfaults in Java are a routine condition. So it took some configuring gdb to get into a place where I could run gdb and jdb on the same process at the same time so I could debug both the Java and C++ sides of the system at the same time.<p>Note there is more to it than just having a way to share access to functions and data, you also will need answers for how you will handle dependencies, do builds, run unit tests, run an IDE, for each environment.
评论 #34208973 未加载
pestatije超过 2 年前
You mean something like this?:<p><a href="https://en.wikipedia.org/wiki/List_of_JVM_languages" rel="nofollow">https://en.wikipedia.org/wiki/List_of_JVM_languages</a><p><a href="https://www.graalvm.org/22.2/graalvm-as-a-platform/language-implementation-framework/Languages/" rel="nofollow">https://www.graalvm.org/22.2/graalvm-as-a-platform/language-...</a>
评论 #34208934 未加载
lordkrandel超过 2 年前
Hmmm, are you a developer?
Generally, language is a small part of the choice. Much comes from the ecosystem: libraries, compilers or interpreters, testing environments, CI, CD, licenses, that tend to be different. Multiply the choice and you generally multiply the cost of maintenance. That's why the frontend and backend separation was born and why Node was actually built to try to solve. You have to maintain entire different toolchains.
TotoHorner超过 2 年前
Services Oriented Architecture is the most common way. Use different systems and have then communicate through HTTP or gRPC
评论 #34208899 未加载