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

Programmer Humor

32050 readers
1463 users here now

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

Rules:

founded 5 years ago
MODERATORS
 
top 24 comments
sorted by: hot top controversial new old
[–] [email protected] 90 points 11 months ago (1 children)

What was your first girlfriend like?

error: IndexOutOfBoundsException

[–] [email protected] 30 points 11 months ago (2 children)

Ah shoot, she's actually their zeroth girlfriend

[–] [email protected] 6 points 11 months ago

I hate when I am written in Pascal

[–] [email protected] 6 points 11 months ago (3 children)

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

[–] [email protected] 4 points 11 months ago (1 children)

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

[–] [email protected] 2 points 11 months 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.

[–] [email protected] 1 points 11 months 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.

[–] [email protected] 2 points 11 months 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.

[–] [email protected] 1 points 11 months 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.

[–] [email protected] 4 points 11 months ago (1 children)

Perl had $[ (yes, just those two characters) to allow setting of the first array index, but it's a fatal error to put anything but 0 into it now.

Of course, since Perl arrays can be negative subscripted from the last element, you can stand on your head and index the array negatively from the wrong end. -1, -2, -3 etc. Use unshift to put things on the beginning (logical "end") of what you're doing rather than the usual push. Presto, a 1-based array (up to sign, anyway).

You may wish to file this under "stupid, but it works".

People with more time / more need for something that looks professional, would probably be better off writing something that uses tie instead. (Or, yes, yes, a different language entirely, hush now.)

[–] [email protected] 1 points 11 months ago

Thanks I hate it.

But still better than mathlab not allowing 0 indexed arrays.

[–] [email protected] 60 points 11 months ago (5 children)

You gotta allocate your GFs statically or this just keeps happening.

[–] [email protected] 21 points 11 months ago (1 children)

I tried to declare my GF global, but she became an astronaut, and I get linking errors

[–] [email protected] 35 points 11 months ago

Mate, your GF is definitely global. I was able to access her just fine.... read AND write.

[–] [email protected] 12 points 11 months ago (1 children)

Plus you won't worry that you forget to free her

[–] [email protected] 11 points 11 months ago

As low as my opinion on some exes may be, I still don't believe it's appropriate to mark them as candidates for garbage collection.

[–] [email protected] 10 points 11 months ago

I'd add an imaginary boolean flag to the GF class and always have an initial GF where imaginary == True.

[–] [email protected] 9 points 11 months ago (1 children)

The struct and its CRUD functions seem to be all implemented. Problem is: The Create method is never be called.

[–] [email protected] 8 points 11 months ago

Might be a problem with the factory then.

[–] [email protected] 5 points 11 months ago

*'^You gotta allocate you GF$'

[–] [email protected] 31 points 11 months ago

should have used Rust instead. that way you never talk to a friend in the first place

[–] [email protected] 30 points 11 months ago

girlfriend_list->start

Segmentation fault (core dumped)

[–] [email protected] 17 points 11 months ago

Pointer references protected (Canadian) memory.