loading...

How is it like to be back from Node.js to PHP?

Adnan Babakan (he/him) on November 05, 2019

Hello there community!!!! It's been a long time since I've written my last post because I was working on some projects full time and I didn't have ... [Read Full]
markdown guide
 

This idea that PHP is somehow unique in it's ability to allow you to write spaghetti code is absurd.

Have you not seen 10,000 line Javascript files of uncommented procedural code? I have. And oooo boy the hoops you have to jump through to write OO JS code in structured files is nuts.

Now granted, some languages provide more structure, or frameworks out-of-the-box... but whew JS is not one of those languages.

Writing bad PHP code is lazy programming or beginner mistakes. Let's stop shifting blame.

 

Couldn't agree more. Additionally, the more recent features and tools of PHP have made it a more pleasant experience.

 

Indeed, bad code is on the programmer not the language ( at least at the initial phase), there is a point as you learn more techniques, OOP, SOLID, PHP Unit, and good practices ,your code structure and refactoring gets better, you dont have to write spaguetti code unless you want to or are very new to programming,a programming language doesnt make you a good programmer from day 1. Some are easier to get started and thats where you see bad code spread everywhere, ex. Using deprecated mysql code instead of PDO or mysqli at least.

 

Thank you Juan for you comment. You are totally right and I couldn't agree with you more.

 

Thanks for you comment. And yes I agree with you too in some ways but still PHP's nature is the spaghetti code, though I'm a PHP programmer myself and more than half of my programs have been written in PHP XD

 

It's literally not.

Php mixed into html has been discouraged for like a decade now. Beyond that it's a procedural & OO language. Style or mess... is up to you.

Spot on. Rubbish code is on you as the programmer. If people are writing junk in PHP, they're writing it elsewhere too, especially JS.

 

Why on earth, are we in 2019 and still keep reading something between the lines of "PHP is Garbage"...

All the cons you mentioned are the result of bad coding practices and could be found no matter the language, except for the naming convention of its functions (I wonder what was going on) but that's it.

So let's stop this madness of PHP is bad because X Y Z...
I'm pretty sure that some years from now, people will say the same thing of Python, due to its actual popularity, a lot of new comers that will make mistakes and put some ugly code in the wild.

Sorry for the rant 😅.

 

Thanks for you comment Frank. Despite all the cons I mentioned about PHP I also mentioned some pros I love about it and that's one of the reasons I came back to PHP and this post was about my personal experience. Reading about comparison of two languages will still be there since programming world is growing. But to be clear again I'M A PHP PROGRAMMER TOO! XD

 

Nice article! In terms of php performance I'd like to mention something new maybe not many people know about:

reactphp.org/

I've did a test project and got to handle a big amount of traffic for a php script with a sql query.

Looking forward to test it in some real world projects.

 

Hey Alexandru! This library seems intense and I've not seen it before. Will try to test it on some personal projects and maybe write a post about it so everything will be fair enough. Thanks for sharing this with us.

 

Once upon a time I thought about moving to Node.JS, and did a lot of work on learning it... but I didn't like it at all and left it behind with no excuses. Anyways, since I was so deep into JS, I frequently find myself writing code in PHP like:

MyObject.doSomething();

And once I did this:

$myObject = {
'prop1' => 'value1'
};

And this:
printf(${name}); // backticks ommited

And shame on me (could be using a debuging tool I know!)
console.log($myObject);

But that's funny and highlights how insane programming can be!

 

Nice post! But about the callback hell, I would not consider it a problem anymore, as async/await, or even promises can make it go away.

 

This is completely true in some cases but sometimes you would still need callbacks, it's somehow inevitable! XD

 

Actually no. You can use something like promisify or even build your own solution, but you don't need to use nested callbacks.

Thanks for sharing this with us. That's true but still it is a little bit of more work to be done anyways.

 

I just wanted to add a little comment about php. It's definitely more convenient in some ways, but then when you get to even slightly complex code, it becomes a huge burden -- especially the simple and common practice of putting a function inside a function.

 

Hey agamemnus! This is a point of view which I accept as well.

 

None of your Node nonsense...Php can be clean and uncomplicated.

Php, Laravel, sass and vanilla javascript. Job done.

Minimal compiling, no jquery, no typescript. Secure login, easy eloquent db interactions, lovely migrating.

 

Hi. Thanks for your comment. This is only my personal experience and opinion. I am not forcing it on any one. XD

 

I feel this article has not really needed. It's adding more ammunition to people that hate PHP for the sake of it. There is no point in really comparing the two technologies because as you've mentioned in your post - it depends on a number of factors such as infrastructure, project size, development skillset, budget etc.

Laravel is an excellent framework but it's not the only one available for PHP. The language has come on a long way since the early version days. It's time to embrace what PHP can do and not focus on what it cannot do.

 

Hi Alex, thanks for your comment. I see your concern about the filling up the gun for the people who hate PHP which I'm not one of them anyways XD.
Laravel isn't the only one absolutely and you are right. I've also worked with Phalcon which was absolutely pleasant.

 

Thanks that was a good article, I like your sense of humor too 🤣👍
We've all seen spaghetti code in many languages. It can happen anywhere 😯

 

Hey Peter. Thanks for you comment. Sense of humor has made up my life by now XD. Spaghetti code is really common in every language and that is true but in PHP I see it more happen which is not PHP's fault anyways. LOL

 

Totally! My first internship when I got back into coding was with a company that was running a PHP based web app. And you want to talk about spaghetti 😫🤯

AND there were almost no comments, and no documentation!
It was the worst, plus they knew the tech stack was going to fail, but just kept throwing more spaghetti on top of it. Needless to say I left after not much time

Yeah that happens a lot. I had a somehow same experience in a company I was working for. Ask me about spaghetti. XD
I think I should change the post's name to spaghetti. Comments are all about spaghetti. LOL

 

Very informative. However, splti not split? Typo?

 

Thank you very much Lauren. You read my code more precise than I did myself. Unfortunately Dev.to doesn't have an IDE for coding LOL.

 

Adnan you're the best!
Keep up the good working. Hope you will be famous one day, and not only in Iran :) ♥

 

Thanks Vitali.
You didn't mention your nationality on your profile page but based on your lastname I suppose you are Russian if I'm not mistake, anyways I hope you get to be the greatest programmer in your own country or maybe the world! XD

code of conduct - report abuse