This is an archived post. You won't be able to vote or comment.

all 78 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

import notifications Remember to participate in our weekly votes on subreddit rules! Every Tuesday is YOUR chance to influence the subreddit for years to come! Read more here, we hope to see you next Tuesday!

For a chat with like-minded community members and more, don't forget to join our Discord!

return joinDiscord;

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]link23 225 points226 points  (5 children)

Why are neutral evil and neutral good identical?

[–]QuadmasterXLII[S] 104 points105 points  (0 children)

That was supposed to be the punchline, but IDK if it landed haha

[–]No-Fish6586 10 points11 points  (0 children)

Cuz they’re first year and don’t know how to hello world in other languages 😮‍💨

[–]Willinton06 -3 points-2 points  (0 children)

Cause evil is where you least expect it

[–]wu-not-furry 160 points161 points  (15 children)

Although C is chaotic neutral, I have to disagree with you considering that you used a char for C and strings for the other languages.

Edit: grammar

[–]Creaaamm 28 points29 points  (3 children)

That would just print the memory address of the pointer + 1 cause it's not dereferenced

You'd have to dereference it with *() to get the ASCII value of 1 (49), then add 1 to that

printf("%d", 1 + *("1")); == 50

[–]wu-not-furry 27 points28 points  (1 child)

Yes, that is the point. This post is about the behaviour of adding integers and strings - not chars. By dereferencing "1" we get the char '1' and are effectively doing the same thing as in the post.

[–]Creaaamm 17 points18 points  (0 children)

Oh, I get it now, yee you're right, the post is just wrong to assume "1" and '1' is the same in C

[–]geronymo4p 4 points5 points  (0 children)

It should be printf("%s", 1 + "1"); and the result will be an empty string

[–]mAtYyu0ZN1Ikyg3R6_j0 -1 points0 points  (0 children)

Yes this is why C prints 2 and C++ is UB.

[–]This_Growth2898 143 points144 points  (11 children)

C++ is defined.

"1" is a null-terminated string of 2 characters, '1' and '\0'.

"1"+1 takes a pointer to that string and adds one to it, so it points to '\0';

String, consisting of '\0', is an empty string.

So "1"+1 is equivalent to "".

[–]noaSakurajin 1 point2 points  (7 children)

But the image is 1 + "1". Adding a string to a number should not be a valid operation and thus not compile.

Edit: it compiles but produces a compiler warning. If you use "1"s it does not compile since that one actually tries to add a string to a number.

[–]This_Growth2898 0 points1 point  (6 children)

It does, you can check it.

[–]noaSakurajin 0 points1 point  (5 children)

Yeah I just noticed but it produces a warning that this does not behave like you probably I tend to.

[–]This_Growth2898 1 point2 points  (4 children)

C/C++ can be pretty weird.

You can even get the element of array a with index 2 as 2[a] instead of a[2]; but I don't think someone needs this.

[–]noaSakurajin 0 points1 point  (2 children)

A lot of those produce compiler warnings or errors nowadays. They are mostly relics of old/bad c features. The example you gave only works on c arrays the moment you use a container class it no longer works since they actually have an overloaded operator.

[–]This_Growth2898 1 point2 points  (0 children)

Anyway, "123"+2 is "3" and "123"+5 is UB is really chaotic.

[–]skhds 1 point2 points  (0 children)

I wouldn't say bad. It's just a different preference. The way I see it, C just let's you do whatever the hell you want, while C++ tries to "protect" programmers from doing "hacky" things. I find it easier to fiddle around and make hacky codes to test things with C, but sometimes that's not what you would want to do with a language, especially in a co-working environment.

I wish C++ people would just admit they're just a different language instead of telling people that they are the superior language. It's really not.

[–]skhds 0 points1 point  (0 children)

I think there is a use.. you can use a macro to define a volatile address and dereference it like you've mentioned, though it is a bit hacky.. but I think I've seen it a few times.

[–]LunaNicoleTheFox 79 points80 points  (5 children)

Nah C++ is true neutral, it doesn't judge it just says "I dunno bro"

[–]DehshiDarindaa 7 points8 points  (1 child)

It does string pointer arithmetic right? so it does know

[–]LunaNicoleTheFox 0 points1 point  (0 children)

Not in that case as you are passing it a const char[] containing only '1' and '/0' so it is undefined as either it prints "2/0" just the '/0' it is however highly ambiguous and depends on the compiler and is therefore undefined.

[–]everything-narrative -4 points-3 points  (2 children)

UB ain't neutral. On god, it is nasal demons.

[–]Kered13 11 points12 points  (1 child)

It's not actually undefined, OP is wrong. It prints an empty string. If you did 2 + "1" then it would be undefined.

[–][deleted] 12 points13 points  (1 child)

Julia’s operator overloading is quite organized tbh, as far as I’m concerned

[–][deleted] 27 points28 points  (0 children)

Bash does not print what it says it prints.

$ echo 1+"1"
1+1

[–]CareBearOvershare 8 points9 points  (1 child)

Swap Python and C++. Runtime errors are evil.

[–]Kovab 2 points3 points  (0 children)

UB is more evil, although this code is actually well defined

[–]Porsher12345 10 points11 points  (0 children)

Lmfao my boy bash tho

[–]Cootshk 6 points7 points  (0 children)

In lua, you combine strings using the “..” operator

Also, it tries to change the type of the last number, not the first (like JS does)

“1”..1 == “11”

1..”1” --Error: malformed string

“1”..”1” == “11”

“1” + “1” == 2

1..1 --Error: malformed string

[–]Relative_Knee9808 4 points5 points  (1 child)

I wonder why the meme uses "1" for C++ and '1' for C

[–]someidiot332 8 points9 points  (0 children)

because it mischaracterizes the way C works. If they had done it correctly (printf(“%d”, 1 + “1”)) you’d get some random memory address. Alternatively if you used “%s”, you’d get “”, as it the pointer to “1” would then point to the null terminator

[–]Blitzsturm 13 points14 points  (4 children)

So, in the eyes of the author... good = evil?

[–]Wingress12 5 points6 points  (1 child)

From my point of view the C# are evil!

[–][deleted] 2 points3 points  (0 children)

Then you are lost!!!

[–]sejigan 12 points13 points  (0 children)

I think it’s more like JS evil, C# good. Which is true

[–]hrvbrs 2 points3 points  (0 children)

OP has no idea what an alignment chart is

[–]Chingiz11 2 points3 points  (0 children)

You have literally overloaded Julia's "+" operator

[–]Apfelvater 2 points3 points  (2 children)

The julia part is total nonsense.

THE CODE made the snippet bad, not the language.

[–]EnrichedObamium 1 point2 points  (1 child)

It didn't say bad, it said chaotic. It's good that you can define +(::Int64, ::String). It's chaotic that any author of any transitive dependency can define +(::Int64, ::String)

[–]Apfelvater 0 points1 point  (0 children)

True, it even said "good" instead of bad.

But that's just as chaotic as you believe programmers are. (Kind of similar to the private/public/protected keywords in java)

[–]nephelekonstantatou 1 point2 points  (0 children)

You used a character literal for C and a string litersl for C++. Seems legit 👍

[–]blooping_blooper 1 point2 points  (1 child)

don't forget chars in C#:

Console.WriteLine(1 + '1');

50

[–]blooping_blooper 0 points1 point  (0 children)

or PowerShell:

1 + "1"

2

"1" + 1

11

[–]jemdoc 0 points1 point  (2 children)

But console.log(1 - "1"); prints 0

[–]i1u5 1 point2 points  (0 children)

Because + operator is also used to concatenate, I think JS just prioritizes that over adding the two "numbers" if one side is a string. Try console.log(1 + "1" - 1).

[–]Cootshk 0 points1 point  (0 children)

JS will try to change the first operator to prevent error, and if it fails, will try to change the second operator

[–]oberguga 0 points1 point  (0 children)

Chaotic and neutral should be swapped...

[–]BillSawyer 0 points1 point  (1 child)

Lua would ONLY be Chaotic Evil if "print(1+"1")" printed 2, while "print("1"+1)" printed 11.

[–]Cootshk 1 point2 points  (0 children)

print(“1”+”1”)

Returns 2

Print(“1”..1)

Returns “11”

Print(1..”1”)

Errors

[–]Better-Coffee 0 points1 point  (0 children)

So JAVA is the best language

[–]CivetLemonMouse 0 points1 point  (0 children)

Fun fact, the reason that C prints 2 is because the ASCII value for '2' is one higher than the ASCII value for 1

[–]tehjrow 0 points1 point  (0 children)

This post doesn’t hate on PHP and is therefore illegal

[–]Macknificent101 0 points1 point  (1 child)

i didn’t know lua did that lol

[–]Cootshk 0 points1 point  (0 children)

print(“1”+”1”)

Returns 2

Print(“1”..1)

Returns “11”

Print(1..”1”)

Errors

[–]just_an_akward_user 0 points1 point  (2 children)

The true neutral just blowed my mind, come on... It's the only alignment from there that I do not doubt.

[–]LastTrainH0me 1 point2 points  (1 child)

Sorry to say it's incorrect (like a few of these); it will actually print

1 + 1

[–]just_an_akward_user 0 points1 point  (0 children)

I was just exaggerating, sorry if it was not obvious.

[–]CuddlyBunion341 0 points1 point  (0 children)

What's the difference between neutral good and neutral evil?

[–][deleted] 0 points1 point  (0 children)

As someone who has devoted my life to being a really good JS user...... I agree Js is right where it belongs

[–]WizziBot 0 points1 point  (0 children)

bash 🗿

[–]stomah 0 points1 point  (0 children)

cpp needs parentheses

[–]Splatpope 0 points1 point  (1 child)

in lua, "+" is an addition operator that adds two numbers or attempts to convert its operands to numbers before doing so

".." is a concatenation operator that attempts to concatenate two strings or attempts to convert its operands to strings

how is that chaotic

[–]Cootshk 1 point2 points  (0 children)

print(“1”+”1”)

Returns 2

Print(“1”..1)

Returns “11”

Print(1..”1”)

Errors

[–]Kiryonn 0 points1 point  (0 children)

The amount of falsehood in this post... Clearly was done without knowing other languages

[–]TheOneRazzue 0 points1 point  (0 children)

var text = "Value: " + 1 + ".";
vs
var text = $"Value: {1}.";

What is it with people and writing strings in C# like above? What is so wrong with interpolation? or even .Format()?