• nautilus@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    36
    ·
    11 months ago

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

    • Steeve@lemmy.ca
      link
      fedilink
      English
      arrow-up
      15
      arrow-down
      1
      ·
      11 months ago

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

    • clearleaf@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      11 months ago

      “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”

      • nautilus@lemmy.dbzer0.com
        link
        fedilink
        English
        arrow-up
        1
        ·
        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!

  • Perroboc@lemmy.world
    link
    fedilink
    arrow-up
    35
    ·
    11 months ago

    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.

    • lseif@sopuli.xyz
      link
      fedilink
      arrow-up
      1
      ·
      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");
      
  • Bappity@lemmy.world
    link
    fedilink
    English
    arrow-up
    18
    ·
    edit-2
    11 months ago

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

  • Limitless_screaming@kbin.social
    link
    fedilink
    arrow-up
    10
    arrow-down
    1
    ·
    11 months ago

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

    • qaz@lemmy.worldOP
      link
      fedilink
      arrow-up
      8
      arrow-down
      1
      ·
      11 months ago

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

  • fl42v@lemmy.ml
    link
    fedilink
    arrow-up
    1
    ·
    11 months ago

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

  • marcos@lemmy.world
    link
    fedilink
    arrow-up
    1
    arrow-down
    2
    ·
    11 months ago

    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.