lzdude69 wrote:
Quote:
That higher level languages allow more scope for optimisation is a *fact*, well established in compiler theory.
I personally would say C/C++ is a fairly high level language, and so is Python, Python just comes with a plethora of crap that you would otherwise have to implement yourself.
Nope. C is as close as you get to the metal without going to ASM (and C++ not much better). Python has garbage collection, doesn't have pointers, doesn't have declarations, doesn't use machine types... the list goes on. That the syntax resembles C++ is neither here nor there.
Quote:
Well, you can say that about any compiled language. Code that runs on a VM is a little different obviously, but sure enough the VM had to come from somewhere. I was referring solely to syntax, as everything has to eventually resemble ASM. Does Python loops/conditionals not resemble C/C++/ASM/BASIC loops? Are Python types completely alien, or do the mimic types we've been using for ever?
Compare these snippets, the first in python and the second in C++:
Code:
[x*x for x in v if x > 3]
Code:
template <typename T>
std::vector<T> func(const std::vector<T> &v) {
std::vector<T> r;
for (int i = 0; i < v.size(); i++)
if (v[i] > 3)
r.push_back(v[i]*v[i]);
return r;
}
They both perform exactly the same operation (return a list of the squares of all items greater than 3 in a source list). However, even with the template, the C++ version still only works on one type of container, while the python version will work on any container (list, array, file, etc.). The C++ version is also 8 lines instead of 1, and is harder to read and maintain. But the big issue here, and the main win for Python, is that the python version can be automatically and transparently parallelised across multiple threads by the VM, and the C++ version cannot.
Quote:
To even write an algorithm faster/better than C++, wouldn't that require a very similar knowledge of the Python VM?
Nope, see the above example. High level languages express 'concepts', low-level languages express 'operations'. Operations can never be handled as well by the compiler as concepts.
This is the reason why Google wrote their backend in Python, Yahoo wrote theirs in LISP, Apple uses Objective-C for all their stuff, etc. You can't really write stuff like Google's distributed map-reduce search algorithm in a low-level language like C++. And even if you do, the performance wont be any better, and the maintainability will suck.
Quote:
Quote:
Meaningful whitespace is one of my main gripes with python, but it does at least guarantee that everyone uses a consistent code format

That was the whole reason for that right?
Quite likely.