The missing language
In the last month or two I have been writing a fair bit of C code.
I really dislike C. But I have not been able to find a language to replace it with, except C++, and that's not much of an improvement for what I did.
Maybe someone can read this and help me. I don't mind learning a new language. Really, it's no problem.
The goal is writing small programs (in the hundreds of lines region), which have the following requirements:
The program MUST be correct. Can never segfault or crash in some other way.
Since the code is short, I think I have managed, using bstrlib, to get this, after quite a bit of pain, by auditing and unit-testing. But I am not sure, and I will never be.
It would be awesome if the language could be garbage-collected for this reason.
It MUST have a decent string handling.
The programs handle mail. So, it's strings galore.
It MUST have very low overhead. The programs should run and end quickly. Very quickly, because people may be waiting for them to end.
It MUST be a reasonably simple language. I am not a great programmer, and these tools will be hacked at by people with limited programming skills (sysadmins like me!)
Trivial access to C libraries.
So, let's see.
C: gives 3, 4 (in a fashion), and 5
C++: 2, 3, maybe 4, and 5
D: It seems to give me all of these, along with a C-like syntax... but I can't get it to work yet (correction, I got dmd to work, so it's looking good for D!).
So, any takers?
Python might be an idea if you don't mind scripting languages.
Hey!
I think you found the perfect match in D, and I don't see any good reason for it not to work for you, unless you don't use Windows or Linux for your OS.
Check out the #D channel at freenode, I and the rest there will do our best to help you with any problems.
larsivi
try D
I say use Python. 2.4 is quite speedy.
Or use Java.
Also try Ruby if a interpreted "scripting language" is a choice. Access to C libraries is said to be easier with Ruby than with Python. And programming in Ruby is fun!
try ml
Hi Roberto
I'm intrigued by D since quite some time. I only wish it came in the gcc suite. I seem to remember to have read it can link just well to C (and C++?) libraries, so we wouldn't have the high barrier of entry ruby has compared with python, for example.
Well, I guess I only need a project that would help me get a practical use for D.
Those who propose python and ruby: you don't understand exactly how quick these programs need to work.
They are run, 5 or 6 of them, for each message in a mail server that processes hundreds of thousands of messages per day.
Sometimes per hour.
For example: a dash shell script (much lighter than python or ruby) had much more overhead than rewriting it in C! :-)
I am a big python advocate, but they are not the tool for this job.
My first bet was scheme. Specific powerful compilers are Gambit, Chez (not open-source) and stalin. But since you need extreme speeds, you will need to think about how memory is allocated.
ML-variants are extremely fast. Take a look at mlton or ocaml for getting speeds on par with C.
I had similiar problem and I've chosen C. My program, which must run really really fast, was written in bash. Next, I've tried python, which occured to be slower, and then, I tried and ported it to C, which is much faster. Simple fragment was even 100 times faster than its bash version. So, I need to stay with C, even with its problems and maybe this is time to learn writing safe code ;)
oort: the problem you had with bash could be if the program is dominated by loading time.
Once a bash script is in memory and running, it's almost finished ;-)
I have notinced HUGE performance improvements by switching for dash in shell scripts. It loads in about 1/10th the time of bash, and then the script speed is rather unimportant.
Re: lisp/scheme... ok, I have been postponing lisp for the last 12 years, maybe it's time to look into it already....
ML is very interesting as well.
Looks like you are ready for Ada ;).
No, seriously, looking at your list of requirements, it seems to be a good fit. #1 is just legendary. #2 is covered - you have fixed, bounded and unbounded strings. WRT #3 and 5 I will just mention that since a few years Ada has become an official gcc frontend. Which means that you get trivial linking with C code (and C++ for that matter), very much the same code efficiency (same backend) and it is provided by all major distributions. As for #4, you just have to try. You won't regret it, I promise ;).
For starting up I cannot recommend enough this book:
http://www.amazon.com/gp/pr...
(Programming in Ada 95 by John Barnes)
ocaml or eiffel
both compile fast and lead to programs that do not crash
I was going to suggest Ruby, but I guess that won't work.
So I have to agree with George Shapovalov - Ada would be a good choice. Its the defacto standard for writing "correct" programs. It was designed for flying airplanes and ICBMs; I think it can handle your mail. ;)
Not a particularly easy language, but it is the first language that my university teaches so its not particularly difficult either.
While you are trying to get D to work(which is the best match in my eyes too, unless you need C++ support[=gui :P]), you could also take a look at http://www.hpl.hp.com/perso... .
My vote goes to Ada (2005 is the best version by far) and Ocaml. In both cases you need to learn how to write good code (question of art more than mere technics ;) ).
Ada is imperative, it can give access to pointers (and registers, ideal for real time :) ), so you must be careful to what you're doing with it (no nasty code like in C because of harsh code verifications, but you can have your program not crashing and doing rubbish instead :s ). It's a very solid language, I use it every day at work (OK, I work on a military project ^^).
Ocaml is functional, so it's pure mathematics. It's even more strongly typed than Ada (but it forbids to have coertion, also present in Eiffel, for that very reason), so the compiler is good enough to guess what the types are (sometimes you can also declare a function without precising what the arguments are !). It is very strong with recursions (a 'for' loop isn't nice, though), and ML syntax allows to have matching, it rocks ! :)
I don't practice Eiffel, but I also recommend you to take a look at it. That's a very powerful OO language...
Concerning rapidity, Ocaml is better, but we have to precise that Ada2005 comes with a lot of optimized libraries (useful for not creating everything from scratch like before, with pointers and free for trees by instance :/ ), and the compiler adds a lot of code for verification at the execution (and the coder of Ariane5's bugged module should not have disabled the int overflow verification...), hence the relative lack of performance...
I'd give my vote to Ada as well, recommending the same book as above (Programming in Ada 95 by John Barnes).
#1 is the goal of Ada, you won't get another language that is better on this point.
#2 is also great, though you must remember what kind of string you've got (fixed, unbounded or bounded) and convert between them. (Not that different from C++, but might be considered a drawback compared to say Java)
#3 is covered, perfomance is identical to C/C++
#4 It is as simple as you get without going VB. It's not C syntax, but Algol/Pascal, but that actually only makes it simpler (though you might have to re-learn some stuff if you only know C based languages).
#5 Is also coverd, as it's a front-end to GCC. It will also easily bind to C++.
I'm not sure if Lua would be fast enough - it is faster than python/ruby/etc, but it's certainly not C :)
On the other hand, it's incredibly small and simple. So maybe...
how about cyclone?
Cyclone? Got URL?
Objective-C is fast enough, Apple use it
Lisp or C#
Lisp has Perl regex, which is actually faster than the Perl version. With sbcl, all of my code is compiled, and it has a gc to boot.
C# seems like a Lisp copy.
C# won't work. While the code runs fast enough, it takes too long to load.
Everyone: before you suggest another language that is interpreted/has a VM, please try this:
* write the smallest program you can
* start it 100000 times in sequence
* time it
* compare it with the smallest shell script you can write running the same way.
If it's not 20 times faster than the script, it's not worth it, because C/C++/D are 50 times faster than the script.