this post was submitted on 27 Mar 2025
9 points (100.0% liked)

Programmer Humor

22284 readers
932 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
 

This post was brought to you by this PMD rule.

Transcription

Why do we have this stupid code analyzer rule enabled anyway? Nobody writes code like this...

After telling them the lore why it's there:

You have seen such things before?

11 Times, as a matter of fact

you are viewing a single comment's thread
view the rest of the comments
[–] koper@feddit.nl 2 points 2 weeks ago (5 children)

So what is the reason for doing it that way?

[–] i_stole_ur_taco@lemmy.ca 2 points 2 weeks ago (4 children)

I think this is just a picky optimization.

The first one runs the constructor to instantiate a new string, then gets its class (which is presumably a static property anyway). The second doesn’t have to run any constructor and just grabs the static class name from the type.

Maybe there’s more implementation nuance here but it seems like an opinionated rule that has zero effect on performance unless that code is being called thousands of times every second. And even then the compiler probably optimizes them to the same code anyway.

[–] ryannathans@aussie.zone 1 points 2 weeks ago

It's not picky, needlessly creating objects makes the garbage collector run a lot more. Especially if it's invoked frequently like Minecraft recreating the object for every block on the screen for every frame to render. The garbage collector is largely responsible for lag of up to a second occurring at random times.

load more comments (3 replies)
load more comments (3 replies)