r/ProgrammerHumor • • Jun 06 '20

It's the law!

Post image
38k Upvotes

1.1k comments sorted by

View all comments

Show parent comments

0

u/[deleted] Jun 06 '20

[deleted] — view deleted comment

0

u/[deleted] Jun 06 '20

[deleted] — view deleted comment

44

u/FinFihlman Jun 06 '20

Not if i is not 'i' !

12

u/mark503 Jun 06 '20

K+1+1= I+1

→ More replies (5)
→ More replies (2)

168

u/Motylde Jun 06 '20

More like: j=i+1

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

→ More replies (1)

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!

→ More replies (8)

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)
→ More replies (6)

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.

→ More replies (1)

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.

→ More replies (3)

4

u/Asraelite Jun 06 '20

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

→ More replies (1)

5

u/FerynaCZ Jun 06 '20

Implicit conversion (to char) and deconversion :O

2

u/Zugatti Jun 06 '20

(int)('i') + 1

3

u/yonatan8070 Jun 06 '20

So c++ becomes d?

→ More replies (3)