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
  • 3
  • 4
    JavaScript. The VM for that is included in the browsers shipped with the platforms you mention. (Even C and C++ require supporting libraries - C and C++ runtime libs - which can require extra installs, e.g. MSVC redistributable packages.) – Mat Feb 09 '15 at 05:42
  • 1
    -1, shows no research effort. – GrandmasterB Feb 09 '15 at 06:23
  • 4
    @GrandmasterB given how many programming langauges exist out there, it is infeasible for me to go out and research each one and classify it based on whether or not it reaches my guidelines. Much easier to ask a question like this to a community of experts who have much more experience than I, is it not? – J-' Feb 09 '15 at 07:10
  • 5
    @GrandmasterB I don't appreciate the snark, I have done research. I've done enough to know that I should be asking people who know more than me to fill me in on the gaps. Please try being constructive next time you believe your down vote is talking for you, because just saying -1, no research effort. Is not very helpful, perhaps you could improve on that next time you leave a comment and not wait until someone asks you further to expand on your little quip. – J-' Feb 09 '15 at 07:45
  • +1 for having the sense to ask others and learn from their experience and not wasting an infinite amount of time researching all decent programming languages – AK_ Feb 09 '15 at 11:15
  • 1
    Why are you looking to avoid all languages that have a run time? what's the point? Basically you can use any language that the GCC can compile... or most things that use LLVM... – AK_ Feb 09 '15 at 11:21
  • What does the program have to *do*, especially interface-wise? As soon you do anything more than printing to stdout you're going to have to introduce dependencies on various libraries that differ between different Linux, Windows and MacOS. – RemcoGerlich Feb 09 '15 at 15:02
  • Sorry, but this is a poll, and polls are off-topic. – Doval Feb 09 '15 at 15:06
  • @Doval How on earth is this a poll? I'm asking about languages that satisfy a list of requirements, that's not a poll. – J-' Feb 10 '15 at 00:02
  • I won't vote for reopening if you don't clarify your question. Your first requirement is completely unclear and ambiguous. So please edit your question to explain what you mean. See my answer.... – Basile Starynkevitch Feb 13 '15 at 10:29
  • @BasileStarynkevitch To clarify what I mean, I would prefer to not have a user need to install anything to be able to run my program (e.g. needing python, lua or java on their system to run it) how would you recommend I clarify that so that nobody else is confused? – J-' Feb 13 '15 at 15:15
  • 1
    OP is probably asking about **Single File Application**, which is quite common. Additional requirement is that this single-file application do not create additional files or modify the system in any way during its operations, i.e. it can be removed by merely deleting the application file. A third requirement is **Cross-platform**, which shouldn't be taken literally to mean "one binary file to rule them all", but rather "one code base that can compile to all platforms" with minimal workaround around platform differences on the programmer's shoulder. – rwong Feb 14 '15 at 03:16
  • @rwong Yes, you have it almost exactly correct. Too many people got caught up with the technicalities and didn't know how to proplerly answer the question. – J-' Feb 16 '15 at 05:38
  • 1
    @Jarod: the onus is on asking the right question, using meaningful keywords. Without the right keywords, it is difficult for others to guess what you were asking. – rwong Feb 16 '15 at 17:13

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.

Basile Starynkevitch
  • 32,434
  • 6
  • 84
  • 125
  • +1 for mentioning Ocaml, Haskell and Common Lisp. You might add Scheme to the list, since there are free and open source compilers available as well, e.g. MIT Scheme, Chicken Scheme, ... – Giorgio Feb 09 '15 at 10:05
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,367
  • 1
  • 15
  • 19
  • @Jarod I inferred from "must not require the user to install extra programs or runtimes" that you want many end users to be able to easily install your programs, and so these need to be production-quality programs. Languages like Go and Dart are good for that. Research languages like Haskell and Scala are not -- they change rapidly and contain many experiments that didn't pan out. I mentioned that D, Rust, and Nim are currently less mature because they aren't yet ready for broad production applications. – Jerry101 Feb 10 '15 at 02:00