There are a few thought experiments I've been running through my head for the past few months. The questions that lack importance, given that they've already been answered. I can't help but ask anyway.
Why do languages have their own VM?
For most languages, you are limited to their custom engine. Certainly, programmers have made Ruby, Python and PHP for various virtual machines developed by Oracle and Microsoft. These are popular languages and for popular virtual machines.
The question is more broad. If I want to run Language X, then I need to find interpreter or compiler for my system. If such a thing exists, some of the more interesting languages have poor support for Windows.
My thoughts go beyond simply running code.
Why can't I use library written in Language X in Language Y?
A few things has peaked my interest in this thought experiment of mine. Technically, you should be able to do so using LLVM, given that if you compile to IR for a given language, then you should be able to call into that module from another supported language. There are details that are no simple and the first is that it would require having a reference to that library to know what the call depending on the restrictions within the caller language.
The second is HippyVM, which attempts to provide a VM for PHP using PyPy. One of the long term goals after successfully porting PHP to PyPy is interoperability between the two languages. Where you can call a PHP library from Python and a Python library from PHP. This could change things. Or maybe not.
The problem is the lack of success in Java VM, CLR and LLVM. It is certainly true in the technical sense that you should be able to call another library in another language, because it is after all, bytecode. The truth is that it is not easy and if something is not easy, then it is not often done. My criteria is calling into userland libraries and not built-in types and libraries, which are obviously supported.
Best practices, debugging and programming tools.
In the thought experiment, You have a VM that can run all languages that exist and will exist. In this VM, there is interop between languages and libraries.
So what do you get?
- Debugging tools and libraries that work in one language can be applied to other languages. In this environment, you don't require duplicate effort of porting libraries from one language to another.
- Programming tools from one language could be applied to another. So if you have a tool that formats code based on the VM AST, then could that be applied to another language as well? So formatting code to a coding standard would be as simple as running a command.
- Learning best practices from one language and applying it to another. If there was only one VM to code to, then what tools and best practices might come from it?
DSLs and programming should be easy.
In my thought experiment, I think about the different concepts I've been learning from functional languages. How awesome these concepts are, and if they could be applied to my favorite languages.
I keep thinking back on the Python language and how everything should be as readable as possible. How everything should make sense as much as possible. You should be able to code how you think it should work and most of the time, it should just work. That is perhaps the best feeling in the world.
Yet, there is also a fascination with making code as small as possible using only symbols for most things. I weep when I think about how great functional languages are, but how complicated they are when starting out. There is a great power with Haskell and Clojure that I love and would enjoy.
It is true that with any language, there is a learning curve and I don't believe or at least there is no evidence that it will go away. BASIC and COBOL prove that even with the most simple of all languages, you still have a learning curve.
My point, is that code should be readable while not completely going into the realm of BASIC and COBOL. I'm not sure how to accomplish this and I think looking at Python and other languages that have this goal in mind should give some insights to a possible solution, if one exists.
Haskell does give one possible solution that I want to explore with experiments, if at all possible. Domain Specific Languages, might allow a programmer to provide an intuitive interface to a library as long as building the DSL is not complicated. If creating a mini language was simple, then would more programmers create them to provide an easier way of using their libraries?
It might create a problem where you have too many tiny DSL and programmers have a difficult time remembering and learning them all. It is one possibility and I'm not sure what the solution or if it is even a problem.