Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
closer506y@maushax Code in PHP is unreadable only if programmer makes it that way, just like with any other language.
If one does coding the proper way, PHP is marvelous tool for what it's supposed to do. Don't blame language for not being used properly (something that happens A LOT with Javascript). -
closer506y@ganjaman Really? That's your answer? I provided my view, based on my personal experience and based on listening to developers who I consider the best in the field.
Most people who attack PHP work with some of the languages that have the same bad reputation (for example Java). PHP is not even my main tool at the moment, but jokes about it are not only old, they also discourage young developers from using helpful tool because they make a mistake of trusting random people on the internet.
I actually didn't even want to answer to what you wrote, it's not a behavior that I like to encourage. Sometimes this community seems way too toxic for a group that complains about Stack Overflow very often. -
@closer did you even realize that you just proved what i said with this second comment of yours lmao
-
Yeah.
Because every tiny existing function in a language must be used, arrow functions are bad.
No. Just don't use it.
Simple.
Goto... Semaphores.... Threads.... Futexes ...
There are many things in PHP and every other mofo language that can generate an unreadable garbage.
Just don't do it. -
xewl41716yIt's cool that it's there and I welcome it, though I'm not sure I'll be using it, often.
Unreadable? Then you're using it wrong, but that's just imho. Also, people who claim they haven't written any unreadable code in their life have a wrong view of themselves xD
Go PHP! (: -
Froot75546y@mundo03 Probably, JS got arrow functions years ago and if anything they've improved readability.
-
@irene PHP already had anon functions. Arrow function is the JS term for the cleaner syntax.
-
mundo0349796y@Froot why would it improve readability?
Arrow functions is not just a new way to declare functions.
Also, JS did not get those years ago, node did, big difference. -
@maushax @IntrusionCM @Froot @xewl @mundo03
A framework like Laravel utilizes a bit of a functional style.
You don't use arrays much, everything happens in collections, on which you call map/filter/reduce/etc.
Anyone who thinks:
array_filter($users, function($user) { return $user->isAdmin; })
Is more readable than:
$users->filter( fn($user) => $user->isAdmin )
...has a weird brain.
I'm all in favor of being descriptive and verbose with your own function and variable names, but verbose syntax doesn't add any useful context — it just distracts from the true meaning of your code. -
Froot75546y@mundo03 What? There is a difference between JS and node but that's not it.
ES2015 added arrow functions, go look it up.
Also, they improve readability when you use things like maps, filters, reduces etc. You don't need to write a bully function to get a simple result -
mundo0349796y@Froot yeah, I know EC did that but the browsers did not for a while. I did look it up after ai posted my lies.
I do see why arrow functions might reduce how much you type, if you think that means readability then fine.
But arrow functions also modify how you use functions, what this means and adds restrictions on annonymous functions.
That translates as function and fat arrow functions not being the same thing and therefore are not to be interchangeable. -
Froot75546y@mundo03 They are different yea, but that's the point 😀 The context locking via this is actually very helpful in many cases
-
Froot75546y@hash-table lol are you saying it's hard to find a job as a node.js dev? 🤣
Believe me, it's not. And there's also a difference in job quality. PHP tends to be used in old rusty companies and legacy systems while Node.js is seen more in startups. Depends on what you like to work on and how much you like being paid I guess. -
That's actually a good quality of life improvement, missed it a little from JS (tho this is just a little drop in the ocean what JS allows to do), but what I am waiting for, which I probably will be waiting for the day I kick the bucket:
assignable function parameters by name, similar to python (and .net I think?) that way you can skip defaults and not assign thousands of empty values just to get to some of the parameters in the end and keep things much more clean. (without all the hacks around it, by passing arrays and ruining suggestions etc) -
@JoshBent
Yeah what I usually do for bitchy methods which need lots of parameters, is to create a separate class which just holds the parameters.
function bakeCookie( CookieIngredients $ingredients)
Then I can decide in the CookieIngredients class which ingredients are mandatory, which are optional, and which ones need validation.
The CookieIngredients list is a so called "data transfer object", which optionally even has its own methods for making sure you don't add poison to your cookies.
Usually I also add some fluent and/or magic methods to such a class, so I can construct and modify it easily:
CookieIngredients::standardBatter()->add(new Ingredient('chocolate chips', '12g')).
But yeah... sometimes all that verbosity is a little bit exhausting. I do like the python way as well, especially if you're passing a bunch of simple configuration values, all of which are optional. -
@bittersweet oh yeah, absolutely, exporting into a class works too, but as you said already, it becomes very verbose and often times crowded as hell for what was before a 4000 char liner haha
Related Rants
!rant
Best day of my life ❤️.
Arrow functions will be added to PHP 7.4:
https://twitter.com/nikita_ppv/...
rant
arrow functions
php