r/ProgrammerHumor • • Jun 06 '20

It's the law!

Post image
38k Upvotes

1.1k comments sorted by

View all comments

Show parent comment

98

u/DudeitsCarl Jun 06 '20

I think it’s j == i+1

135

u/Polywoky Jun 06 '20

You forgot the single-quotes:

'j' == 'i' + 1

0

u/[deleted] Jun 06 '20

[deleted] — view deleted comment

108

u/zaszthecroc Jun 06 '20

That's part of why I love Java. You can construct a loop like for(char current = 'a'; current <= 'z'; current++).

You can do the same in C/C++ and many other languages.

As a matter of fact, 'j' does not equal 'i1'.

His statement was correct.

'j' == 'i' + 1. These are single quotes representing characters (an integral type), not double quotes representing strings. The + operator literally adds their integral values instead of doing string concatenation (which wouldn't even work in reasonable[1] languages because 1 isn't a string).

[1] it does work in JavaScript, because fuck types I guess.

34

u/death_of_gnats Jun 06 '20

If types didn't want to be fucked they shouldn't have gone onto the web

12

u/Meloetta Jun 06 '20

This is victim blaming! You shouldn't be teaching your languages to be strictly typed, you should be teaching your typeerrors to stop expecting certain types! Let's focus on the real villains here

2

u/[deleted] Jun 06 '20

Look, man. If the type didn't want to be fucked then maybe it shouldn't be walking around unboxed?

9

u/hyrumwhite Jun 06 '20

It concatenates in JS because JS has no concept of Char. Both double and single quotes create Strings.

2

u/zaszthecroc Jun 07 '20

My complaint is that JS just casts the 1 to a string, though!

2

u/decorona Jun 06 '20

Lol lol lol lol as a novice JavaScript engineer in dead at this. My brother codes in C++

→ More replies (7)

2

u/MangoCats Jun 06 '20

Anybody remember Fortran? Traditionally, in Fortran the variables I, J, K, L, M, N were always integers while others like A, B, C and X, Y, Z were floats - smart programmers don't use floats for loop counters.

→ More replies (2)

2

u/0vl223 Jun 06 '20

In any C based language you could write for(ShapeWithCorners current = new Point(); current.Corners <= 20; current++) and each iteration would be a shape with one corner more if you really want to do that. It is just a question of properly overriding the ++ operator.

3

u/FVMAzalea Jun 06 '20

Not all C based languages allow you to overload operators. You’re thinking of C++ overloading, but that doesn’t work in Java or Objective-C, or even C itself. It would work in Objective-C++ but that’s only because it’s an unholy mix of Objective-C and C++.

→ More replies (2)

1

u/SamsungPassAutofill Jun 06 '20

This quote may well be the dumbest one I have seen on reddit so far. Congratulations!

→ More replies (1)

2

u/[deleted] Jun 06 '20

Syntax error timeeeee

2

u/el_bhm Jun 06 '20

It looks hella stupid. Is this BASH or JavaScript?

4

u/Zamundaaa Jun 06 '20

That works in C, C++, Java and all programming languages with chars. It's only a bool evaluation statement that results in true though.

1

u/eg_taco Jun 06 '20

This is kosher in C where char is actually a number type, and single-quoted char literals get turned into their ASCII code.

14

u/BesottedScot Jun 06 '20

i += 1

j = i

30

u/Axe-actly Jun 06 '20

j = ++i;

One line better than 2. Me big brain.

3

u/BesottedScot Jun 06 '20

Haha holy fuck.

1

u/aalleeyyee Jun 06 '20

i love light mode!

Blasphemy!

2

u/[deleted] Jun 06 '20

i was waiting for one of Rooster's goons.

→ More replies (1)

4

u/Asraelite Jun 06 '20

In that case we can move back to the original order, i+1 == j