Details
-
Github
Joined devRant on 10/31/2019
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
-
PHP arrays.
The built-in array is also an hashmap. Actually, it's always a hashmap, but you can append to it without specifying indexes and PHP will use consecutive integers. Its performance characteristics? Who knows. Oh, and only strings, ints and null are valid keys.
What's the iteration order for arrays if you use them as hashmaps (string keys)? Well, they have their internal order. So it's actually an ordered hashmap that's being called an array. And you can produce an array which has only integer keys starting with 0, but with non-sequential internal (iteration) order.
This array weirdness has some non-trivial implications. `json_encode` (serializes argument to JSON) assumes an array corresponds to a JSON array if its keys are consecutive integers in increasing order starting with 0, otherwise the array becomes a JSON object. `array_filter` (filters arrays/hashmaps using callback predicate) preserves keys, so it will punch holes in the int key sequence if non-last items are removed, thus turning arrays into hashmaps and changing your JSON structure if you forget to discard keys before serialization.
You may wonder how JSON deserialization works, then? There's a special class for deserialized JSON objects, `stdClass`. It's basically a hashmap too, but it's an object, not an array, and all functions that would normally accept arrays won't work with it. So basically its only use is JSON (de)serialization. You can even cast arrays to objects, producing `stdClass`.
Bonus PHP trivia:
Many functions return nonsensical values. `preg_match`, the regex matching function, returns 1 for success, 0 for no matches and false for malformed regular expression. PHP supports exceptions, so it could just throw one on errors. It would even make more sense to return true, false and null for these three cases. But no, 1, 0 and false. And actual matches are returned by output arg.
`array_walk_recursive`, a function supposed to recursively apply callback to each element of an array. That's what docs say. It actually applies it to leafs only. It will also silently accept object instead of array and "walk" it, but without recursing into deeper objects.
Runtime type enforcing is supported for function arguments and returned values. You can use scalar types, classes, array, null and a few special keywords. There's also a `mixed` keyword, which is used in docs and means "anything". It's syntactically valid, the parser will accept it, but it matches no values in runtime. Calling such function will always cause a runtime error.
Strings can be indexed with negative integers. Arrays can't.
ReflectionClass::newInstanceWithoutConstructor: "Creates a new class instance without invoking the constructor". This one needs no commentary.
`array_map` is pretty self-explanatory if you call it with a callback and an array. Or if you provide more arrays of equal length via varargs, callback will be called with more arguments, one from each array. Makes sense so far. Now, you can also call `array_map` with null instead of callback. In that case it treats provided arrays as rows of a matrix and returns that matrix, transposed.5 -
Dear Dark Side #2
Open company projects on all screens
Open your hobby project bottom left screen
Code without guilt
Update company backlog3 -
Did you ever think time estimations are hard? If so, did you ever try adding your actual taken time months after working on a ticket?8
-
Novice computer enthusiasts argue that an application is safe because it's end-to-end encrypted.. but they don't realize this doesn't guarantee safety because of MITM attacks on possibly exploitable midpoints.
A good example of this is mail servers using TLS 1.2 but one or two of them not verifying certificate autorities.5 -
I am so in LOVE with IntelliJ. I used to use Eclipse before, just switched to intelliJ last week and I am falling in love with this IDE a little more every day!!!!!16
-
Using eclipse after a long while on a work laptop and this fucking piece of shit console window popping the fuck up and my cursor auto switching to it is the fucking shit design of a fucking lunatic from the fourteenth circle of hell, where the eternal punishment in addition to being roasted alive, probably includes being forced to fucking use eclipse.
Did I mention fuck eclipse? Fuck, I don't even care if I did. Fuck eclipse again.
Oh and to add on, if you're thinking of making the very useful suggestion that it's very easy to turn off window focus with just two buttons, then fuck you and the guy who designed that shitty UI fucking button.3 -
Python be like
"Yeah this is the absolute best beginner language to learn programming concepts"
Python also be like
"Yeah well we couldnt implement 70% of programming concepts because the ast is retarded but heres a library for drawing 3d cats with a printer"30 -
If the package.json is longer than your actual code this maybe shouldnt be a package. Just saying.1
-
Motherfucking website style JavaScript rant ahead.
Just tried to register some travel tickets, at FlixBus. Of course alternatively I could go for a train but those would be more expensive. So yeah.
Turns out that the website loads JavaScript from 20 domains including 3 required CloudFront ones (those are the most annoying because it's not possible to tell by the domain what it would be doing). But alright, I'll take it. Web 3.0 amirite?
So I go and find myself a nice bus, add it to my cart.. oh shit it's the wrong one. Change some parameters, hit return.. well guess what. Turns out that in all their JavaScript glory they couldn't implement that much. Awesome!
Go to another site to get another ticket for my travel back, only to find out that while they couldn't implement return, their webdevs are apparently skilled enough to get a giant boner on blinking "(1) Almost ready!" in the site's title, when changing to another tab and there happens to be stuff in the cart. Do you really think I care about that shit! Don't distract me and let me get my shit done!!!
So, to all you webdevs who would pull something like this and wank on it too. Guess what motherfucker. That purchase got cancelled through the power of JavaScript wank, because there's no way I'm supporting that dystopian junk. Guess what, when people shell out money at your shitty online shop, they may want a quarter-ass decent UX too. And no notifications or any of that wank, you hear me?
But yeah fucking Web 3.0!!! Give me a fucking break.8 -
Me: hmmmm it's a pain in the ass building my program and having to rebuild it everytime I want to swap to my Chromebook (going from x86 to ARM64), I really wish they could develop an OS that is essentially a VM so you would compile once and have the OS' VM later do the heavy lifting
My brain: hey Alex, that sounds like a great idea, you deserve a coffee for that!
Me: yes I do... Wait... Coffee... Cup of jo... Java.... WAIT! This sounds like what Java was intended to be!!!!!
My brain: oh dear god... Time to fucking bury this thought to never be discussed again!!!!!
What's the lesson to learn here? If it looks like Java, sounds like Java and acts like Java, beat it over the head and bury it 6 feet down :-37 -
I got hired to run an A/B test between a competitor landing page and a new page. While I didn’t do the new page initial design, I did advise on and completed its final tweaks. The result was a 430% increase in leads generated over the original.2