I need to write an extremely lightweight program (trying to get below 8Kb) that performs some simple math. The language also needs to be platform independent. Which language do you think would work the best? (Oh, and no frameworks allowed.)
c or assembly (though you'll need to compile for each platform)
TCL is a scripting language that's cross-platform (not sure how lightweight it is)
I'd suggest Java but the VM probably thrashes your size requirements
Would browser based JavaScript be an option? Lightweight and runs on almost all platforms via browser.
Not sure what you mean by framework??
python
why?
- It comes installed on my linux distributions, OSX and can be packaged as a native executable on windows. In other words the user of your app won't have to install anything
- It's really easy to learn.
C. Of course you need to compile separately for each platform, but other than that, it's quite light, and platform-independent (or multiplatform, whichever expression you prefer).
Which platforms are the program targeting?
So far, we have the following requirements:
- Program must be under 8 kilobytes.
- Must be platform-independent.
- No frameworks allowed.
Here are some questions:
- Can the 8 KB program be a script for a scripting language?
- How big can the runtime environment for the program be?
- Should the program be native code on its own?
- Which target platforms should the code run on?
- Is cross-compiling the code for each platform an option?
The questions that I've presented are going to affect the desirable options. If the program must be 8 kilobytes with the runtime environment, then there really isn't much of a choice other than compiling against the target environment.
If the target is an embedded device, or non-x86, then its likely that the choices will be further restricted. Small embeddable langugages such as Lua can still be used (written in C), but that would require a fairly large "runtime" for the script to execute.
If cross-compiling to the targets are an option, then writing a program in C and compiling to each target platform will probably yield fairly small native programs.
With the current requirements, there are a few questions that need to be addressed in providing a good comprehensive answer. Other than that, the best that can be done is a brainstorming of options that may or may not lead to a desirable solution.
Bespin from Mozzila is an online environment. So it is, by definition, platform independent. Try at https://bespin.mozilla.com/
Even C requires a runtime. Only realistic answer to this question is dc, or even a custom calculator that executes scripts, implemented in C. (Such a calculator could be smaller than dc, if it doesn't depend on arbituary precision).
You'd be surprised how much you can get done in less than 4k of Java:
Of course that doesn't include the JVM :-)