views:

163

answers:

6

I'm going to reveal my ignorance here, but in my defense, I'm an accounting major, and I've never taken a computer science class.

I'm about to start a new project, and I'm considering using Python instead of PHP, even though I am much more adept with PHP, because I have heard that Python is a more powerful language. That got me wondering, what makes one programming language more powerful than another? I figure javascript isn't very powerful because it (generally) runs inside a browser. But, why is Python more powerful than PHP? In each case, I'm giving instructions to the computer, so why are some languages better at interpreting and executing these instructions? How do I know how much "power" I actually need for a specific project?

+1  A: 

I hate statements of the sort "language X is more powerful than Y." The real question is which language makes you more powerful. If language X allows you to write better code (that works) faster than Y does then, yes, X is more "powerful".

If you are looking for an objective explanation of language powerful-ness ... well, good luck with that.

kaloyan
+4  A: 

It's not really a matter of power, but a matter of what you're trying to do and how you try to do it. You could say that Python is "more powerful" because it comes with a large set of built-in libraries, or that C++ is "more powerful" because it's much faster, or that Haskell is "more powerful" because it uses lazy evaluation - in short, it's really a matter of opinion. But I haven't seen many desktop apps written in PHP, and I don't see web apps written in C++ (though there are probably exceptions, of course).

Some languages simply offer what is considered an "elegant" way to perform certain tasks. For instance, look at a factorial function in Haskell:

factorial 0 = 1
factorial n = n * factorial (n-1)

Some might consider this elegant mainly because it reflects the mathematical definition clearly. But is this better than another implementation? No. (Especially since this would overflow the stack.)

In conclusion, use what you feel is best for your task - if you're best with PHP, and you don't want to learn Python, than don't. If you're interested in what it's like, then check it out. Don't learn it because it's "more powerful."

l33tnerd
there are languages which which require the translator to detect and optimize out the tail recursion. so the stack overflow may not be true for all languages.
alvin
You're right (and I think Haskell is one of them), but my main point was that elegance is not necessarily useful or practical.
l33tnerd
A: 

The stock answer is the only features that make certain languages more powerful than others are language features that cannot be easily replaced by adding libraries.

This definition will almost always list LISP on the top, but has the odd side effect of listing assembly near the top unless special care is taken to exclude it.

Joshua
+3  A: 

When Paul Graham talked about Lisp being the most powerful language available, he meant most expressive. You can express any program in any turing complete language. That's the whole point. What makes one language better than another (for a particular task) is its ability to define a given program more concisely or clearly. For most programming tasks, that's what matters.

Occasionally (and I mean very occasionally) performance starts to play a role, and features like the ability to embed assembly language easily in your program matters. But for the most part, it's about the ability to express your ideas clearly and concisely.

Nathon
I suppose this is what I was hoping to find out. I had figured that in most cases the differences in power of programming languages had to do with performance. Thanks.
smfoote
I've also heard it said that many design patterns are workarounds for missing language features, and I'd tend to agree. I still want a macro facility for C#, even though that would make name-completion a much harder problem.
Jeffrey Hantin
@Jeff: I know pretty much nothing about the world of CLI, but apparently the language [boo](http://en.wikipedia.org/wiki/Boo_(programming_language\)) runs in it and provides lisp-style macros among its many features.
intuited
A: 

I would not say that there are computer languages "more powerful", just languages more suited for your specific problem domain.

That said, PHP is a language that evolved from a hack and tailored for a very specific problem domain; this shows up in several places, like for example inconsistent parameter order across database interfaces. IMHO PHP community has made some very sad decisions for new syntax enhancements over the time.

IMHO Python is much more general, well designed and elegant, but your question is one that usually starts flamewars.

Paulo Scardine
A: 

Its an interesting topic and in my line of word I come across this a lot. But I've discovered 'power' in the literal sense no longer has value when it comes to the language. What I fear those telling you 'python is more' powerful are getting mixed up with the language and the implementation.

I'm a recent convert to python (last 2 weeks) previously I was a PHP coder. The libraries made on top of the language of python - namely django -help make the language more powerful - as its faster to use and build upon.

PHP has the fable 'if you want to do something. there is a function for it' and the documentation is brilliant - therefore powerful in that sense.

And in regards to interpreting the language - again dependant upon who has been coding it - its no matter. By general consensus python may be considered quicker and less CPU intensive, is it creates compiled versions of your code. But PHP can have a good caching system.

In short - Pick you favorite.

Glycerine