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
-
There's a con talk from the guy who wrote php that will likely make you lose all hope. I'll see if I can find it.
-
C0D4669445yI like it. I'm not affecting the global state of the array unless I explicitly want to, it's a tad safer and I can cleanup the data in the cloned array from memory when I no longer need it.
-
@SortOfTested "I've always been firmly against any sort of multi threading because it just gets too complicated. We as humans are not smart enough to write complex multi thread safe code"
Eh -
Parzi86695yDO NOT USE PHP UNDER PENALTY OF THERMAL RUNAWAY CAUSED BY HCF CAUSED BY YOUR SHIT INTEL SERVER CAUSED BY INITIAL PHP HAX
-
C0D4669445y@don-rager could be, Ive been in the abusive relationship for over a decade 🥰
I do use python and java as well and have no issue with their way of handling data, I just enjoy that bit of freedom/control depending how you look at it. -
What @C0D4 said.
PHP is not Rust.
You don't use PHP to effectively calculate digits of pi, sort through big piles of image data or simulate weather patterns.
People use PHP as a transformation layer between an HTTP request and a database.
PHP arrays are incredibly inefficient to begin with, and them being immutable by default doesn't help -- but they aren't meant for efficiency.
In practice, no one uses straight up arrays, you use some kind of Collection object (which operates on values by reference).
Also, if you want efficiency, you also have Sets, Stacks, Maps, and Vectors in PHP:
https://php.net/manual/en/...
Criticizing PHP for its arrays... As a Haskell developer, looking at Java:
"WTF what is this Null crap? Why are you throwing exceptions all over the place? What is this garbage?" -
C0D4669445y@Jilano we can't be having a well formed argument around here 😆
@bittersweet wait, there's someone else around here in agreement with me on this topic 🥰 I'm not used to this. -
I actually like a system like that, I work in node and its pass by reference, so if you pass in an object that you want to do changes to but not edit the original object you have to clone the object first such as
{ ...oldObject } or stringify and parse. -
@Jilano
I guess I won't start about my unironic passion for 3-space indentation then. -
It's easier to pass value type arrays by reference when needed, compared to passing reference type arrays by value.
Value type arrays are cleaner and safer, too. No accidental side effects.
You asked which language does that: Swift does. -
@Jilano
It's pretty simple: Haskell has alignment-based indentation, everything in a block is aligned to a keyword. But in some cases you must still pick an indentation, for example when you put a block of code after a "do" on a new line, or kind of want a reset on the alignment... the only actual compiler-enforced rule is that it must be indented further than the previous line.
I've worked on a Haskell codebase of a few million lines, which already used 3 spaces in those cases. If you stare long enough at something, you'll eventually start to hate it less, maybe even like it (or so my girlfriend told me).
Now I find that 2 is kind of ambiguous and subjectively "not indented enough", and 4 feels like "overkill".
So.... 3 spaces indentation feels right to me now.
But I would not just push a commit replacing 2 or 4 spaces with 3 for an existing codebase... I only use 3 spaces in private projects. -
To full appreciate PHP, the photo should show a person with leprosy and nail fungus, holding the hammer with their feet. Seems like most PHP devs I'm forced to pick up after have double digits IQs.
-
hjk10156965yActually it's perfectly reasonable PHP does this. To answer your question: Perl, Go.
What you see in other languages is an implementation detail coming trough. Why are the other data types like int copied and perfectly acceptable to you?
PHP does this right and consistently. Unless specified you do not want to accidentally modify the data. However you do not need to go wild and & all your parameters!!! For performance reasons the data is only copied when changed.
Objects are different as you inject them to perform operations on them (although stdclass is not designed for this) they should be passed as reference as this is what you almost always need. -
tman185yC/C++ works like this also, but you may got confused, because common representation of arrays are pointers in C, but it's almost equal to a reference. So basicly passing an array to a function in C is a reference passing.
-
@hjk101 Also, in every-day practice, you rarely pass arrays to methods.
When you retrieve a bunch of users from a database, you probably have them stored in some (symfony/laravel/etc) Collection object, which internally uses a protected array. Laravel even has a LazyCollection class which has a similar public interface to normal Collections, but is completely based on (lazy) generators instead of arrays.
I would never claim that PHP is good at datastructures. Even the PHPDS vector/set/map/dequeue etc stuff is "passable" at best compared to Haskell or Rust.
But PHP isn't like some malformed hammer either. It's more like a Swiss army knife. All the tools it offers are not as good as specialized tools, but they are passable.
However, the best feature of PHP is that you can actually hire teams for it.
Have you ever tried to hire 25 Rust devs? Or even just a team of proficient C++ devs on a startup budget?
Related Rants
PHP ist one of the languages I use regularly, but not the main language.
Anyhow, passing an array to a function will create a Copy of the array unless you specifically choose to Pass the reference.
That's seriously fucked up. What other language does that?! Coming from C, Java, Python to PHP I was not prepared to expect shit like that.
rant
wk194