9
Fabian
6y

Which programming languages can create portable programs that can run on every operating system, device, etc. (and are actually intended for that)?

- Java
- Python
- I heard some things about C# maybe…?
- What else?

Comments
  • 2
    Java and Python But they’re both really slow. Thats the price of portability
  • 5
    I don't know about mobile devices, but Go can compile for Windows, Linux and macOS.
  • 4
    Java is slow because of the way its compiled.
  • 2
    And Python is slow because its run with a interpreter
  • 4
  • 2
    @HampusMa Nowadays Python works pretty much like Java, where it is compiled into bytecode first and then run in a Python VM, IIRC.
  • 1
    @TobiSGD Oh i didnt know that. Thanks i guess
  • 1
    @TobiSGD Does the user just install a simple thing like the JRE for Java and then they can just run it? Or does it have to be explicitly compiled for every device?
  • 1
    Well do not take my word for it but GO was built for that purpose all be it, it is mostly a server language.
  • 2
    @Fabian You have to compile explicitly for the different platforms, but since in Go everything is statically compiled into the executable (including the runtime environment) you don't need to install anything but the application itself (where install means: copy it to the machine).
    Currently working on a REST-API for an internal project in our company, the complete binary so far, including HTTP/1.1, HTTP/2 and websocket server is about 12MB in size.
  • 1
    Pen and paper
  • 2
    I guess JavaScript also works similarly? For example I'm running a NodeJS program on my Raspberry Pi with Raspbian right now and I have also previously run it on Debian and even Android and the instructions say that it works for Windows as well. But I've also heard a lot about messy JS setups and other JS weirdnesses on DevRant and r/programmerhumor, so maybe that's not a good choice?

    BTW, context: I'm looking for programming languages that are worth learning. If I don't even know what operating system I'll be programming for in the future, it's better to choose something that can run everywhere. I already know Java and have written a simple script in Google Sheets (uses a custom JavaScript variant), but I've not learned any Python or Go yet.
  • 3
    Any language, as long as you run your app in docker :)
  • 1
    Javascript and .NET Core
  • 4
    @Fabian For Node.js you need the Node.js environment on the machine you want to run the application on. The Node.js environment comes with the V8 Javascript engine from Chrome/Chromium for executing the scripts.

    I personally don't like Javascript and it (or better the V8 engine) is single threaded, which can be a real problem if you have to deal with a lot of concurrent calculations (just I/O, so querying a database or reading a file is asynchronously in Node, so that is fine, but once you start doing heavy calculations on environments that are inherently multi-threaded, like webservers, you might run into serious performance problems).
    Having said that, Go is pretty easy to learn (simplicity is a goal of the language), I would say it is a good mix of C, Python and a bit Javascript, so maybe just give it a try.
    I love the language.
  • 1
    C# when running on .net Core.

    Oh and java
  • 2
    PHP, Ruby, if we count by interpreter availability like with Python.
  • 1
    @HampusMa you can compile python and java is the fastest vm language (look it up, its about a year old article)
  • 2
    @jespersh since java9 i think you can bundle a barebone jvm in your jar
  • 3
    I'm wondering that nobody said C yet which basically runs everywhere (although it is a PITA to make it compile everywhere).

    Also most of you forget that running "everywhere" for most languages means running everywhere where a runtime/interpreter is available.
  • 1
    @TobiSGD just to be sure, python and js are both scripts fed to an interpreter. So if one is a valid answer, so is the other.
  • 0
    I’ve read python is slow, but isn’t java has good performance?
  • 0
    Ruby, Py, Java, JS/Node, ...

    Even C if you write it correctly.
  • 0
    @beggarboy .net doesn't run on Linux. You can somewhat run most programs with Wine/Mono, but it's not just a matter of download+run.
  • 0
    @Fabian I thought .NET Core had UNIX build tools and such available?
  • 0
    Oh wow, so many comments. I guess I should have defined my question better: I'm looking for things that I can just program once, without any change to adjust for other systems or devices (unless I want to do GPU stuff and such of course), and that users can just download and run, as long as they have the corresponding thing, like JRE or Python, installed, without having to launch an IDE or use a command-line compiler or whatever. Basically something that Just Works™. I'm pretty sure C does not fulfil those criteria and Assembly definitely doesn't, both were commented here. This was not meant as "which programming languages do you like". In the best case something where I just say "install XY" (e.g. "Java") and it's intuitive to the user what to do, afterwards they can just download and run the one binary/whatever file.

    So I guess the list so far is this one?
    - Java
    - Python
    - C# probably
    - Go
  • 0
    @ojrask Does PHP fulfil the criteria in my comment above?
  • 0
    @Fabian yup, as long as a PHP interpreter is installed things will work, assuming you're not running exotic extension code. Of course you need to have the correct version, similarly to Python 2 vs. 3, depending on what you want to run. PHP has built-in support for single-file executables as well (PHARs) that you can run.
  • 1
    Dart seems okay, and Kotlin/Native is becoming an option

    ohh, also C++ with Qt if you're up for the challenge
  • 0
    .NET core brings nice cross-platform magic, and you can even bundle the runtime up in the executable with a tool like dotnet-warp.

    The performance metrics they’re getting are pretty impressive too, admittedly it’s interpreted and just-in-time compiled, but unless you really specifically need bare-metal performance you’re fine.
  • 1
    https://docs.microsoft.com/en-us/... @Fabian

    What people don't see is that since they allowed people to make vs code

    and then fucking refactor the csharp framework? thats golden.
  • 0
    @ojrask I know at least that I was unable to get paint.net running, even with complicated Wine setups or Mono.
  • 0
    @Fabian I presume Paint.NET is not written with .NET Core, but .NET Framework, which is Windows specific?
  • 0
    C does work for that setup unless you want to do GUI programming. But since that sucks in C anyway, nobody will do that.

    However, you will need to provide several binaries for the users to download, depending on CPU and OS.

    In order to do that without getting crazy, you will need to design your application in a proper way, e.g. with encapsulating stuff with multithreading so that you can have the Win API under Windows and POSIX threads under Android and Linux. No big deal.
  • 0
    C# on .net core!
  • 0
    @irene Lots of things are Windows-only software, but can still run with Wine.
  • 0
    JavaScript is what you're looking for. Got tons of options there like react native, electron and so on. Stuff runs well and is battle tested
  • 0
    Java isn't slow, wtaf
Add Comment