this post was submitted on 23 Oct 2023
570 points (96.3% liked)

Programmer Humor

32426 readers
668 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] QuazarOmega@lemy.lol 30 points 1 year ago (2 children)

Ah shoot, she's actually their zeroth girlfriend

[–] agent_flounder@lemmy.world 6 points 1 year ago

I hate when I am written in Pascal

[–] dan@upvote.au 6 points 1 year ago (2 children)

The best programming languages let you pick if arrays are base 0 or 1. Shout out to Option Base 1.

[–] xmunk@sh.itjust.works 4 points 1 year ago (1 children)

Shout out to PHP which just don't give a fuck $arr['apple'] = 5

[–] dan@upvote.au 2 points 1 year ago (1 children)

PHP causes so many issues because of the fact that it uses the same syntax for both arrays and dictionaries/maps. [] (or array() in older PHP versions) always JSON encodes to [] because there's no way to tell if it's supposed to represent an empty array or an empty dictionary.

[–] xmunk@sh.itjust.works 1 points 1 year ago (1 children)

Eh. It works just fine. I agree JSON encoding is weird but if you use it the recommended way (just use a StdClass object and throw on the fields you need) it works fine. Someone added half assed support for weird PHP arrays that usually works and is generally good enough.

[–] dan@upvote.au 2 points 1 year ago (1 children)

stdClass is for objects. I'm talking about maps. I guess you could use stdClass for maps too, but that feels weird.

[–] xmunk@sh.itjust.works 1 points 1 year ago

If you read the docs for json_decode, the default behavior is to operate with stdClass - I too prefer working with associative arrays because of their power but... that kind of just reinforces how useful they are. PHP can give you the full Java class system if you want.. it's just a pain and useless in most circumstances so we all just toss around associative arrays.