If you’re into programming, I’d suggest you read this.
As a developer I’d love if I can write code that anybody can run, on their desktop (as opposed to trying to move it on to a browser so it can be truly cross platform), but let’s just stay away from the operating system in the browser paradigm. Let’s say I want to build an application which would run on windows, mac osx, and linux (and perhaps even bsd, etc). There are three major options I have
1. Write the code in java, and have it execute in a virtual machine. While java is nice, I’m not too fond of having my code run in a virtualized wrapper like format. Moreover, performance concerns, the Java Native Interface, etc do not make this the best choice for me.
2. Write code in a more simplified language like python, or ruby which has language bindings to major system so which allows me to run my code on most systems. This is nice, but there’s the performance concern, the obsfucation and moreover requiring the right version of python or ruby to be installed in the target machine.
3. Write code on C++ with the right cross platform libraries and compile. This is a confusing option because finding good cross platform libraries and learning to use all of them can be very complicated. But this does, however mean that my code will run natively, thus, much faster than the aforementioned options.
My idea deals mostly with number 3. I won’t beat around the bush and get to the point:
1. An easy to use suite of cross platform c++ tools, with open source wrappers to all of them, and are configurable to larger extents.
Here’s what this means. Suppose I needed to build an alarm clock, and wanted it to run natively on all platforms, I first write a “libcollection” file. This will be a list of all the libraries that I’ll be using for the project, and these are sort of dependencies. These might be gtk, wxwidgets, or qt for gui, opengl or SDL for graphics, openal or some other audio library for audio, one particular library for networking, etc, etc. These might also include other details as extra libraries, dlls, per-platform specification, etc.
ALSO, we will have native access to files, operating system, etc, through a vast object oriented library, who’s code will work on all object oriented systems.
The first benifit of this is that there’s a program that downloads the latest versions of all the libraries, and their dependencies, and create a project for an ide of your choice, ready to compile with any supported compiler.
Now the hassle of getting the right libraries is removed, which is only the beginning, as the best part, and an excruciatingly hard part is to write object oriented wrappers for all of these. So for example if I have:
(note this is just a concept and not anyway related to the final code)
File music_file(“asastor.mp3”); // FILE: is a wrapper class
Audio_Decoder decoder(music_file); // An audio decoder
Audio_Output output; // to output audio
decoder.play_with(output); // set the output module.
decoder.playfrom(“1:00”) //play from 1 minute timestamp
Now, you say, sure, there are libraries that can do things like this, even if you present an oversimplified audio, graphics, networking and filesystem interface, there are ways to do this, but the best caveat will be this:
Suppose you are writing code for linux. You’ve set your gui engine to gtk. So instead of writing code for gtk, you write it like this:
Window new(“My window”);
Button click_me(“Click Me!”);
new.Attach(click_me);
Now suppose some code like this would attach a button to a window. While porting code from gtk to another gui engine like qt is painful, it’ll be as simple as setting a simple variable in your library collection file. Of course, the functionality will be lesser than all libraries, as certain features are there in qt that’s not there in gtk but while we cannot hack our way to replicate features, we’ll have to allow ability to add features directly from the libraries themselves.
This would enable to write code once, and have it run almost flawlessly anywhere. Taking what we already know about building good cross platform libraries, and the great many advancements in compiler and build tools, and the power to run an application natively using the blistering fast power of computers, rather than running it on top of some other layer. Moreover, with so many open source libraries with some really cool stuff from computer vision, to artificial intelligence, etc, allowing developers to easily install and use these libraries would be a great first step before encapsulating them classes.
If compelling enough reason exists to build this and enough support, I plan to build this over the next few years.
Long comment(I’m bored), be warned.
Can we please stop with the “virtualization bad, bare metal good” myth? Reality is rarely that simple. See this.
ashish@redacted:~$ cat Fibonacci.cpp
#include
#include
int fibonacci(int n) {
return n > 1 ? fibonacci(n - 1) + fibonacci(n - 2) : 1;
}
int main(int argc, char **argv) {
std::cout < 1 ? fibonacci(atoi(argv[1])) : fibonacci(0)) < 1 ? fib(n - 2) + fib(n - 1) : 1;
}
public static void main(String[] args) throws Exception {
System.out.println(fib(args.length > 0 ? Integer.parseInt(args[0]) : fib(1)));
}
}
ashish@redacted:~$ g++ -O2 Fibonacci.cpp -ofib
ashish@redacted:~$ time ./fib 45
1836311903
real 0m13.614s
user 0m13.609s
sys 0m0.000s
ashish@redacted:~$ javac Fibonacci.java
ashish@redacted:~$ time java -server Fibonacci 45
1836311903
real 0m10.703s
user 0m10.621s
sys 0m0.032s
ashish@redacted:~$ g++ -O3 Fibonacci.cpp -ofib
ashish@redacted:~$ time ./fib 45
1836311903
real 0m8.782s
user 0m8.777s
sys 0m0.000s
-O2 and -server would be the standard(as in recommended in most production environments) options. And the O3 results are due to g++ concentrating on time at the expense of space. Disassembly shows it expanded the recursion to 4 levels.(Interestingly enough, this is not as dangerous as it sounds. I added print statements to the fib function, and gcc reverted back to zero-unrolling. So it apparently does perform checks for side effects.)
And besides, the way things are going, your code is probably going to end up running on a virtualized copy of an OS anyway(doesn’t matter if the hypervisor itself is bare metal — there’s still indirection involved).
Still, (3) would be a very interesting thing to do. This happens to be how most real programs are structured anyway, but the abstraction layer you target is inhouse — the scope of usage is restricted to at most one organization. If you could come up with a standardized interface layer and, more importantly, have it taken seriously by enough people(eg “most new FOSS”), that would be reasonably spectacular.
I don’t say “virtual machine bad, native gcc code good, hulk smash!” too often. But the point of having such a library is to
1. Abstract the different syntaxes by writing wrappers to each of them, in different namespaces but same names.
2. Make them as interoperable as possible. The jpeg decoder should fit well with the graphics system, etc.
3. Exploit already existing cross-platform c++ tools and make them easilly accessible and hot-swappable.
Btw, since when are you using a unix style command line at Redmond, and compiling c# while you’re at it?
Sure, and like I said, a library like that would be awesome. But maintaining it is going to get fairly complex(APIs change, feature-specifications change), and I’d really suggest finding help before committing to something so huge.
That was actually me on a kgp machine(don’t have java/gcc here). But most of us are apostates here at Research. Cygwin and Firefox are so common they’ve ended up on the division homepage. And while the mothership occasionally complains about Firefox, no-one really objects to Cygwin because, let’s face it, there are no real alternatives.
PS. Above listing was actually two files, one cpp, one java. A lot of stuff got elided because it was between angle brackets.
Hi, just came across this interesting entry. Just wanted to let you know (you might already know) that NSPR (Netscape Portable Runtime) library is one good option. AFAIK, it supports Windows, Solaris, Linux, AIX, HP-UX.
BTW, you can compile c#/c++ using a unix-style makefile (with MKS or cygwin).
So you can just have one single Makefile for all the platforms.