DEV Community

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

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 ...
Collapse
 
syntaxseed profile image
SyntaxSeed (Sherri W)

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.

Collapse
 
eaich profile image
Eddie

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

Collapse
 
jcadima profile image
Juan J Cadima • Edited

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.

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him) • Edited

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

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

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

Collapse
 
syntaxseed profile image
SyntaxSeed (Sherri W)

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.

Thread Thread
 
adamcosi profile image
Adam

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.

Collapse
 
franksierra profile image
Frank Sierra

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 😅.

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him) • Edited

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

Collapse
 
lffg profile image
Luiz Felipe Gonçalves • Edited

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.

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

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

Collapse
 
ondrejmerkun profile image
Ondřej Merkun

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

Thread Thread
 
adnanbabakan profile image
Adnan Babakan (he/him)

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

Collapse
 
atrandafir profile image
Alexandru Trandafir

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.

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

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.

Collapse
 
abraunton profile image
Alex Braunton

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.

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

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.

Collapse
 
delmontee profile image
Delmontee

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.

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

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

Collapse
 
agamemnus profile image
agamemnus

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.

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

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

Collapse
 
petecapecod profile image
Peter Cruckshank

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 😯

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him)

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

Collapse
 
petecapecod profile image
Peter Cruckshank

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

Thread Thread
 
adnanbabakan profile image
Adnan Babakan (he/him)

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

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him) • Edited

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

Collapse
 
laurentariel profile image
Lauren Tariel

Very informative. However, splti not split? Typo?

Collapse
 
adnanbabakan profile image
Adnan Babakan (he/him) • Edited

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.