Ah, where to start... I guess the beginning is best?
NickJohnson wrote:I'm not talking about making another Python interpreter, and I'm not talking about premature optimizations either. I mean you could actually have a C library with functions that allow you to make things work like Python in *native C code*. The syntax would be odd, but it is undoubtedly possible.
I get what you're saying, I'm being snarky. But there's a reason for that, elaborated upon below. Also, remember that bold for later!
Here's an example of how I could implement slices in C. First off, you make a string structure with two elements. The first is an integer, and the other a pointer. The integer lists the length of the string (essentially making a Pascal-style string) and the pointer points to the string. If you want a slice, a function called slice() would pass back a string structure pointing to a section of the original, with a different length. You can then concatenate strings with a special version of strcat(). GC can be done with some special restrictions on pointers as well as threading. If C had a more flexible syntax, more like Lisp, you could make nearly anything work, and at a smaller speed price than a very high level language.
... and now you've destroyed all of the speed benefits you were talking about before. Also, you're adding a lot of memory overhead.
The whole optimization thing doesn't even really apply. If you match completely unoptimized C code to even horrendously optimized Python, also assuming the same algorithm, the C will always beat the Python. So if you could get C to look decent while doing high level stuff (which I'm not claiming is possible), why not use it?
Compare the two bold statements.
Also, it may beat it, but the issue is not pure speed. The issue is, is it
fast enough? You're going to be hard-pressed to find a high level application which you
need the .02ms speed increase that C gives you. And if you do, you can rapidly develop most of the app in Python itself, and then use the C FFI to get that necessary speed out of it.
The main reason why we aren't using C for more things is it's lack of really good, powerful libraries.
Agreed. Sort of. It's a lot of work to implement things. C is a bit too low level most of the time.
There's nothing magic about very high level languages - everything is equally powerful (although C also has pointers, which are a big plus). It's just the syntactic sugar that sets things apart.
You're sort of abusing 'syntactic sugar.' Usually syntactic sugar is certain syntax that's more convenient than another syntax. But you're using it to mean "entire libraries that people have put X hundred man years into."
What I really mean to say is that: A. it would be really cool to make C do much that Python can, and B. why waste so many clock cycles by restricting ourselves to languages that have such strict requirements if we can adapt something with more control? I don't mean to sound like a zealot: I just think it might be an interesting idea.
You're completely right. It's just that it's not possible.
Switch!
dude101 wrote:Why doesn't someone just make a compiler for these high level languages? It's obscene to a 10,000 line interpreted Perl script. If the Perl langauge lets you do stuff easier than C, fine. But just compile the damn code. Is that asking too much?
Many people do. Haskell is about as high level as you can possibly get, and ghc is an amazing compiler. The "problem" is that it's not worth the huge effort to make one of these compilers. It's not like compilation magically makes things faster.
And back!
NickJohnson wrote:The point is that these languages include features that are really hard and inefficient to compile, because the designers don't intend for them to be fast or compiled. This means the languages can be much more expressive, at a very large inherent speed cost.
Yeah. Ruby (my preferred interpreted language) is
exactly like this. Matz is more of a visionary than an implementer. Only recently has Ruby gotten any kind of real speed improvements, and that's with the move to someone else's interpreter.
Although, it's surprising that Lisp, a language that has as many if not more high level features than Python, can be compiled and run with only about double the overhead of C. Maybe that's due to the functional language restrictions?
Lisp is not functional, it's mutliparadigm. Then again, "Lisp" is sort of a useless term. Scheme is functional, Common Lisp is not.