Live data from Hacker News

Taking PHP Seriously

slack.engineering

561–570 of 673 posts

Re: Taking PHP Seriously

#561
post #353

Earlier quoted context omitted.

But program managers and CTOs and other non-engineers at a company care about scalability, performance, technical debt and quality, right? Let's not pretend that these don't matter once you've gone past the "users actually care about our app" phase, because they do and they affect the bottom line of a company. And IMHO PHP falters in these regards.

Performance? You need to update your act. PHP7 is 3x faster than python and now faster than Java 8 . The only people that can call php slow are masochistic c++ web hacks. https://blog.famzah.net/2016/02/09/cpp-vs-python-vs-perl-vs-...

This benchmark shows things a little bit differently.

http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan...

But I think, what's important to note is that PHP 7 has improved in speed department by a great deal.

Re: Taking PHP Seriously

#562
post #353

Earlier quoted context omitted.

But program managers and CTOs and other non-engineers at a company care about scalability, performance, technical debt and quality, right? Let's not pretend that these don't matter once you've gone past the "users actually care about our app" phase, because they do and they affect the bottom line of a company. And IMHO PHP falters in these regards.

> But program managers and CTOs and other non-engineers at a company care about scalability, performance, technical debt and quality, right? Rarely. Mostly they care about meeting quarterly goals and budgets; and ease of finding inexpensive, more-or-less competent talent. In both of these, PHP excels. I'm currently maintaining an app stack for a Fortune-100 company that, if I told you what it was, you simply wouldn't…

I'd upvote this many time if I could. I am in the same boat--my team helps maintain a ten year old web application that is used by the largest companies in our domain. The application is literally the backbone of data used by these companies to make money. We have reliability issues, and sometimes clients get a little upset, but every year it is the same thing: how much do we need to budget for support?

Re: Taking PHP Seriously

#563
What I find interesting about all this debates about programming languages is that most of the time people fail to remember that they are just that "languages"... Each one has its strong points and flawns, at the end of the day what truly matters is how competent you are at expresing on them and carrying out your goals.

For decades people have been complaining about Php, and how afwul it is, yet still, for decades successful projects have raised (and still do) having Php as its core, just today there 2 posts on the front-page about big companies (Slack, Dailymotion) talking about their Php codebase...

The argument that due the huge volume of programmers using it, it is "bound to" return a few success cases here and there is BS... if that were true we would be flooded about news about how X and Y company succeed "thanks to" using Python, Java or whatever language you deem as "superior", but that doesn't happen... because companies don't suceed "in spite of" Php, they suceed "with" Php, in the same way companies don't suceed "thanks to" X or Y language but "with" them.

When people set to built a piece of sotware they don't have in mind "I wan't to build the most technically perfect code base" or "I want to build the fastest piece of software" because nobody writes software for the sake of it, everyone has a goal... they want to build "a messaging app for teams" or a "video-sharing website" and the best programming language for that, is whichever enables them to do so on the way they need it, with the resources they have, and within the timeframe they set.

And rant as much as you wish, but Php remains king about doing exactly that "enabling people".

Re: Taking PHP Seriously

#564

Earlier quoted context omitted.

Ah yes, the * VZs. From my perspective, there's a few reasons. One, my friends were very privacy conscious and would often either not sign up or use a weird name (like some people do). This made it hard to find people. Two, the user experience sucked hard. Third, they had different domains for different subgroups (I remember one for school children and one for students). Finally, if you went travelling to any other c…

It's a testament to the poor state of the art in user experience for early social networking sites that Facebook had a (relatively) "good" user experience. It has always been horrible, except relative to most of its competitors.

So, not luck. Despite all the down votes

Re: Taking PHP Seriously

#565

Earlier quoted context omitted.

I stopped taking this seriously after "the documentation is really good". Not sure whether this is your real opinion or you are just making fun of people who say that.

We can't argue objectively about an opinion but take a look at this typical page of the php.net documentation: http://php.net/manual/en/function.usort.php It has everything I need to know about the function clearly laid out. The behaviour of sort when elements are the same. A list at the side of related functions that I may want to look at instead. I also like documentation that includes user contributions as these o…

Php documentation is the worst. Some of the reasons..

1. They have exactly one set of documentation pages for all the php versions.

2. Another thing is that documentation can be quite wrong for even the fundamental stuff. I have seen a core developer blast out in reddit that "The documentation is wrong!", when the other party pointed them towards a piece of documentation.

3. Incomplete or shallow description. Go check out the documentation page for Exceptions in php and try to find information regarding the behavior of return statements in a 'finally' block. Now go an see the respective page in Python documentation and see how in depth the documentation is.

And having code samples is not exclusive to Php's documentation..

Re: Taking PHP Seriously

#566

Earlier quoted context omitted.

It sounds like you're trying to write Javascript as if it were Java. I've worked with developers who did this (e.g. http://chriswarbo.net/blog/2014-03-12-trolled.html ) and I would advise that you instead try to write more idiomatic Javascript, or else use some kind of Java-to-Javascript compiler. Your critique of Javascript is basically "it's not Java". I could make a similar critique of Java not being StandardML, b…

I am trying to write a code that is readable and maintainable instead of building complex abstractions. That is where Java classes fit perfectly (unless you are a beginner who had just read a book on patterns and tries to use every one). And I am not only person who needs classes in JS: https://github.com/search?l=JavaScript&q=class&type=Reposito... I do not see any benefit in prototypes. It just makes code more comp…

> I am trying to write a code that is readable and maintainable instead of building complex abstractions.

My point is that what's "readable and maintainable" depends on the language; especially on what facilities it provides, and to some extent community consensus (what's 'idiomatic').

Javascript's main facilities are first-class functions with lexical scope, lightweight key/value mappings (which it calls "objects") and prototypical inheritance between those objects.

Java's main facilities are classes with properties and methods; whilst it's recently gained first-class functions, most Java code has been written without them, and they'll always be in competition with classes+methods (e.g. look at all of the APIs which use single-method classes, like "Comparator").

These are very different, so what's readable/maintainable will differ in each. For example, Javascript's objects are so lightweight that it's idiomatic to write them inline exactly where they're needed, like 'foo({bar: function() { ... }, ...})'.

In idiomatic Java, such objects should be instances of a class, which should either be global or else implement a global interface. Since global class/interface declarations require standalone files, our declarations end up very far away from the use site; this prevents us accessing the use-site's scope and puts us under more pressure to make it descriptive, generic, reusable, etc.

> Yet Javascript has neither of those.

ES6 has a module system, Java has its "package" system. Trying to apply SML practices to either is a bad idea, just as trying to apply Java OO practices to JS is a bad idea, or trying to apply Lisp macro practices to C is a bad idea.

Re: Taking PHP Seriously

#567
post #289

Earlier quoted context omitted.

I don't know if you can do that in Rust (I suspect you can with some effort), but you can certainly do it in Haskell (with slightly different syntax, of course) using a library like Blaze-HTML5. Your argument is a bit spurious; you're right insofar as you can't write PHP in a language that's not PHP.

> I suspect you can with some effort That is my point. You require effort in an order of magnitude greater than with PHP in order to achieve the same result, which in the case of a beginner, is the difference between continuing their journey in programming or abandoning the ship. You are failing to see the big picture and are taking for granted the plethora of initial setup you have to do to begin working with a lang…

>You require effort in an order of magnitude greater than with PHP in order to achieve the same result..

An order of magnitude? Really? I don't think so.

Rust has a library (probably among others) called Horrorshow[1], that exports macros to do html templating.

You claim that it is easy in Php to do html templating. But you miss the fact that it provide zero sanity/security checks while doing so. You need to sanitize every one of those variables before inserting into the html stream.

You see, Php just trades off every bit of sanity and security for a little bit of ease of use. It is that simple.

[1] https://stebalien.github.io/horrorshow-rs/horrorshow/

Re: Taking PHP Seriously

#568
post #554
post #541

Earlier quoted context omitted.

And any PHP thing could be easily prototyped in C# using MVC framework or such. 0 to http-response time is easily comparable if not even faster to what you'd have with PHP. You don't even need IIS. C# is a fine language and I have enjoyed it thoroughly before returning to PHP after some years, but you also can breed monsters with it. Cheers!

touch public_html/foo.php gets me to a http 200 with a valid php file (with the assumption that i already have a public_html directory with mod_php or the like enabled), how fast can you get a C# to http 200 ? :)

I have IIS running with c:\inetpub online (just like you have apache with mod_php). I put a valid foo.ashx up there and voila - the field is level. Okay, the invocation is a bit heavier,

    

    using System;
    using System.Web;

    public class Handler : IHttpHandler {

        public void ProcessRequest (HttpContext context) {
... code ...

versus just

    
but, come on, it's not that bad/difficult, is it?

on an tangential note - I never had imagined i'd be defending the point that C# is as simple as any other language... Funny how life sometimes takes you to unexpected places.

Re: Taking PHP Seriously

#569
post #402

Earlier quoted context omitted.

The way you write code I wouldn't trust you with any language really. You give 6 lines of code and it has display of all the worst practices that I haven't seen since I read a 13year olds tutorial on the language back in 2003.

Hi, can you list all the worst practices you see in this code? Just curious of the full list

I'm no expert but since he didn't reply:

- Use of mysql_ functions (This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used)

- Using the user input directly in the query instead of binding, using prepared statements, or at the very least casting to an integer (don't do this)

- (besides mixing multiple layers) Possible whitespace problems in the output validation (if you're using JSON), you want most php code to be "validated" (like using json functions), to have proper headers, to output types correctly (like booleans). This is also why you should never use PHP's closing tag, except for things like pure PHP templating, it's even in the PSR-2:

> The closing ?> tag MUST be omitted from files containing only PHP.

Not really the case here but you get the idea. It's like you're using a "html view" to output JSON API stuff.

- Possible "Undefined index", or worse, at $ar["name"], $ar["location"]

- Having to write some ugly conditionals if you have more than a single result and need to end the sequence without a comma or do any kind of transformation

- Trying to save vertical space by using expressions in the same line, sacrificing readability

- No error handling. What if the DB connection fails?

- Output is not valid JSON

http://www.php-fig.org/psr/psr-2/

http://phptherightway.com/

http://jsonlint.com/

Re: Taking PHP Seriously

#570
post #523

Earlier quoted context omitted.

it's a business decision comparison, not a technical categorical comparison. you need something to receive http request and return http responses, and you're comparing different popular (because hiring, training, and available community / support resources) ways to do that. they might be apples and oranges but at that level you're concerned with comparing fruits.

In this case it was a technical comparison; the original poster stated, "php's performance was an order-to-two or magnitude better than rails". If you are making a technical comparison then it needs to be at the correct layer of abstraction. If we were to compare performance of Laraval and Rails that would be a fair comparison. If we are comparing on performance then PHP should be probably be compared to Ruby+Rack si…

i am the original poster.

i was clarifying the compassion.

Post reply on HN