PDA

View Full Version : Why I've chosen Python over PHP?



Caughtrandomly
30-05-2013, 01:50 PM
I just thought I'd post a small article on why I've chosen Python over PHP, so let me start by saying I have been coding now for around 8 years and my first programming language I learnt was PHP (or scripting language depending on peoples opinions)
Anyway back to the point, I love PHP and I found it to do everything I wanted, it was widely used meaning there were many different ways to solve problems, etc., I liked that PHP is so easily accessible and that most hosting comes with it, but then I look into Python.
After working with Python for just over a year I found that the syntax was much cleaner (in my opinion), for example:
In PHP if I wanted to do a if statement and return true if its false, I would do:


$variable = false;
if(!$variable) {
return true;
}

Where the syntax for Python can be:


variable = False
if not variable:
return True


Another example I'll post was if I wanted a function to return false if the input is right



function test($input) {
if($input == "yes") {
return true;
} else {
return false;
}
}


Whereas in Python it would be


def test(input):
if input == "Yes":
return True
else:
return false


I just overall found the syntax to be much cleaner and I know some people disagree as they would prefer to use the curly brackets instead of white spacing (Which is what most programming languages use)

I also have several other reasons why I choose Python over PHP, for example, the framework Django, but I'd like to hear your opinions before I go onto that.

Just wondering what other peoples opinions are on this?
Please note, I'm not trying to start a programming language war, just curious!

Chippiewill
30-05-2013, 02:01 PM
Well, your code is mostly just inefficient here, no need for curly brackets if you use ternary operators.

Caughtrandomly
30-05-2013, 02:07 PM
I'm aware of that Chippiewill, but the code isn't inefficient as there simple examples of both code and yes you could use Ternary Operators (would of been easier to say PHP Shorthand) but I'm on about general PHP, as I personally don't like using shorthand most of the time.

Zak
30-05-2013, 02:15 PM
I've never coded in Python but the syntax just makes it look unprofessional.

I haven't really coded in PHP either but the syntax is clearly suit of C++ and Java. I prefer their syntaxes over what I've just seen in Python, just looks very aged.

Caughtrandomly
30-05-2013, 02:19 PM
Thats a fair opinion Zak, I've done a lot of work in C#, which has a very similar syntax to PHP, and I still prefer Python over that for software development.

Zak
30-05-2013, 03:12 PM
Tbh I hate PHP and I'd probably hate Python too :P Has Python got the versatility that PHP has?

Want to hide these adverts? Register an account for free!