this post was submitted on 21 Apr 2024
885 points (97.9% liked)

Programmer Humor

19512 readers
336 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 1 year ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] ValiantDust@feddit.de 83 points 6 months ago (2 children)

But are you gonna return something for this method??? You said you'd return an integer, yet there is no return statement!

[–] gregorum@lemm.ee 41 points 6 months ago* (last edited 6 months ago) (1 children)

and it had better be an integer! it had better be an integer, motherfucker!!

[–] porous_grey_matter@lemmy.ml 17 points 6 months ago* (last edited 6 months ago) (1 children)

Well yea... If you write "return " that is actually wrong, as opposed to just not having gotten around to filling it in yet

[–] sik0fewl@lemmy.ca 16 points 6 months ago (3 children)

This is why I always write my methods from bottom to top. This way I've always got a return statement and I use my variables before they are even declared.

[–] NightAuthor@lemmy.world 4 points 6 months ago (1 children)

For a second there I thought you might be serious

[–] ShouldIHaveFun@sh.itjust.works 2 points 6 months ago (1 children)

I do actually use variables before I declare them most of the time. IDEs make it so easy to then generate the declaration with the correct type.

[–] NightAuthor@lemmy.world 1 points 6 months ago

That’s true, in fact I’ve started doing that myself. Same with methods, instead of going and writing the method and then coming back to use it, I’ll write the invocation first.

[–] N0tTheBees@sh.itjust.works 1 points 6 months ago

Ah an avid dreambird user I see

load more comments (1 replies)
[–] kevincox@lemmy.ml 65 points 6 months ago (2 children)

IDE is one thing, Go refuses to compile. Like calm down, I'm going to use it in a second. Just let me test the basics of my new method before I start using this variable.

Or every time you add or remove a printf it refuses to compile until you remove that unused import. Please just fuck off.

[–] FizzyOrange@programming.dev 16 points 6 months ago

Yeah I think it's trauma due to C/C++'s awful warning system, where you need a gazillion warnings for all the flaws in the language but because there are a gazillion of them and some are quite noisy and false positives prone, it's extremely common to ignore them. Even worse, even the deadly no-brainer ones (e.g. not returning something from a function that says it will) tend to be off by default, which means it is common to release code that triggers some warnings.

Finally C/C++ doesn't have a good packaging story so you'll pretty much always see warnings from third party code in your compilations, leading you to ignore warnings even more.

Based on that, it's very easy to see why the Go people said "no warnings!". An unused variable should definitely be at least a warning so they have no choice but to make it an error.

I think Rust has proven that it was the wrong decision though. When you have proper packaging support (as Go does), it's trivial to suppress warnings in third party code, and so people don't ignore warnings. Also it's a modern language so you don't need to warn for the mistakes the language made (like case fall through, octal literals) because hopefully you didn't make any (or at least as many).

[–] treechicken@lemmy.world 12 points 6 months ago* (last edited 6 months ago) (1 children)

VSCode with Go language support: removes unused variable on save "Fixed that compilation bug for ya, boss"

[–] kevincox@lemmy.ml 4 points 6 months ago (1 children)

Like actually deletes them from the working copy? Or just removes them in the code sent to the compiler but they still appear in the editor?

[–] FizzyOrange@programming.dev 17 points 6 months ago (1 children)

Yeah IIRC it deletes them, which is as mad as you would expect. Maybe they've fixed that since I used it last which was some years ago.

[–] jose1324@lemmy.world 4 points 6 months ago

Bruh that's insane

[–] tunetardis@lemmy.ca 36 points 6 months ago (6 children)

Compiler/interpreter: Can't find variable farfignewton.

Earlier:

Me: Declare variables near, far

IDE: Oh! You mean farfignewton right? I found that in some completely unrelated library you didn't write. Allow me complete that for you while you're not paying attention.

[–] frezik@midwest.social 15 points 6 months ago (2 children)

And people wonder why I stick to Vim.

[–] lud@lemm.ee 12 points 6 months ago (2 children)

I mean, if you want something dumb you can use any text editor.

[–] frezik@midwest.social 5 points 6 months ago (1 children)

Yes, compared to the annoyances of "smart" IDEs, I do want something dumb.

[–] FizzyOrange@programming.dev 1 points 6 months ago (1 children)

No I'm good with smart IDEs. Anyway don't people set up Vim as practically an IDE these days anyway? That's what Vim users always tell me.

[–] frezik@midwest.social 3 points 6 months ago

The advantage there is that you pick and choose how you turn things on, so you leave out the annoying bits.

[–] tunetardis@lemmy.ca 2 points 6 months ago (1 children)

One thing most text editors can do is print. I was shocked the other day when I couldn't print a readme from vscode when someone asked for hard copy.

[–] lud@lemm.ee 1 points 6 months ago (2 children)

Print?

Why would you ever need to print?

[–] bitcrafter@programming.dev 4 points 6 months ago (1 children)

Because some of us are bitter at the trees for generating so much pollen at this time of year and want revenge.

[–] lud@lemm.ee 2 points 6 months ago

That's fair, I didn't think of that.

[–] Threeme2189@lemmy.world 2 points 6 months ago

when someone asked for hard copy.

[–] andnekon@programming.dev 4 points 6 months ago

using lsp in vim has pretty much the same problem especially with java

[–] elxeno@lemm.ee 13 points 6 months ago (1 children)

near, far

The obvious autocomplete is , wherever you are

[–] tunetardis@lemmy.ca 3 points 6 months ago

This is why I fear activating any AI features in the IDE.

[–] brisk@aussie.zone 4 points 6 months ago* (last edited 6 months ago)

I try my best to make my IDEs follow the principal that I should be able to type without looking at the screen, but apparently IDEs are really invested in return accepting completions to the point it's often not configurable even when every other key is.

[–] dojan@lemmy.world 4 points 6 months ago (1 children)

Visual Studio: PROPERTY DOESN'T EXIST ON TYPE!! NOTHING EXISTS ANYMORE!!!!!! REALITY HAS COLLAPSED!

Me: What? I haven't even touched that class, let me check.

Visual Studio: Oops, nevermind, héhé 🙃

[–] DacoTaco@lemmy.world 2 points 6 months ago (1 children)

I swear to god this didnt used to be a problem few years ago. However im having that bug constantly now...

load more comments (1 replies)
[–] gregorum@lemm.ee 4 points 6 months ago* (last edited 6 months ago)

thank you for flooding my memory with a bunch of silly 90s car commercials

[–] RagingRobot@lemmy.world 2 points 6 months ago

Then it automatically imports the library for you too lol

[–] dudinax@programming.dev 9 points 6 months ago

Me:

jetbrains: This heredoc goes on FOREVER!

Me: I'm going to close it..

jetbrains:

[–] labsin@sh.itjust.works 6 points 6 months ago

I start writing the implementation and get the "variable not defined" error and then let the ide add the declaration. It's less keys to press and misspell.

[–] kamen@lemmy.world 6 points 6 months ago

Imagine lint running on format and your linter removing unused variables: you start typing, hit format by muscle memory before using the variable. Rinse and repeat.

[–] dojan@lemmy.world 5 points 6 months ago

I recently started poking with Vue, For the most part when it comes to webapps I've mostly worked with React, Blazor, and a touch of Svelte. The linter is so aggressive. I start defining a method and it instantly goes "IT DOESN'T RETURN ANYTHING!!"

Okay, thanks! I literally just defined the return type!

[–] morrowind@lemmy.ml 3 points 6 months ago (1 children)

Word proccessors have had this figured out for ages, I wonder why it's so hard to implement this QoL change for code

[–] RagingRobot@lemmy.world 6 points 6 months ago (2 children)

How do you mean? You can't type a word without using it in a word processor. Once the word is typed out it's been used. Variables need to be declared then used so 2 separate steps.

[–] morrowind@lemmy.ml 2 points 6 months ago

There's no direct equivalent but word like won't bother me about spelling or grammar until I'm done typing that part

[–] ricdeh@lemmy.world 1 points 6 months ago (2 children)

What do you mean? Variables do not necessarily need to be used, you can allocate memory for some value and initialise it but then simply don't do anything with it.

[–] DacoTaco@lemmy.world 2 points 6 months ago (1 children)

You can but compilers will optimise that away unless you tell it not to.

[–] Shareni@programming.dev 1 points 6 months ago

Meanwhile go: you will remove it or I won't compile, unless you know the secret handshake

[–] RagingRobot@lemmy.world 1 points 6 months ago

Yes you can but the little red squiggles show in your editor to warn you that it's unused code. That's what the whole post is about lol

[–] dylanTheDeveloper@lemmy.world 3 points 6 months ago (3 children)

I'm not a CS major but why exactly does having a variable or parameter that's not used in C, C# and C++ throw a warning

[–] Prunebutt@slrpnk.net 9 points 6 months ago

It's probably gonna be optimized out by the compiler. However, linters will mark it for you, since it suggests that you actually wanted to do something with that variable and forgot about it after declaration.

... Or it can be removed to reduce visual noise once it's not necessary anymore after refactoring.

[–] gens@programming.dev 5 points 6 months ago

Lets say you use a variable named abcd in your function. And a variable named abcb in a for loop inside the same function. But because reasons you mistakenly use abcd inside that loop and modify the wrong variable, so that your code sometimes doesnt work properly.

It's to prevent mistakes like that.

A similar thing is to use const when the variable is not modified.

[–] Shareni@programming.dev 2 points 6 months ago

Because it's code that literally doesn't do anything. Some languages won't even let you compile without special instructions.

[–] cruxialwd@programming.dev 1 points 6 months ago

Programming with Java be like :v

load more comments
view more: next ›