Does python have more power than php?

I know(skills) as of server scripting: php and java,…
Well many web server environments (like 4GH Godaddy) not support java but python… You find it good learn a third additional language like python…?

Does python have more power than php?

I’ll answer this one, but in the future you may want to make your posts clearer. Aside from the gist of your post I doubt anyone can understand your post.

Python has been around for years, a fair bit longer than Java. It is primarily a scripting language, in many ways like PHP once was, which is why so many libraries exist for Python, and why there is still such a great divide between Python 2 and Python 3.

For the record, Python isn’t as powerful as PHP. Python can be used everywhere, but so can PHP with the correct libraries. As someone who has casually worked with both languages I will say that Python is much, much nicer to work with. I’m a huge fan of Django, and it’s my framework of choice when working on stuff at home. PHP can be nice to work with, but I argue that most PHP projects are legacy projects, and most Python work is newer and as such is nicer code to work with.

You can be a lot more expressive with PHP, so in that way it could be considered stronger, but given the sheer amount of crappy code out there I would probably call that a weakness.

If you are a beginner and you want to start out in Web Development I would recommend picking either Ruby, Python, or ASP.NET. All three have/are strong frameworks, and by their nature will allow you to generate much nicer code. However, at the end of the day, these are tools to get the job done. Evaluate the job, and the tool will almost pick itself.

If you were like me to have knowledge of PHP/MySQL & Java/JSP/MySQL & Java/Android, would you save time to learn Python 3 or latest??? would it make the life even a little easier?

One man’s trash is another man’s treasure, all those programming languages are still around not just for nothing, there aint a remedy that satisfies every programmer’s need. I personally prefer PHP over Python due to my fondness of C++/Java/C# style syntax, but Python has its place in elsewhere and for those people, Python may as well be more powerful than PHP indeed. The word ‘powerful’ itself is a bit confusing anyway.

The “which is more powerful” qestion as well as “which language to pick up next” really cannot be answered without knowing what types of things you are and want to work on. PHP destroys any other language when it comes to the most common tasks in web development, including speed of development (for those who know what they are doing) because of the tools available (aside from django in python, there isn’t much else. This is a completely different story if you want to DEPLOY your own web app that has built in server. Python can handle this much better (but again like @ULTiMATE said, there’s a huge divide between 2 and 3 which will cause you headache if you need to read some documentation.

If you want to get in to game development, it depends on what kind, before you make your decision.
If you want to get in to some highly computational apps, it depends on what kind, again…

One language that hasn’t been brough up yet is Go, and depending on what your doing this might be your best third language.

So before this conversation goes any further with pointless suggestions being thrown at you, what are your interests / goals for this new language?

Unlike PHP, which has web development features built directly into the core language, Python’s web development capabilites are provided by add-on modules. Basic CGI capabilities are provided by the ‘cgi’ module which comes in Python’s standard library. There’s also a wide range of third-party modules available for Python; some are complementary, others compete. As a result, Python provides a more flexible base for web development.

There are some adverse side effects, Unless you are working experienced Python web developers, PHP is easier to get started with. Second, support for PHP is more common with shared-hosting companies than support for the various Python options.

-iGyan

python except for web what other uses has? is it like java, for web apps, for desktop apps, … for mobile apps… i do not think the latter…well?

Recent events at PHP internal has made me believe that PHP’s declining and may not last another decade. If this happens, Python has a good chance to take the throne, its objected oriented but actually quite easy to learn. Node.js is also a strong candidate, but the language has yet to mature and there is a good deal of uncertainty involved with node.js. Java and C# suffer from the problem of being statically typed, which is an advantage for desktop apps but a hindrance for web development(C# does not run very well on linux hosts, thats another problem for C#.net and ASP.net). Ruby has a steep learning curve, its difficult if not impossible for complete newbies to start with, the fact that you need at least some programming background to understand/write ruby code is probably why it never reached the popularity as many people had hoped.

Off Topic:

I’m not sure I’d agree with you there. I’ve just started looking into Ruby myself (albeit as someone who already knows several languages) and I don’t see why it would be any harder for a complete beginner to pick up than PHP. In fact, there are some aspects of the language that I think make it slightly better than PHP as a first language (no need for semi-colons and less use of curly braces and parentheses, to give an example).

What parts of the language do you think would be more difficult to get to grips with for a new programmer?

Python is very widely used for mobile, desktop apps, server scripting, mathematics, etc. In a lot of ways its easier to pick up on than PHP. It is a good tool to have under your belt.

I agree with the PHPs decline and possiblly not lasting, but Python is in too much of an unstable point right now and is hindered by a lot of performance issues even compared to PHP. Now something like .NET or GoLang replacing it in 10-15 years when highly concurrent apps are more mainstream, that I can see.

Well its a completely different story once you already know a lot about programming, no matter whether you know just one or multiple languages. For computer genius who grasped the basics of programming easily, they may not understand how an average beginner coder perceive and learn these programming concepts. Some programming languages are more suited for newbies to start with as they provide easier ways for newbies to learn such concepts from scratch. There is a reason why certain languages are more newbie-friendly than others, take a look at this link if you are interested. Its generally believed that Python > PHP > Ruby in terms of ‘ease of learning’(although PHP can be easier if you come from a C/Java background), assuming you are a complete newbie with no idea of how to write even the simplest hello world code:
https://www.udemy.com/blog/modern-language-wars/

To tell the truth, I actually did attempt to start with Ruby a few years ago before I became a PHP programmer, as I was trying to play with a game dev engine called RPG Maker which uses ruby code. I had absolutely no luck, ruby was beyond my understanding however hard I tried. A few months ago, however, I accidentally picked up the old Ruby book I used before and browsed through it again. Everything was making perfect sense and I could write ruby code easily. It will take me shorter time to learn Ruby than the time I spent on PHP years ago, but its by no means an implication that Ruby is easier to learn than PHP. It simply proves that taking on another language is much easier once you already learn the basic concepts/terminologies with one language, nothing more nothing less.

Yeah I’ve come across that infographic before, but I was hoping you might have some specific examples of what you think makes Ruby harder to learn?

As a beginner, the first things you come up against are things like variable assignment, operators, conditionals and loops. Here are some simple examples of those, in both PHP and Ruby:


// Set a variable
$name = 'Bill Gates';

// simple operation
echo 5 * 5;

// Conditional
if ($hungry) {
    eatFood();
}

// Loop
for ($i = 0; $i < 5; $i++) {
    echo "There's no place like home.";
}


# Set a variable
name = 'Bill Gates'

# simple operation
puts 5 * 5

# Conditional
if hungry
    eatFood()
end

# Loop
5.times { puts "There's no place like home" }

To me, Ruby doesn’t seem to be more complicated than PHP and as I mentioned previously, there are some ways in which I think the Ruby syntax is nicer. Take the loop code for example, it’s more readable. You can also make simple conditional statements even more readable:

eatFood() if hungry

I must agree with fretburner.
For me, Ruby’s syntax was considerably easier to wrap my head around than PHP’s.

For example:

You can also invert conditional statements with unless

puts "I love PHP" unless ruby_better

and the last expression evaluated within a method is the return value

def ruby_better
  true
end

You don’t need parenthesis after your method names, semi-colons are optional, the list goes on …

Also, due to the fact that virtually everything in ruby is an object, chaining is much easier which makes for very readable code:

Take for example a case when you have a hash where you want the first 3 alphabetically sorted key values. In PHP you’d do the following:

$foo = array("zulu" => "1", "alpha" => "4", "golf" => "8", "bravo" => "3");
$keys = array_keys($foo);
sort($keys);
$bar = array_slice($keys, 0, 3);

This seems incredibly verbose mainly due to -the fact that PHP doesn’t return the sorted array from sort.

Compare this to the ruby equivalent:

foo = {"zulu" => "1", "alpha" => "4", "golf" => "8", "bravo" => "3"}
bar = foo.keys.sort.slice(0,3)

Example taken from here: http://andyjeffries.co.uk/articles/4-reasons-why-ruby-syntax-is-better-than-phps-

I just read a cool article on SitePoint (formerly RubySource) about Ruby’s Top Self Object.
It examines the value of self in the top lexical scope, explains why all functions are actually methods and concludes that this is one of the reasons that Ruby is easy to learn and use.

Thoughts?

Really? PHP, Python, Ruby? Mheah! Pffftt!

JavaScript, now that’s what I’m talking about.

For self Ruby, take this Javascript window/global(nodejs) object, all functions are methods for the containing object, global or not, and memoization should really be a thing to teach from the start when it comes to recursion!


var f = [];

function factorial(n) {
    console.log(this);
    return n == 1 ? 1 : f[n] > 0 ? f[n] : f[n] = factorial(n-1) * n;
};

console.log(factorial(10));

Prototypical nature of JavaScript is actually pretty easy to put in practice. The inheritance mechanism makes much more sense to me in JavaScript than in other languages (Golang for example), it’s simpler and clearer. All in all, JavaScript kicks ****!

First of all, I agree with you that ruby has more elegant syntax than PHP on various aspects, the fact that its pure object oriented makes it quite attractive to OO programmers like me. However, I believe your argument was no different from fretburner in a way that both of you are advanced/professional programmers with a good talent in coding. I never said a computer genius can not grasp Ruby as easy as he/she does with PHP or python, we see it happens all the time.

Unfortunately, this does not apply to an average beginner coder. Dont get me wrong, I like ruby’s number iterator such as 2.times{print something}, I also use method chaining in lots of my projects, but most newbies dont understand such concepts easily. Method chaining for instance, is quite confusing if you dont know what you are doing with it. I work on a PHP application/software myself, the userbase consists mostly noncoders or beginners. Its quite common that a programming concept that takes a few mins for me to interpret will take them forever to understand, even with simple PHP.

In fact, Ruby’s flexibility in writing conditional statements like unless and loops like until is a hindrance for newbies to grasp the very basic concepts. Same reason why you teach one language for starters at once, not two, three or more. Its more important for newbies to understand the concepts rather than syntax, ruby promotes coding with fluent interface which is a bless for advanced coders but just makes newbies life more difficult. Difficulty in focusing on what they should be focusing can be a real problem at times.

Also keep in mind that Ruby’s nature as pure object oriented language makes it hard if not impossible to introduce the basic computer science concepts to starters without talking about objects and classes. Reality is, absolute beginners do not grasp the concepts like objects and classes as fast as we believe they should.

On the other hand, ruby code may be easier to read for programmers, but I am talking about how to write a working program for absolute starters. The ability to read a program is vital, but you have to be able to write your own piece of code to become an intermediate coder rather than stay as a newbie. Again I emphasize that I am not talking about ivy league students who are expected to learn new skills fast enough. Its more about newbies who come from backgrounds with no more than HTML and CSS, its not an easy job to understand the mindset of newbies/starters when you are already an expert programmer, especially if you possess the talents they normally do not when it comes down to coding. There’s a reason why superstar athletes do not make better coaches than role players, as they do not understand how average athletes play their games.

@myty ;

Could you explain this bit to me:

return n == 1 ? 1 : f[n] > 0 ? f[n] : f[n] = factorial(n-1) * n;

I understand it more or less, but the f[n] bit has me confused.

@Pullo;
It’s the memoization part.

Let’s break it down. First, a stack of recursive calls is build, until n hits 1. Then the stack gets calculated (imagine putting back together Matroshka dolls, not taking them apart, to understand the stack resolve), from n low to n high, but on every step, the previous same range values are calculated over and over.

To avoid that, we memorize the previously processed inputs. Imagine that for each Matroska doll you add, you then disassemble them all and start all over again in order to get to next step, next bigger doll. Memoization helps avoid that. The f array holds just that, the previous processed inputs. This way, on the next recursive call, we skip the calculation part and just use the previously stored value.

One other thing to note here is how easy the conditional or ternary operator can be nested in Javascript. One of them can be an expression for another.

The real question is: for any given programming concept, is there anything about Ruby syntax that makes it harder to learn or implement than the equivalent in PHP? So far you’ve failed to convince me that there is.

If you mean it’s confusing that there are several different ways to do something, then in that respect Ruby is no different from PHP. How many different ways are there to write a loop in PHP? I can think of at least four.

Take a look at the article Pullo linked to on Ruby’s Top Self object and you’ll see that’s just not true. You can learn all the basics without knowing anything about classes or objects.

A line of code that’s easy to read and understand is also easier to write. To take Pullo’s example

puts "I love PHP" unless ruby_better

is so close to a plain English sentence that my grandmother could work out what was going on.

@Pullo;

Here’s a legitimate reference, maybe the master explains it better.
http://my.safaribooksonline.com/book/programming/javascript/9780596517748/functions/memoization