Php or Python or both?

  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »

71 Replies - 3037 Views - Last Post: 17 October 2017 - 11:46 PM

#16 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1828
  • View blog
  • Posts: 5,755
  • Joined: 15-January 14

Re: Php or Python or both?

Posted 30 August 2017 - 12:19 PM

Quote

Not sure why you'd bother, to be honest.

You're not sure why people would bother to improve things? Well, to each their own, but there's a guide to help people migrate.

Quote

It's a language designed by amateurs for amateurs.

Right, in the same way that the Wright Flyer was designed by an amateur pilot. This isn't Personal Home Page Tools we're talking about here, this isn't PHP version 2 or 3. We're talking about modern PHP. Today, Andi Gutmans is a GM at Amazon Web Services, in addition to his work on PHP and Zend. He and Zeev work with the Apache Software Foundation and the FSF. You're welcome to show up to a ZendCon and call everyone amateurs if you want, the last time I went I met Andy, Zeev, and some of the core developers, they're accessible, but it's not going to go over well. These people take great pride in their work, regardless of what you think about Rasmus Lerdorf's Personal Home Page Tools.
Was This Post Helpful? 1
  • +
  • -

#17 jon.kiparsky  Icon User is offline

  • Chinga la migra
  • member icon


Reputation: 10681
  • View blog
  • Posts: 18,289
  • Joined: 19-March 11

Re: Php or Python or both?

Posted 30 August 2017 - 12:44 PM

Not sure what anyone is trying to salvage about PHP. It's broken to the core - interleaved html and source code, lists that are also arrays, coercion hell, etc, etc. If you fixed everything that's broken about it, you've had to invent a new language. If you're doing that, you're probably making a whole new set of mistakes, which you're going to have to fix. Why not just use something that works already? (or, if you really want a new language, just admit it and call it that - and maybe get someone who knows what they're doing to help with that)
Was This Post Helpful? 0
  • +
  • -

#18 ge∅  Icon User is offline

  • D.I.C Lover

Reputation: 180
  • View blog
  • Posts: 1,126
  • Joined: 21-November 13

Re: Php or Python or both?

Posted 30 August 2017 - 01:43 PM

Your arguments are rubbish. Interleaved html and source code is depricated since the beginning of times, there has always been an identical operator === which does not do type coercion, and functions now have type return values. I don't know what you are talking about concerning lists.

It is not because a language can do something that it is something you should do. You can apply separation of concerns and a lot of other good design principles in any language.
Was This Post Helpful? 0
  • +
  • -

#19 jon.kiparsky  Icon User is offline

  • Chinga la migra
  • member icon


Reputation: 10681
  • View blog
  • Posts: 18,289
  • Joined: 19-March 11

Re: Php or Python or both?

Posted 30 August 2017 - 02:03 PM

View Postge∅, on 30 August 2017 - 03:43 PM, said:

Your arguments are rubbish. Interleaved html and source code is depricated since the beginning of times,

Really? Looks like nobody told PHP that...

Quote

there has always been an identical operator === which does not do type coercion,


Exactly what I'm talking about. If you have to use a special operator to get it to work right, you're using a broken language.

Quote

I don't know what you are talking about concerning lists.


PHP doesn't distinguish between lists and arrays, leading to all sorts of fun bugs. (some of which you'll find if you look in the PHP section of this very site)

Quote

It is not because a language can do something that it is something you should do.


A language should provide a useful set of tools for solving problems. Those tools should offer reasonable interfaces and they should behave in reasonable ways. PHP is a complete mess and it should not be used.

Quote

You can apply separation of concerns and a lot of other good design principles in any language.


Yes, I suppose that's true. I don't see how that's an argument in favor of any language, though. A language worth using is designed for programmers. PHP is not designed at all.
The only way you could use PHP to write good code would be to use it to implement a real language and then write in that language.
Was This Post Helpful? 0
  • +
  • -

#20 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1828
  • View blog
  • Posts: 5,755
  • Joined: 15-January 14

Re: Php or Python or both?

Posted 30 August 2017 - 03:42 PM

Quote

It's broken to the core - interleaved html and source code

Sorry, but how exactly is that an indication that PHP is "broken to the core?" While not the only use, the major use case for PHP is through a web server, serving content. Anything that is not inside PHP tags get sent straight to the output pipeline. How is that broken in any way, shape, or form? Is it just "broken" because you don't think it should work like that, even though it was specifically designed to work like that? I mean, it was a specific design goal, that is literally the exact opposite of being broken. It works exactly like they designed it to work concerning what gets sent straight to output, and what goes to the PHP parser/interpreter. Obviously, no one is forced to put non-PHP data in the same file as PHP code, you don't get a ticket or anything if you decide not to do that, and in many, many use cases there's no reason to mix non-PHP data with code, but it's an option, and it makes it a lot quicker to get certain things done.

Quote

If you have to use a special operator to get it to work right

It's not "a special operator", it's "an operator". Different operators do different things, it's weird how that works but it's true.

Quote

PHP doesn't distinguish between lists and arrays

Is that what the current issue of Goalpost Position Weekly says, one of the requirements for a "real language" is that it has to have native support for a structure that Jon considers to be a "list" but not an array? Here you go, now doubly-linked for your pleasure.

Quote

A language should provide a useful set of tools for solving problems. Those tools should offer reasonable interfaces and they should behave in reasonable ways.

Similar to the SPL.

Quote

PHP is not designed at all.

See, I read a statement like that, which is obviously and demonstrably false, and may just be trolling, and it casts doubt on every single other thing you've said. If you're willing to make blatantly false statements here, then why should anything else you say be believed? It's kind of like the things that Trump says, it creates a problem of credibility. Why should anyone assume that you know anything about PHP if you're just going to make clearly false statements about it like they're true?
Was This Post Helpful? 1
  • +
  • -

#21 jon.kiparsky  Icon User is offline

  • Chinga la migra
  • member icon


Reputation: 10681
  • View blog
  • Posts: 18,289
  • Joined: 19-March 11

Re: Php or Python or both?

Posted 30 August 2017 - 05:19 PM

Quote

While not the only use, the major use case for PHP is through a web server, serving content. Anything that is not inside PHP tags get sent straight to the output pipeline. How is that broken in any way, shape, or form?


That is broken because if used as directed, PHP creates confusing and difficult code. Surely you'd agree that one of the fundamental goals of language design would be to reduce complexity, no? Interleaved code is a complexity multiplier. (it gets even better when you use the traditional "compose your SQL on the fly as a bunch of strings and pray" technique within this mess - but please tell me you've got an ORM now, right?)
Think separation of concerns: a given piece of code should deal with one thing at a time. Calculation of content is one thing, presentation markup is a different thing, and they should be handled separately. Think of the most basic clean code concepts - if you have a function which does "print X squared", you have a crappy function. Instead, you want a function which "squares X" and another one which prints a number. This is literally stuff from your intro CS course, right? But PHP apparently doesn't know about clean code.

Quote

"It's not "a special operator", it's "an operator". Different operators do different things, it's weird how that works but it's true.


Okay, I can understand one operator for assignment and another for comparison, this makes sense to me. But when you have one operator for comparison and another operator for "no, really, compare it right" then you have one comparison operator too many. This is a bad response to a bad mistake. PHP should have been abandoned when the need for the triple-equal was discovered, because it was clear at that moment that things had gone irretrievably off the rails.

Quote

one of the requirements for a "real language" is that it has to have native support for a structure that Jon considers to be a "list" but not an array?


Well, a list and a map are different things. And a structure that acts like one and can turn into the other without warning is a brain-damaged structure, and amounts to a very clever tool for sabotaging the code of anyone foolish enough to use the language.
It's funny, Art, I think I remember you fielding a question about exactly this design failure a while back.

Quote

obviously and demonstrably false


To me, design implies forethought and intention. PHP shows no evidence of this, either in its history or in its result. It started out as a bag of tools, and it was added to without and sort of plan, and that's how it got this way. It's like building a house by starting with a shack and nailing another shack to it and knocking through a door. Sure, you've got two rooms, but wouldn't it have made a better building if you'd just torn it down and built a house?
Was This Post Helpful? 1
  • +
  • -

#22 ge∅  Icon User is offline

  • D.I.C Lover

Reputation: 180
  • View blog
  • Posts: 1,126
  • Joined: 21-November 13

Re: Php or Python or both?

Posted 31 August 2017 - 01:30 AM

Actually, I like reading jon, it's refreshing to read so much bad faith ;)

I agree the PHP documentation does not provide a good example, but so are other documentations.

For instance, there is a lot of client-side devs out there using jQuery who repeat DOM selections endlessly because they read code in the documentations going like $("#foo").css("top", 0); – It's a simple way to show features : you don't distract people with variables and other things unrelated to the feature you are showing, and you want your code to work so that people can copy/paste it and experiment : the code in documentations is not the best code you can write, it is the simplest working code you can write – so every time they need to do something with #foo, instead of storing the jQuery object in a variable, they recreate another jQuery object (I doubt jQuery caches the result of the $ calls because the DOM can change between two calls) because they have never seen anything else in the documentation. They also increment class names and concatenate jQuery selectors for the same reason : because to them, the most natural way to use jQuery is to write a string inside the $ function.

It is the same thing with PHP : you see it written like that in the doc, because it's a simple way to demonstrate a feature, and if you don't know any other languages, if you have never programmed anything, you are led to believe it is the most natural way of doing things.

This post has been edited by ge∅: 31 August 2017 - 01:36 AM

Was This Post Helpful? 2
  • +
  • -

#23 Atli  Icon User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4238
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: Php or Python or both?

Posted 31 August 2017 - 03:04 AM

jon.kiparsky said:

Quote

"It's not "a special operator", it's "an operator". Different operators do different things, it's weird how that works but it's true.


Okay, I can understand one operator for assignment and another for comparison, this makes sense to me. But when you have one operator for comparison and another operator for "no, really, compare it right" then you have one comparison operator too many. This is a bad response to a bad mistake. PHP should have been abandoned when the need for the triple-equal was discovered, because it was clear at that moment that things had gone irretrievably off the rails.

I take it Java should be abandoned too, then?
if (string1 == string2)
// NOPE!

if (string1.equals(string2))
// Yep



Of course it shouldn't be. It's a ridiculous expectation, in both cases. Both were designed from the start to operate a certain way, making things like this necessary. - The PHP == operator was always meant to check for equal values in PHP's typical type-indifferent manner. Obviously it would then need a second operator to check the type as well. This was not some "mistake" that was later discovered and worked around: it was designed to be like this, and is working exactly as it was meant to.

PHP has it's issues, but you are not helping your case with nonsense statements like that.
Was This Post Helpful? 2
  • +
  • -

#24 nesir28  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 35
  • Joined: 11-August 17

Re: Php or Python or both?

Posted 31 August 2017 - 04:19 AM

Ok so it seems i got more than i bargained for , i have read through this thread , and while i will not pretend to know much of what you are talking about ,since i have yet to dip my feet into one (or now both ) of these languages i did some external searching on the subject. It seems a that there is in general a argument among web developers about which is better. Wiki came up when searched not that i trust everthing written on there , but even this article ,https://wiki.python....oin/PythonVsPhp leaves the question open. To throw a spanner in the wheel some people are talking about ruby as a competitor too ...

Sorry i come to think of it im not even sure any of you would really find that link of value information wise.
Was This Post Helpful? 1
  • +
  • -

#25 ge∅  Icon User is offline

  • D.I.C Lover

Reputation: 180
  • View blog
  • Posts: 1,126
  • Joined: 21-November 13

Re: Php or Python or both?

Posted 31 August 2017 - 05:29 AM

This link is neat.

It reminds me that python has cool data types. I remember playing with sets, I found it very natural and I regret it is not present natively in JS for example. They added a set object but there are no built-in set operations such as difference, intersection, union, etc. which is really a shame because they could have been optimised and these are things I personally do a lot.

I am not sure comparing the languages themselves is relevant, personal preferences aside (if you hate the language...). I am personally going full JS, client and server side, for my personal projects, but I use PHP at work when it's available.
Was This Post Helpful? 0
  • +
  • -

#26 jon.kiparsky  Icon User is offline

  • Chinga la migra
  • member icon


Reputation: 10681
  • View blog
  • Posts: 18,289
  • Joined: 19-March 11

Re: Php or Python or both?

Posted 31 August 2017 - 07:14 AM

View PostAtli, on 31 August 2017 - 05:04 AM, said:

I take it Java should be abandoned too, then?


Actually, that's not entirely parallel, since .equals is a method on a class, not an operator. I would assume that PHP has a similar construct in its objects. Since we're on the subject, in python you'd overload the __eq__ method on your object and then x == y just means x.__eq__(y). Obviously, this opens you up to some abuse, and I prefer to be pretty conservative with this, but it's nice to be able to use the == operator to mean "equals" and not "identity".
As an aside, python does actually offer an "identity" operator but because real comparison is so easy, it's only ever really used for null checks, ie if book is None

But taking your point more broadly, yeah, I'm not madly fond of Java's sorta-OO design. Python and Ruby, it seems to me, made a better bet when they took the object-oriented paradigm seriously. Java and PHP, I think, both suffer because they chose to hedge their bets and make non-object primitives part of the day-to-day life of the programmer.

Quote

This was not some "mistake" that was later discovered and worked around: it was designed to be like this, and is working exactly as it was meant to.


I think we're going to have to agree to differ on this one. In my view, triple-equals exists only because of PHP's over-broad concept of coercive equality, which to me is a mistake, in that it is a prolific source of bugs, in that == comparison does not behave as expected and fails quietly. That is the fundamental mistake which I was referring to - once you realize that you've screwed up that deeply, it's time to just give up and start again.
Was This Post Helpful? 0
  • +
  • -

#27 jon.kiparsky  Icon User is offline

  • Chinga la migra
  • member icon


Reputation: 10681
  • View blog
  • Posts: 18,289
  • Joined: 19-March 11

Re: Php or Python or both?

Posted 31 August 2017 - 07:48 AM

View Postnesir28, on 31 August 2017 - 06:19 AM, said:

Ok so it seems i got more than i bargained for ,


Excellent! Glad we could give you some food for thought.
I hope this is obvious, but just to be clear on this, this is a long-running argument and there are many points of view to consider here. Namely, the right one and the other ones. :)

Quote

this article ,https://wiki.python....oin/PythonVsPhp leaves the question open.


That looks like a collection of "stuff people have said". Interesting, but for you I think the most useful part of that article will be when you drill down into all of the jargon and the concepts and really try to understand what each of those bullet points really means.

Quote

To throw a spanner in the wheel some people are talking about ruby as a competitor too ...


Ruby is certainly a language worth considering, both on its own merits as a general-purpose language and as a web-development language with rails and (less commonly) sinatra.

To sort of wrap this up, since I feel like the horse is well tenderized at this point, for you the novice developer the main differences between PHP and python or ruby is that PHP is
  • very much a domain-specific language targeting the web
  • a slightly easier path to up-and-running websites (VERY slightly - the django quick-start documentation is very good, and will get you a basic site very quickly)
  • cheaper and easier hosting


The latter is the most significant advantage for me - if you want to have a site up and available to others, and you're in a hurry and on a budget, that's PHP's sweet spot. Drop the files on any cheap hosting service and you're off to the races.

However.

Django has some real advantages if you're looking for long-term play in the web ecosystem
  • python is a general-purpose language with hard-core tooling around math and data, which PHP will never offer. basically, python will be useful to you in ways PHP will never dream of.
  • django imposes a basic structure on your web code which will help you a lot, particularly as a beginner. Basically, you can learn some useful things about programming by following the standard django practices and then asking yourself "why did they do it this way?"
  • long-term, django will give you better code, by which I mean more maintainable, more extendable, and more pleasurable code. You will enjoy your life more if you write django than if you write PHP. (notice that in the above discussion, I'm having more fun than my colleagues)


If you want my best and final advice, I would suggest that you try building the same website three times. It should be something VERY simple, with the most token back-end requirements imaginable. For example, a simple blogging site or something. Users can create accounts, sign in, create articles, and comment on other people's articles. Do it in PHP, in django, and in rails. See which you like best.

You'll learn more from this exercise in a few weeks than from reading my rantings for a year, I promise you that.
Was This Post Helpful? 1
  • +
  • -

#28 jon.kiparsky  Icon User is offline

  • Chinga la migra
  • member icon


Reputation: 10681
  • View blog
  • Posts: 18,289
  • Joined: 19-March 11

Re: Php or Python or both?

Posted 31 August 2017 - 08:20 AM

View Postge∅, on 31 August 2017 - 03:30 AM, said:

I agree the PHP documentation does not provide a good example, but so are other documentations.


An excellent point - it's true that documentation examples sometimes include less-than-ideal code in order to get the examples to run. Monkey-see-ing the docs is not a way to get great code, I agree. However, I don't see where PHP ever says "don't do inline". Might be missing something, but I didn't see it.


Quote

Actually, I like reading jon, it's refreshing to read so much bad faith ;)/>


given that this is the closest I come to a religious conviction, I don't think "bad faith" is really the best choice of words. :)
Was This Post Helpful? 0
  • +
  • -

#29 ge∅  Icon User is offline

  • D.I.C Lover

Reputation: 180
  • View blog
  • Posts: 1,126
  • Joined: 21-November 13

Re: Php or Python or both?

Posted 31 August 2017 - 09:31 AM

You know, I have read ruby on rails code where logic is mixed with the template, and the guy presented it to me as a feature, and he loved it, he said something like "it's what's so great about Ruby" and I found it extremely rubbish.

Many libraries use template engines allowing logic, such as Smarty (Prestashop) and I just hate it. Of course, you don't need to be crazy and change the data on the fly, do calculations and the likes, but people do it, so what is printed is not what is in the database, and to know what is going on you have to read hundreds of lines of code mixing logic and HTML. Awful!

I personally use logic-less template engines like Mustache because they don't even have conditions. They have loops and they don't print some things when the corresponding data slot is empty. That's it. It forces me to send the data correctly structured, or do the crazy stuff I need to do in another file with no HTML in it. My template files are always super clean. But sometimes it's tedious.

I think it's a matter of preference and self-discipline. If the templating system of entire CMS are built like that and if writing logic in templates is promoted by these CMS, you probably can't just call it rubbish. On the other hand, you can have a tool which allows you to do powerful stuff and save your ass once in a while, but have the self-discipline to only use it as a last resort.
Was This Post Helpful? 1
  • +
  • -

#30 jon.kiparsky  Icon User is offline

  • Chinga la migra
  • member icon


Reputation: 10681
  • View blog
  • Posts: 18,289
  • Joined: 19-March 11

Re: Php or Python or both?

Posted 31 August 2017 - 10:00 AM

Yeah, the standard django templating language allows this sort of nonsense as well. We have house style rules about when this sort of thing is allowable. For example, looping over data for formatting is allowable, but templates should not hit the database. There's no perfect world, it's true.
Was This Post Helpful? 0
  • +
  • -

  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »