r/ProgrammerHumor • • Jun 06 '20

It's the law!

Post image
38k Upvotes

1.1k comments sorted by

View all comments

Show parent comment

0

u/[deleted] Jun 06 '20

[deleted] — view deleted comment

174

u/UlisesNc5 Jun 06 '20

IMO iand j are self explaining. If you see an i, you should know it's an iterator. If you see a j, it means you missed seeing the i.

this is the funniest shit i ever heard

39

u/su5 Jun 06 '20

Which is why I name my variables i,k and m

29

u/rtkwe Jun 06 '20

Like letting loose 3 pigs number 1,2, and 4.

0

u/[deleted] Jun 06 '20

[deleted] — view deleted comment

3

u/2ply4dayz Jun 06 '20

That prank's so old nowadays kids really release 12 pigs. Faculty think they're good after finding 11 and reopen with one still on the loose.

1

u/2ply4dayz Jun 06 '20

John Nash has entered the chat

1

u/[deleted] Jun 06 '20

Some people just want to watch the world burn.

26

u/microbit262 Jun 06 '20

If you see a j, it means you missed seeing the i.

and if there is a k, you missed the j, if there is a l you missed the k and so on.

11

u/Pixilatedlemon Jun 06 '20

Just wait until they hear about ‘x’

2

u/jews4beer Jun 06 '20

I've never thought of _ as a "variable" perse. Like in golang that's something the compiler will force you to do if it's a value you don't end up using. And it's just a "blank assignment". You can't turn around and decide to try to access the value of _.

Maybe I'm misunderstanding concepts here.

0

u/[deleted] Jun 06 '20

[deleted] — view deleted comment

1

u/jews4beer Jun 06 '20

Yea I had never tried it in python, and admittedly would just assign a var name even if I don't use it. But just tried it and yep. I dunno, feels dirty. But that's probably because of my preconceived notion of it's usage.

1

u/TheAJGman Jun 06 '20

I don't think I've ever seen it used though, it's just used as a dump for when you don't give a shit about one or more of the variables you're unpacking.

2

u/TheSpiffySpaceman Jun 06 '20

in C# 7.0+ and Haskell, _ is actually a language feature called a discard variable. the value is never assigned, so it can't be accessed.

That also makes some funny deconstruction possible with something like a tuple type, i.e:

(_, _, z) = getCoordinatesAsTupleForSomeReason();

2

u/Zhusters Jun 06 '20

Yes and no. Of course you know that it is an iterator, but its probably even more convenient to see what is being iterated over.

0

u/[deleted] Jun 06 '20

[deleted] — view deleted comment

1

u/SpotifyPremium27 Jun 06 '20

Should have made that:

const int pain;
→ More replies (3)

1

u/Angus-muffin Jun 06 '20

I have definitely seen j be used before i to iterate over a 2d table stored in a single array. Sometimes in dp problems too with 2d arrays

1

u/[deleted] Jun 06 '20

IMO iand j are self explaining. If you see an i, you should know it's an iterator. If you see a j, it means you missed seeing the i.

If anyone ever asks me why I want comments instead of self documenting code, I'll refer them to this comment.

→ More replies (1)
→ More replies (10)