5

Let's say that I'm a theoretical programmer hunting for a cross platform programming language, what are my options. This language must satisfy this list of requirements:

  • It must not require the user to install extra programs or runtimes (Clarification: I don't mind linking libraries etc. If I can package them with the application. The program must not require the user to install anything to be able to run my game. Basically I just want the user to be able to download my program and run it straight out of the box.)

  • Run on Mac, Windows and Linux

  • It must compile down to an executable, or the runtime be packaged with the executable (E.g. how Love2d allows Lua programmers to create executables, by embeding the runtime in the executable.) The larger size and slower speed is an issue though, so most people would avoid.

  • Free (as in beer)

Preferable but not entirely necessary:

  • Free (as in speech)

  • It can be used to program mobile apps (Android and iOS) as well.

  • Fast

  • Small executable sizes.

  • Mature and stable (as in syntax and the tools surrounding it)

So how about it? If a programmer wants to create a program that satisfies these parameters are C and C++ their only options? Java sort of satisfies these requirements but does require the runtime environment to be installed (Doesn't it?). Are there any languages out there that satisfy this niche? Not necessarily to the same maturity as C and C++ though.

*Edit: I disagree with this question being put on hold, I'm not asking which language I'm going to take up next, which is off topic and subjective. I'm specifically asking about languages that satisfy these requirements, which is not subjective. I'm also not creating a poll, I'm asking for specific pieces of technology that satisfy this list of requirements. The help center suggests leaving a comment here to get it re-opened, so would it be possible to re-open this question for discussion?

J-'
  • 99

2 Answers2

11

You could use some languages with compiled implementations available on all the 3 platforms, e.g. Ocaml or Common Lisp or Haskell or Scheme (or maybe Go, Rust, Opa, Haxe, ...) You could also use implementations which compiles to C or C++ code, in particular Bigloo, Hop, etc.... (At some point Mozart/Oz was doing so)

BTW, notice that even C has some runtime component: the C standard library (libc.so on Linux).

You could also embed some interpreter in your program (e.g. Lua or Guile...)

You might want to use static linking to embed the runtime in your executable. It has drawbacks.

Be aware that a programming language is a specification (often in some English document) which might have several implementations (often, some free software).

It must not require the user to install extra programs or runtimes

I feel that this requirement is ambiguous, very fuzzy and ill-defined: in some sense, when I am browsing any modern site in HTML5+Javascript, some programs (in Javascript) are installed inside my browser (but a naive user won't notice that). And would you accept to have the user download some file once (i.e. getting a self-contained ELF file for Linux/x86-64, or some .exe file for Windows) before using your program? Also, a hello-world C++ or C program requires some "installation" (either compilation of the source code, e.g. for most free software, or downloading a binary executable which will be specific to the user platform). BTW, even in C or C++ you can have dependency hells, such as DLL hells.

addenda

Notice also that with C or C++ on POSIX like systems (typically Linux) you could consider meta-programming : you'll write a program in C which sometimes generates some C code (in some temporary file), and ask the C compiler to compile that new temporary file. In so doing you don't require anything additional since you already need a C compiler in the first place. So if you generate /tmp/emittedcode.c in your program at runtime, you would run (e.g. using system(3) or popen(3)...) a compilation command such as gcc -O -Wall -fPIC -shared /tmp/emittedcode.c -o /tmp/emittedcode.so which produces a shared library that you could dynamically load using dlopen(3) and retrieve symbols in it using dlsym(3). With care you'll find equivalent API in Windows (or use some toolkit like Qt or Gtk which is wrapping them, providing some common dynamic loader API which would be the same for every supported OS).

Also, consider using some JIT compilation library like GCCJIT, libLLVM, libjit, lightning, asmjit, ... You could use them to develop your own language implementation (or consider compiling to C) or just generate useful code at runtime.

5

If it can run in a browser, then JavaScript is available, as well as languages that compile to JavaScript like Dart, CoffeeScript, ClojureScript, and TypeScript. These are your only good choices for running on mobile devices as well as desktops and Chromebooks.

For compiled desktop apps, there's Go. At a less mature state, there's D, Rust, and Nim.

Jerry101
  • 5,447