Live data from Hacker News

PHP the Wrong Way

phpthewrongway.com

71–80 of 194 posts

Re: PHP the Wrong Way

#71

Earlier quoted context omitted.

a "single for loop" and a "fibonacci method" are different enough. there are loads of people who take money for working in PHP, and they're closer to pc86's view of things than yours. I wouldn't say "99%" but... there's a lot. A LOT. I've run (and attended) several local tech meetups in my area, and ... there's a huge amount of technical talent, but also a surprising number of people bumbling around with wordpress, d…

Here, fibonacci implemented in a single for loop (obviously, there's cruft in there to modify the array but there's no need for us to be facetious). Feel free to wrap function call around it if the procedural nature makes you feel icky. $iterations = 50; $numbers = [1,0]; for($i=0; $i You seriously expect me to believe that 99% of PHP developers couldn't have written this?

I'm not sure why you posted code here - I don't think the possibility of this code being written was ever in doubt.

Personally, I already said I don't think 99% is accurate, but... we'd have to define terms.

"PHP developer" - is that different from someone who modifies (or creates) PHP code as part of their job to earn a living? Maybe they're just "PHP workers"?

The very notion of "array_shift" and "array_push" is foreign to a non-trivial amount of PHP workers.

The word fibonacci is foreign to a hell of a lot of people who make their living in code.

I don't think you interact with beginners/amateurs enough to understand where pc86 was coming from.

If you describe fibonacci in english, gave some working parameters, I would be willing to bet 15-20% of people who self-identify as "PHP developers" (and get paid a wage for it) would struggle and ultimately fail that test above.

I still see code (not a lot, grant you) where people have not understood what passing a parameter to a function call means, and instead the first line of each function call is a string of "global $foo" stuff.

Re: PHP the Wrong Way

#72
post #7

Earlier quoted context omitted.

The very existence of PHP is a contradiction, so I wouldn't sweat to much about it. But speaking of boolean logic, negating "always use a framework" does not yield your interpretation.

"The very existence of PHP is a contradiction" Uhm no for me coming from a C background I love PHP since its basically C with a lot of the boring/repetitive stuff abstracted away Good PHP code exists, it only got a bad name due to "web developers" with no formal programming education stumbling across PHP and going "aha this can generate my html etc" and then proceeding to make a pile of mistakes. PHP is a hammer, bla…

> "web developers" with no formal programming education

I know developers who couldn't afford a "formal programming education" or couldn't/didn't go for various reasons, and they'd blow most "formally educated" developers out of the water. I think the word "formal" is surplus here.

> stumbling across PHP and going "aha this can generate my html etc" and then proceeding to make a pile of mistakes.

This holds true for anything in life, really. Anyone who uses a tool which they don't understand will sooner or later make a mistake with that tool, and keep making mistakes.

WARNING: The next might be anecdotal, so YMMV. I used to write a lot of code in PHP (and I am grateful, because it is partially responsible for introducing me to the world of programming), but I slowly moved away from as time passed.

The main problems with PHP (apart from some interpreter issues/design decisions which I won't cover, because there's an abundant amount of that online already) are the fact that:

  1) it probably has the lowest entry barrier, with near-instant gratification and

  2) there is an insane amount of online tutorials, blog posts, courses and even "books" created by people who *think* they understand programming (and PHP), but actually don't.
Web development is not any more trivial than system development, or any less complicated. This probably goes for any type of development.

To be proficient in either, you need need to cover a very wide range of domains, but PHP resources makes you feel like web development is trivial and easy. Anyone who assumes web development is trivial doesn't really know shit about web development (excuse the language).

tl;dr: I mostly agree with you that PHP's design decisions aren't the only problem bad PHP code exists, and that people who use PHP are largely to be blamed for their own mistakes.

Re: PHP the Wrong Way

#73
post #23

Earlier quoted context omitted.

In my experience using a framework does not prevent spaghetti code.

If you want to write spaghetti code, you can write it whichever approach you take. It's more about making it difficult to shoot yourself in the foot.

Frameworks allow you to shoot yourself in the foot with a Tank.

Re: PHP the Wrong Way

#74
post #48

Earlier quoted context omitted.

Probably spl_autoload [1]. [1] https://secure.php.net/manual/en/function.spl-autoload.php

that's what I thought poster might have meant, but.... it's not an autoloader, it's a way of registering autoloader code.

You're thinking of spl_autoload_register. spl_autoload absolutely is an autoloader, and it is registered via spl_autoload_register.

Re: PHP the Wrong Way

#75

Earlier quoted context omitted.

"The very existence of PHP is a contradiction" Uhm no for me coming from a C background I love PHP since its basically C with a lot of the boring/repetitive stuff abstracted away Good PHP code exists, it only got a bad name due to "web developers" with no formal programming education stumbling across PHP and going "aha this can generate my html etc" and then proceeding to make a pile of mistakes. PHP is a hammer, bla…

PHP is pretty objectively bad. For every thing PHP does decently well, something else does it better. Except for this one weird trick: PHP absolutely bulls-eye nothing-but-net nailed deployability before deployability was even a word. In 2000, you could download an installer that set up Apache, MySQL and PHP on your Windows box (and it worked, first time and every time), you could fire up Notepad and 15 seconds later…

FWWIW Ruby is my favourite language, but it's nowhere near being as beginner-friendly for web development as PHP. This is mostly because PHP was designed as an "embedded" language from the grounds up, and by the fact it's so widely supported by hosting providers. Most hosting providers have no support for Rails (or general rack-based applications); most that do, offer patchy support, though.

Furthermore, I remember a few years back, Ruby was a hassle to set up, especially on Windows.

Re: PHP the Wrong Way

#77
post #72

Earlier quoted context omitted.

"The very existence of PHP is a contradiction" Uhm no for me coming from a C background I love PHP since its basically C with a lot of the boring/repetitive stuff abstracted away Good PHP code exists, it only got a bad name due to "web developers" with no formal programming education stumbling across PHP and going "aha this can generate my html etc" and then proceeding to make a pile of mistakes. PHP is a hammer, bla…

> "web developers" with no formal programming education I know developers who couldn't afford a "formal programming education" or couldn't/didn't go for various reasons, and they'd blow most "formally educated" developers out of the water. I think the word "formal" is surplus here. > stumbling across PHP and going "aha this can generate my html etc" and then proceeding to make a pile of mistakes. This holds true for…

Of course I did not want to generalize and stereotype

Yes PHP makes it easy for ANYONE to stumble into scripting/programming

But IMHO that is a good thing, the world needs more people getting into programming, if they make mistakes so be it, learning from mistakes is a good way of learning anything.

Re: PHP the Wrong Way

#78
post #69

Earlier quoted context omitted.

> currently accepted best practice for autoloading According to who? FIG? Are you aware that php has a built in auto loader that supports namespaces and is written in C? > compose projects based on the packages they need. Ah, the NPM/Composer golden brick road to development. Aka, the "I don't know what this is but I'm gonna lick it" approach to development, where you end up with 50 "micro-frameworks" or "utility lib…

> According to who? FIG? According to the vast majority of authors of the most widely used and tested PHP libararies. > Are you aware that php has a built in auto loader that supports namespaces and is written in C? You mean the autoloader builtins that composer uses under the hood already? This is better than a 1 line include how exactly? > Ah, the NPM/Composer golden brick road to development. Aka, the "I don't kno…

> According to the vast majority of authors of the most widely used and tested PHP libararies.

So, FIG.

"Group of developers say that groups' work is the best. News at 11."

> You mean the autoloader builtins that composer uses under the hood already?

No, spl_autoload is a working namespace aware autoloader. Composer uses a bunch of userland code.

> I don't understand what you're saying here, everyone should be writing their own libraries from scratch?

Did I say that? I've seen, multiple times the negative consequences of the current fad to rely on 25 separate, single-purpose 3rd party Libs, all of which are basic functionality that a well thought out library would give you, but with the added "bonus" of each relying on 20 other libraries to do basic things.

> It has always been up to the developer to vet the dependencies they choose to include in their project. That applies to every language ecosystem, not just Node.

Do the vast majority of developers know that? Because the ones I've had the "pleasure" of working with, definitely don't.

Re: PHP the Wrong Way

#79
post #51

Earlier quoted context omitted.

> If its under 50 lines of code for some simple processing It doesn't matter how much lines you write. It has nothing to do with the number of lines but the functionalities and how many developers review that piece of code. Furthermore more a third party codebase is usually the code you don't have to test. You keep on talking about frameworks like it's a bad thing, but all frameworks are not equal in size nor feature…

You still don't need a framework for that. Just use composer to install a bunch of well-tested, feature-rich, but fully independent packages. Start your script with include 'vendor/autoload.php'; and add 50 lines of your own code.

Don't forget to understand how/why/what those other packages do.

Including a package based on the contents of its packagist description alone is basically like reading the ingredients for a pizza and then eating a bag of flour.

Re: PHP the Wrong Way

#80
post #57

PHP community had always been anti-frameworks and anti-libraries. I worked at company where use of third-party libraries was entirely forbidden on most projects. I think it's because: - Quality of PHP frameworks is low (at least it was last time I used it) - PHP parses and evaluates whole libraries and framework code on each requests. There's proprietary commercial (lol!) software to enable at least caching of byteco…

If you haven't used PHP since composer became a standard in projects, you don't know modern PHP.

"Modern PHP" being one of the trigger words in the OP.

That said, in terms of timeline, PHP has gotten better as a whole since then.

Post reply on HN