Is Python easier than PHP?

Azareal

The AtomBB Overlord
Joined
Mar 7, 2010
Messages
1,133
I'd say that it's around about the same. Granted, there are some parts of PHP that are a big pain, but there are also parts of Python that are a big pain.
 

Sysnative

Habitué
Joined
Mar 1, 2013
Messages
1,103
I think Python is nicer. Whether or not it's easier I'm not really sure.

I'm more familiar with PHP due to the necessity of using it for my sites. PHP is very hacky though, and encourages bad practice. I think python is better designed, but that said I've never had to use it in any large projects.
 

euantor

MyBB Lead Developer
Joined
Jul 23, 2009
Messages
717
As Azareal said, they're pretty similar. Both are dynamically typed and are interpreted languages. Python is probably easier to get started with if you've never done any programming, as PHP has a lot of quirks and there are many ways to achieve the same thing (though most of them are the wrong way...).
 

rafalp

Desu Ex
Joined
Feb 17, 2008
Messages
1,340
Do you think Python is easier than PHP?

PHP is much faster to get in than Python, especially if you have no prior experience in the field, you can simply hack stuff together and echo all output to user and get stuff to show in browser. To do same in Python you would need to learn basics of shell-fu to make PIP install some WSGI stack for you, that you would then need to learn how to integrate your code with.

This difference is PHP's greatest strenght, but ultimately its also its greatest weakeness, because there is great deal of people within PHP world hacking scripts blissfully unaware of things like patterns, PSR's, automated testing, package management, etc ect.

Big difference between Python and PHP lies in standard library, or "core features". There's running joke in Python community that you can import antigravity due to amount of solutions available in language alone. For example there are simple HTTP, SMTP and IMAP implementations in Python stdlib, both for implementing servers and clients. There is HTTP documents parser. There is i18n and I10n implementation.

Python is very "sweet" language, which means there's ton of sugar in it. For example you may check if two collections overlap via writing custom function, but you may also do it via "set(collection_a) & set(collection_b)". You may iterate collection via for loop, or you may process it in place via [process(i) for i in collection]. instead of dedicated array_XYZ functions from PHP there is "[:]" slice operator that behaves differently depending on arguments providen (vide [a:b] doing something different [a] and [a:b:c], and you can use negative arguments there for extra magic).

Python is dynamicaly typed while PHP is weakly typed. PHP tries to convert types to another when it thinks other type is better fit, which may produce some suprising behaviours and edge bugs. Python code relies on behaviour similiarites instead, which either produces crashes ("I can't iterate on number!") or edge bugs ("I didn't know I was iterating on characters in string instead of strings in list!").

Python's type system is more complex than PHP's one. There are two basic types for list, mutable and immutable. There is separate type for map. In PHP there is just array().

Basic types in Python have methods, sometimes very suffisticated ones, like split() or title().

Python object model is very magic. Everything is an object, even object definitions are objects. But at same nothing is real object but special type of map of values and functions that just wraps around basic map type. Everything else is parser doing its magic in converting objects into simpler structures and interpreter pretending "thats really object!". This is why object methods have explicit "this" argument.

On other side such "weak" object model allows for many amazing things. Objects can inherit from many types at same time, they can change themselves on runtime, even on instatiation. Metaclasses in Python while very confusing and tricky to get into, it allow for some crazy stuff in ORM's.

Python has exception-based error handling. Every error in Python is exception that can be caught and handled. You can even catch syntax exceptions! PHP is still making transition from returning falses and error codes to exceptions.
 

Madi

Espresso King
Joined
Sep 5, 2010
Messages
168
I'd say that it's around about the same. Granted, there are some parts of PHP that are a big pain, but there are also parts of Python that are a big pain.
Thanks Azareal, I'm pretty sure that any language got its tricky points.

I think Python is nicer. Whether or not it's easier I'm not really sure.

I'm more familiar with PHP due to the necessity of using it for my sites. PHP is very hacky though, and encourages bad practice. I think python is better designed, but that said I've never had to use it in any large projects.
Definitely PHP is the most widely used server-side scripting language thats why you'd find the most hackers playing within it. Python looked good for me as well when I read a bit about but its popularity compared to PHP is not that big.

As Azareal said, they're pretty similar. Both are dynamically typed and are interpreted languages. Python is probably easier to get started with if you've never done any programming, as PHP has a lot of quirks and there are many ways to achieve the same thing (though most of them are the wrong way...).
Thanks man, Can you suggest any good python tutorials to look through?

PHP is much faster to get in than Python, especially if you have no prior experience in the field, you can simply hack stuff together and echo all output to user and get stuff to show in browser. To do same in Python you would need to learn basics of shell-fu to make PIP install some WSGI stack for you, that you would then need to learn how to integrate your code with.

This difference is PHP's greatest strenght, but ultimately its also its greatest weakeness, because there is great deal of people within PHP world hacking scripts blissfully unaware of things like patterns, PSR's, automated testing, package management, etc ect.

Big difference between Python and PHP lies in standard library, or "core features". There's running joke in Python community that you can import antigravity due to amount of solutions available in language alone. For example there are simple HTTP, SMTP and IMAP implementations in Python stdlib, both for implementing servers and clients. There is HTTP documents parser. There is i18n and I10n implementation.

Python is very "sweet" language, which means there's ton of sugar in it. For example you may check if two collections overlap via writing custom function, but you may also do it via "set(collection_a) & set(collection_b)". You may iterate collection via for loop, or you may process it in place via [process(i) for i in collection]. instead of dedicated array_XYZ functions from PHP there is "[:]" slice operator that behaves differently depending on arguments providen (vide [a:b] doing something different [a] and [a:b:c], and you can use negative arguments there for extra magic).

Python is dynamicaly typed while PHP is weakly typed. PHP tries to convert types to another when it thinks other type is better fit, which may produce some suprising behaviours and edge bugs. Python code relies on behaviour similiarites instead, which either produces crashes ("I can't iterate on number!") or edge bugs ("I didn't know I was iterating on characters in string instead of strings in list!").

Python's type system is more complex than PHP's one. There are two basic types for list, mutable and immutable. There is separate type for map. In PHP there is just array().

Basic types in Python have methods, sometimes very suffisticated ones, like split() or title().

Python object model is very magic. Everything is an object, even object definitions are objects. But at same nothing is real object but special type of map of values and functions that just wraps around basic map type. Everything else is parser doing its magic in converting objects into simpler structures and interpreter pretending "thats really object!". This is why object methods have explicit "this" argument.

On other side such "weak" object model allows for many amazing things. Objects can inherit from many types at same time, they can change themselves on runtime, even on instatiation. Metaclasses in Python while very confusing and tricky to get into, it allow for some crazy stuff in ORM's.

Python has exception-based error handling. Every error in Python is exception that can be caught and handled. You can even catch syntax exceptions! PHP is still making transition from returning falses and error codes to exceptions.

Thanks man for the post but I wish I can understand it. I am a total beginner towards backend development but I am really interested to hop into the field and learn some programming. I'm a junior front-end developer (HTML and CSS) but I always had the desire to convert these static webpages I built to dynamic ones. So I'm asking about a language that this considered to be "beginner-friendly" so that I can be able to grasp the programming concepts and have a good foundation to start to build upon from.


_______________

That being said, I played into some PHP tutorials, learnt about some operators and some stuff. I feel like PHP is really very hard to start with especially for a complete beginner in the field of programming. I played with Ruby on Codeacademy for a few hours and it was actually less "bitter" than PHP. I dunno where this going actually but I feel that I miss something. Its not about the syntax of the language, its about my feeling that I need to know about something else before I hop into programming field. I heard people saying "You should have 'decent' database skills before you start programming" Is that true? Do I really need this or can I learn about databases whilst learning programming?

Thanks for the advice guys I appreciate it alot.
 

Azareal

The AtomBB Overlord
Joined
Mar 7, 2010
Messages
1,133
With PHP, you can probably start building websites within an hour or so. This might be a slight exaggeration.
With Python, it will take.. a while. The other thing is that PHP hides problems from you, which means that you might be able to get things done faster in the beginning, but then you have some mysterious bugs that have snuck in.

PHP is highly popular, as an amateur can just jump in and start building sites without having to worry about the details.

Do I really need this or can I learn about databases whilst learning programming?
Not really. Depends on what you're building.
 

Sysnative

Habitué
Joined
Mar 1, 2013
Messages
1,103
Definitely PHP is the most widely used server-side scripting language thats why you'd find the most hackers playing within it. Python looked good for me as well when I read a bit about but its popularity compared to PHP is not that big.

I didn't really mean that "hackers" would be using PHP. I mean "hacky" as in cobbled together - most PHP applications don't follow coding best practices, it's easy to create a working PHP application that doesn't use a sensible structure etc.

It's a very hacky language, and it's very easy to do stuff badly with it.
 

Madi

Espresso King
Joined
Sep 5, 2010
Messages
168
I didn't really mean that "hackers" would be using PHP. I mean "hacky" as in cobbled together - most PHP applications don't follow coding best practices, it's easy to create a working PHP application that doesn't use a sensible structure etc.

It's a very hacky language, and it's very easy to do stuff badly with it.
Oh my bad :D sorry. And why is that? Is it because its a loose language?
 

Madi

Espresso King
Joined
Sep 5, 2010
Messages
168
With PHP, you can probably start building websites within an hour or so. This might be a slight exaggeration.
With Python, it will take.. a while. The other thing is that PHP hides problems from you, which means that you might be able to get things done faster in the beginning, but then you have some mysterious bugs that have snuck in.

PHP is highly popular, as an amateur can just jump in and start building sites without having to worry about the details.


Not really. Depends on what you're building.

I will be basically building websites as a start. What do you suggest?
 

Sajuuk

Adherent
Joined
Oct 12, 2009
Messages
431
I learnt coding from PHP, but you'll find that it does not really scale very well with large websites. It's good for when your site is small or moderately sized, but you'll need caching system in time, since it becomes inefficient when your site has decent traffic and serves a lot of page views at once.

For that, Python becomes a necessity as it scales better (hint: YouTube is a python based site and scales well as a result) for very big websites. But all coding languages have their weaknesses, however PHP is the easier to learn imo.
 

Madi

Espresso King
Joined
Sep 5, 2010
Messages
168
I learnt coding from PHP, but you'll find that it does not really scale very well with large websites. It's good for when your site is small or moderately sized, but you'll need caching system in time, since it becomes inefficient when your site has decent traffic and serves a lot of page views at once.

For that, Python becomes a necessity as it scales better (hint: YouTube is a python based site and scales well as a result) for very big websites. But all coding languages have their weaknesses, however PHP is the easier to learn imo.
Many people working for big enterprises here in my country and (banks as well) do learn ASP.NET and they tell me they use it because they cannot build a bank secure system with PHP or any other language than ASP.NET
 

Sysnative

Habitué
Joined
Mar 1, 2013
Messages
1,103
Oh my bad :D sorry. And why is that? Is it because its a loose language?

Jeff Atwood can explain it much better than I can...
http://blog.codinghorror.com/the-php-singularity/

He's critical there about people criticising PHP, but also justifies why it's so popular. It's everywhere - if you want to code web apps that you want to distribute and be able to run on any server, then you need to know PHP.
 

Sysnative

Habitué
Joined
Mar 1, 2013
Messages
1,103
To add -

I think Python is much better than PHP. I think it was easier to learn, makes more sense, is more fun to code in, and is generally more likeable than PHP. That said, PHP is what I have to code in the majority of the time. There are very few occasions where it would make more sense for me to code in Python than it would to code in PHP.

Depends on the type of application though - I learnt PHP to help support my sites, so it was more of a necessity for me really.
 

Azareal

The AtomBB Overlord
Joined
Mar 7, 2010
Messages
1,133
Jeff Atwood can explain it much better than I can...
http://blog.codinghorror.com/the-php-singularity/

He's critical there about people criticising PHP, but also justifies why it's so popular. It's everywhere - if you want to code web apps that you want to distribute and be able to run on any server, then you need to know PHP.
Ah yes, Jeff Atwood. The thing is that the solution that he pushes (Rails) is simply not that fast. I'd go as far as saying that it's fairly slow.
People don't want to pay extra money to upgrade their servers, just to use a prettier language.

As far as performance is concerned, one of PHP's greatest weaknesses as a language is multi-threading, which Python also doesn't do too well out of the box, however it does have the option of having multiple processes.

We're getting to the point where PHP is only five times slower than traditional compiled languages. That's a massive improvement over the last decade.
 

Madi

Espresso King
Joined
Sep 5, 2010
Messages
168
Can you guys give me links for stuff I need to read before I hop into deciding what language or maybe links that help me decide?
 

Azareal

The AtomBB Overlord
Joined
Mar 7, 2010
Messages
1,133
Can you guys give me links for stuff I need to read before I hop into deciding what language or maybe links that help me decide?
ablog-carlesmateo-com_wp_content_uploads_2014_09_blog_carlesmateo_com_performance_languages-png.31427

There's this. PyPy is a much faster subset of Python. HHVM is an alternative implementation of PHP. PHP7 is estimated to be around about HHVM speed.
 

Sysnative

Habitué
Joined
Mar 1, 2013
Messages
1,103
Ah yes, Jeff Atwood. The thing is that the solution that he pushes (Rails) is simply not that fast. I'd go as far as saying that it's fairly slow.
People don't want to pay extra money to upgrade their servers, just to use a prettier language.

As far as performance is concerned, one of PHP's greatest weaknesses as a language is multi-threading, which Python also doesn't do too well out of the box, however it does have the option of having multiple processes.

PHP has plenty of weaknesses outside of performance, but yeah, I wouldn't necessarily say Python is the best replacement option either. Then again, Google uses Python and Java extensively - got to be some merit to it.

Not suggesting that what Jeff Atwood proposes is the best alternative. PHP 7 might be great, but there is also a reason that Facebook developed Hack.
 

Xambo

Enthusiast
Joined
Sep 14, 2013
Messages
132
Woah, PHP is easier for web sites, python is easier for computer programs/scripts.
 

KenBrace

Aspirant
Joined
Feb 13, 2015
Messages
30
I never had much luck with Python. Tried to learn it once but I don't think it was really my cup of tea. I love PHP though. It wasn't very hard to learn.
 
Top