this post was submitted on 13 Oct 2023
332 points (95.9% liked)

Programmer Humor

32050 readers
1463 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
all 26 comments
sorted by: hot top controversial new old
[–] [email protected] 56 points 11 months ago (1 children)

int unused_variable = 0;

Dude wtf is your problem don’t just leave things lying about there don’t you know how to code I mean what the- I don’t go to your house and leave shit on the floor and just—

int _unused_variable = 0;

Ok. We cool.

[–] [email protected] 1 points 9 months ago

sometimes you need an unused variable. some uses in rust:

// destructuring
let (width, _height) = get_dimensions();

// trait implementations (i couldnt think of a better example for this)
impl Into for AlwaysZero {
    fn into(_value: Self) -> {
        return 0;
    }
}

// some types (eg. Result) must be 'used'
// assigned to a variable if we dont care about the return value
let _ = returns_result("foo");
[–] [email protected] 48 points 11 months ago (2 children)

mfw my face when the go compiler fucking screams at me because I dared to declare a variable and not use it

[–] [email protected] 23 points 11 months ago (1 children)

IF THIS IS INTENTIONAL PUT AN UNDERSCORE BEFORE THE VARIABLE NAME YOU ABSOLUTE FUCKING MORON

[–] [email protected] 13 points 11 months ago

didn’t know the go compiler’s name was steeve

[–] [email protected] 10 points 11 months ago (1 children)

"Don't worry too much about your loops bro, I am the apex of computer science research, I know every optimization in the book." Ok want to compile this? "Is that... An unused variable?!? WHAT THE FUCK ARE WE GOING TO DO GOD IS DEAD"

[–] [email protected] 2 points 11 months ago

honestly my dumb ass will choose for i in list: over for i := range slice { every single time. I’m ugly and I’m proud!

[–] [email protected] 29 points 11 months ago* (last edited 11 months ago) (1 children)

I am guilty of passing Exception variables into try catches and not using them

[–] [email protected] 27 points 11 months ago* (last edited 11 months ago)
catch(error) {
  // todo
}
[–] [email protected] 13 points 11 months ago (3 children)

Function is changing a global variable, the global variable is checked after every call to the function. That's your return value.

[–] [email protected] 11 points 11 months ago* (last edited 11 months ago) (1 children)

I spent 3 hours debugging the serialization code to find out it the crash was because the function didn't have a return statement.

[–] [email protected] 10 points 11 months ago

Sorry, cannot relate; Everything is a boolean when you're using JavaScript.

[–] [email protected] 4 points 11 months ago

That's..... Terrible. Truly the stuff of nightmares!

[–] [email protected] 1 points 11 months ago

OOP methods?

[–] [email protected] 9 points 11 months ago (1 children)
[–] [email protected] 8 points 11 months ago (2 children)

I would love to use golang for this but it’s standard library alone is bigger than the amount of available RAM.

[–] [email protected] 2 points 11 months ago (1 children)

Interesting, since golang only includes the parts of the stdlib that are used in the executable binary.

[–] [email protected] 4 points 11 months ago (1 children)

I just tested it and a simple hello world program still produces a 1.7MiB binary, while the device only has 512KiB of RAM.

package main

import "fmt"

func main() {
    fmt.Println("hello world")
}
[–] [email protected] 3 points 11 months ago

Strip the debug info, should be a lot smaller. Also check out TinyGo, it's meant for embedded devices

[–] [email protected] 1 points 11 months ago (1 children)

BTW: what are you using instead to get small binaries/scripts?

[–] [email protected] 3 points 11 months ago (1 children)
[–] [email protected] 2 points 11 months ago

Likely your C++ implementation also doesn't ship the full standard library. And you may even turn off exceptions and RTTI.

[–] [email protected] 1 points 11 months ago

Idk, mb they expected you to modify smth passed by reference/pointer, and the compiler's too busy to care :)

[–] [email protected] -2 points 11 months ago (1 children)

Ok, you are certainly in one of those languages where plenty of your functions shouldn't return a value, and you won't ever let the compiler know that.

On all of the other languages, it's an error, not even a warning.

[–] [email protected] 9 points 11 months ago

It's C++ and it just causes a SIGILL.