PHP: Frankenstein arrays.
PHP has become quite a nice language, but there are some ugly legacies left from the past. Like the deceptive Frankenstein abomination known as the “array”.
Read in full here:
This thread was posted by one of our members via one of our news source trackers.
This seems to rear its ugly head pretty often when having to deal with a JSON API. Had to deal with this a few times recently. Discovered the other week, if you give it a JSON object with only numeric keys (which are strings with numbers in them because numbers as keys are not valid JSON) regardless of whether they are sequential, it thinks the object is an array. Who would have thought {“1”; “one”, “9”: “nine”} should be turned into [“one”, “nine”]? apparently someone
I’m not sure if it is more or less, JS weirdness I’m much more familiar with which doesn’t make it particularly easy to look at objectively. I do tend to find that while JS has a lot that is really easy to poke fun at, it is also generally fairly easy to avoid (within the bounds of a complete lack of type safety) many of the pitfalls. I also generally find a lot of discussion, examples of usage etc go a long way to pushing you away from those pitfalls as well. Laravel by default decodes JSON in this way, so with what is one of the most popular web frameworks you are basically being guided towards having this problem and certainly on the versions I’ve had to deal with recently (which are old) there is no easy way to get at the original request in the middleware chain or the validation rules they have, making things impacted by this decision painful to do validation on. Also today I learned in another case of PHP weirdness that the string “0” is falsey, so
if(“0”) {
// do nothing
} else {
echo “wat!”;
}
Does indeed echo “wat!”. Even JS isn’t quite that insane unless you introduce some coercion into the condition (at which point you will receive all the pain and suffering that comes with doing something so stupid).
Oh I don’t even mean the exceptionally odd and inconsistent standard library functions, I mean as a language, most of the issues coming down to annoying dynamic typing.
There is a bit of that, there are a bunch of different points from different perspectives in there, but there are a surprising amount of people attempting to make serious arguments that PHP is a better choice than python or ruby, or generally most dynamic languages
I was 40 years old when I realized, for the first time in my life, that me willing to throw away acquired skills and moving to gain new ones, is an aberration and not the norm.
Most people learn a few things and hold onto them with a death grip.
I actually met a woman last year who was LOUDLY BRAGGING about knowing how to manage a Blogger page/blog and was asking me how can she reuse that knowledge if she were to learn how to do so for WordPress and Magento websites… A valid question, surely, but she was just hell-bent on learning the minimum possible amount and that really stood out to me.
Sounds like the reason some people to use C over Rust… >.>
The point of the extra features rust has isn’t for convenience in immediate programming, it’s to catch errors that EVERYONE, including the “grizzled veteran” (even if less often) makes.
PHP is on the level of C, it’s very low level, easy to break, no good early catches, etc…
The one that gets me is Go, it is creating something new that is an active rejection of everything anyone has learned since C. Though that doesn’t really relate to PHP at all, it does seem to suffer a lot from the idea that if you just do it right then it won’t be a total disaster.
I think the creator of Go had this to say about it:
The key point here is that our programmers are not researchers. They are, as a rule, very young, they come to us after their studies, perhaps they studied Java, C / C ++ or Python. They can’t understand an outstanding language, but at the same time we want them to create good software. That is why their language should be easy for them to understand and learn.
It should be familiar, roughly similar to C. Programmers working at Google start their careers early and are mostly familiar with procedural languages, in particular the C family. The demand for speedy productivity in a new programming language means that the language doesn’t have to be too radical.
I still don’t see how golang helps make good software, I keep running into crashes with go programs and libraries… >.>
I totally agree with this, but would also add it should be intuitive and feel natural (so not frustrating) - these are some of the things that makes people want to use a language (some of the others are what you can do with it or the power it affords you)