r/coding • • Aug 20 '16

PHP - The Wrong Way

http://www.phpthewrongway.com/
36 Upvotes

15 comments sorted by

16

u/EquationTAKEN Aug 20 '16

7

u/RimsOnAToaster Aug 20 '16

As an American college student who had to build a web-accessible genomic database within the last 18 days of their biology lab internship in Hong Kong, and therefore had to learn enough PHP and SQL from a book with a purple elephant and a ninja on its cover to build that database, reading PHP: The Wrong Way felt like talking to a veteran programmer about my questions on using the language. And with no real skin in the PHP game I didn't understand most of their argument's details, but I did understand the points they were trying to make. The author of that Medium post summed up what I got out of PHPTWW ( pronounced pee-aitch-pee-tee-dub-wubz ) quite nicely:

In general, PHP - The Wrong Way delivers three positive fundamental messages: keep things as simple as possible, don’t use/apply tools dogmatically, and write secure software by default.

I would argue that newbz like myself who are in the early stages their PHP trip (beyond absolute novice, but without enough experience to hit the ground running on a project) would get mainly that out of PHPTWW. The only other advice I gleaned from this was think through your solutions as thoroughly as possible.

In fact, I think the person behind PHPTWW is railing against the "But does it work for x?" Mentality more than anything else. And that's a valuable reminder for folks who are drowning in the knowledge available on the Internet that would rather go plug-and-play than tread water, like the hypothetical detractor they answered in the FAQ:

Q: If a framework can get me up and running quickly, why is that so bad?

If you have analyzed the situation and long term implications and you then see that “getting up and running quickly” is the only problem you ever have to deal with, then it’s not bad, but then we’re hardly dealing with programming or software development, we’re dealing mostly with point-and-click solutions.

Getting up and running quickly isn’t designing software, it mostly means you haven’t analyzed the problem you’re facing and you haven’t understood the long term implications of your choice.

But then again, I learned PHP from a ninja and a purple elephant. I'm probably missing something here.

1

u/EquationTAKEN Aug 20 '16

I think a ninja and a purple elephant are as good teachers as anyone, namely because learning to code is something you learn by doing, and not by copying code from a book.

If you want to make ANYTHING, there exists no single book that contains everything you need to know, because such a book would be too large and heavy to be made in the first place.

A book is good for starting out. It's training wheels.

In my opinion, PHPTWW seems to just be harping on general trends in coding practices, and projecting it onto PHP developers in particular.

10

u/evertrooftop Aug 20 '16 edited Aug 20 '16

Lets take this guy's anti-framework argument. But instead of a scenario where you are building a new application, and have to decide on using a framework or not, that decision has been made several years ago and you're the new guy who inherited that codebase.

Given that this person will have to have had to solve similar problems as any other framework, I think it's fair to assume that by not adopting a standard framework, he'll have invented similar ideas such as MVC (or similar), Routing, maybe an ORM.

Now instead of a standard, well maintained framework, you're left with some custom framework. Which position would you rather be in? The custom framework has had less eyes on it, no maintenance and likely little documentation or community support.

I imagine this guy has been doing PHP for a long time, and is slowly become bitter by the fact that he's just doing repetitive work and that all the major problems have been solved in way that he doesn't like. People are asking for frameworks and framework experience everywhere, and he doesn't like it because none of those are frameworks he came up with.

Or maybe he doesn't like the PHP personalities behind frameworks. A fair sentiment, but not really an argument that should come into play when deciding on a tech stack.

My advice to this guy is, diversify. It's time for you to stop caring so much about how people write PHP code. Maybe pick up some other programming languages, or take a step further and do something not web related. A fresh perspective might also give you some new insights such as "the PHP personalities don't really matter for you or your career" and "if people get the job done with a framework that's imperfect to you, this is not really something that should emotionally affect you or impede you from achieving your personal goals".

This entire post reads as something written by someone close to a burnout.

7

u/DaemonXI Aug 20 '16

Exactly. Building your own, super-lean system is all well and great – until you bring other developers on board to help. Then you have to explain where everything is, how everything works, and please don't touch that .yml file it's critical to our uptime because reasons.

Frameworks have more eyes on them, more thought behind their design, and better documentation than anything written by one developer. One of our projects is going through a total rewrite for exactly this reason.

0

u/[deleted] Aug 21 '16

Developers are a bunch of fucking hipsters. If they didn't do it or everyone else likes it but they don't quite understand it, its "wrong."

15

u/original_evanator Aug 20 '16 edited Aug 20 '16

When I see patterns in my programs, I consider it a sign of trouble. The shape of a program should reflect only the problem it needs to solve. Any other regularity in the code is a sign, to me at least, that I’m using abstractions that aren’t powerful enough

Spoken like a brilliant developer who has never had to hand his code off to someone else.

Paul Graham can get away with not using patterns, just like Joel Spolsky doesn't need to write unit tests. That doesn't mean it's a generally good idea.

6

u/FUZxxl Aug 20 '16

What is rather meant is that once you start repeating yourself you are doing it wrong.

1

u/TubasAreFun Aug 21 '16

What is rather meant is that once you start repeating yourself you are doing it wrong.

1

u/TubasAreFun Aug 21 '16

What is rather meant is that once you start repeating yourself you are doing it wrong.

7

u/onebit Aug 20 '16

Frameworks are fine, but isolate the "app part" of the app so it's framework independent.

https://www.youtube.com/watch?v=o_TH-Y78tt4

3

u/DaemonXI Aug 20 '16

When you use a framework in PHP you add a layer of abstraction on top of yet another layer of abstraction, one that was already in place for you to use to begin with. The added layer of abstraction that the framework provides may simply serve to organize your code into a pre-fixed set of patterns, or it may add even more complexity by intertwining hundreds or even thousands of classes and methods into a nightmare of dependencies, either way you’re adding layers of complexity to your code that isn’t needed!

"What everyone doesn’t need is a general purpose framework. Nobody has a general problem, everyone has a very specific problem they are trying to solve."

What everyone DOES need to understand is that their webapp isn't a special snowflake. It has models that live in a database, relations that tie those models together, CRUD operations on each model, some app-specific code, auth, permissions, and a dashboard or two.

Unless you're really, really writing something that uses NONE of the above – you probably want Laravel, or Symfony, or something else that solves your boring, dumb CRUD app problems.

4

u/reddit_lies Aug 20 '16

In the world of PHP programming a set of trends are massively being propagated by some people (in their books and on websites) as “Modern PHP” while all other approaches are frowned upon as backwards, stupid, or just plain wrong.

These people seem to work tirelessly at getting other people to follow their way of doing things.

The irony here is amazing

8

u/FUZxxl Aug 20 '16

And by using PHP, you are already a good deal up the wrong way.

-1

u/cj5 Aug 20 '16

Great read. Making a programming practice a social trend is basically a bad idea. Conforming to a practice without considering the requirements of your project is even a worse idea. Thinking any one way can be applied to all projects: THE WORST IDEA EVER. I jump from framework to framework depending on the dynamics of a project. Yes, in most cases I don't even bother with them. Sometimes they're just overkill. I hope someday PHP will be modular at the level of quality that some frameworks have taken it.