this post was submitted on 13 Dec 2025
371 points (97.9% liked)

Programmer Humor

27836 readers
1093 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] spongebue@lemmy.world 1 points 6 hours ago (4 children)

x = -i;

Do many languages let you do that? When it's in front of a variable I would've expected it to be a subtraction operator only and you would need to do x = -1 * i;

[–] EvilHankVenture@lemmy.world 4 points 6 hours ago

In most languages I've seen - is both a unary negation operator and a subtraction operator depending on context. So it would negate an integer literal or a variable in this context.

[–] boonhet@sopuli.xyz 2 points 6 hours ago

Personally I would expect it to behave the same in front of a numeric literal and in front of a variable. I do think most languages do that, but I haven't actually tested that many and could br wrong.

[–] squaresinger@lemmy.world 1 points 5 minutes ago

Why would they not let you do that? I honestly don't know a single language that wouldn't let you do that. Same as basic math notation allows you to do that.

x = -i

is a totally valid mathematical equation.

[–] OshaqHennessey@midwest.social 1 points 6 hours ago

I just tested it in PowerShell. Works fine

$i = 1
$x = -$i
$x

Outputs -1