this post was submitted on 29 Oct 2025
360 points (98.4% liked)

Lemmy Shitpost

35337 readers
3506 users here now

Welcome to Lemmy Shitpost. Here you can shitpost to your hearts content.

Anything and everything goes. Memes, Jokes, Vents and Banter. Though we still have to comply with lemmy.world instance rules. So behave!


Rules:

1. Be Respectful


Refrain from using harmful language pertaining to a protected characteristic: e.g. race, gender, sexuality, disability or religion.

Refrain from being argumentative when responding or commenting to posts/replies. Personal attacks are not welcome here.

...


2. No Illegal Content


Content that violates the law. Any post/comment found to be in breach of common law will be removed and given to the authorities if required.

That means:

-No promoting violence/threats against any individuals

-No CSA content or Revenge Porn

-No sharing private/personal information (Doxxing)

...


3. No Spam


Posting the same post, no matter the intent is against the rules.

-If you have posted content, please refrain from re-posting said content within this community.

-Do not spam posts with intent to harass, annoy, bully, advertise, scam or harm this community.

-No posting Scams/Advertisements/Phishing Links/IP Grabbers

-No Bots, Bots will be banned from the community.

...


4. No Porn/ExplicitContent


-Do not post explicit content. Lemmy.World is not the instance for NSFW content.

-Do not post Gore or Shock Content.

...


5. No Enciting Harassment,Brigading, Doxxing or Witch Hunts


-Do not Brigade other Communities

-No calls to action against other communities/users within Lemmy or outside of Lemmy.

-No Witch Hunts against users/communities.

-No content that harasses members within or outside of the community.

...


6. NSFW should be behind NSFW tags.


-Content that is NSFW should be behind NSFW tags.

-Content that might be distressing should be kept behind NSFW tags.

...

If you see content that is a breach of the rules, please flag and report the comment and a moderator will take action where they can.


Also check out:

Partnered Communities:

1.Memes

2.Lemmy Review

3.Mildly Infuriating

4.Lemmy Be Wholesome

5.No Stupid Questions

6.You Should Know

7.Comedy Heaven

8.Credible Defense

9.Ten Forward

10.LinuxMemes (Linux themed memes)


Reach out to

All communities included on the sidebar are to be made in compliance with the instance rules. Striker

founded 2 years ago
MODERATORS
 
top 45 comments
sorted by: hot top controversial new old
[–] ilikecats@lemmy.sdf.org 6 points 3 hours ago

I have a rule in my NVim init.vim that it gets room for three line number digits. If it goes over, the screen shifts uncomfortably as warning. That works for my current projects.

[–] Monument@lemmy.sdf.org 5 points 4 hours ago

I have no memory of this place.

[–] kryptonianCodeMonkey@lemmy.world 47 points 15 hours ago (3 children)

When I was in my 101 comp sci classes, one of my professors would say, "A function is meant to do one thing. So if your function doesn't fit on the monitor in it's entirety, that is a good indication your function is probably too complicated and/or doing too many things. Either simplify it or break it down further." And that's a rule I usually try to live by with my professional work too. So, anyway... I want to see the 4000k monitor this guy is using.

[–] pupbiru@aussie.zone 5 points 1 hour ago

also depth of blocks: if i’m more than 2 or 3 indents deep, it’s probably got a bit too much logic to it and those comments should be converted to a function name

[–] DarkAri@lemmy.blahaj.zone 4 points 5 hours ago (1 children)

The rule of thumb I use is how likely am I to reuse some part of this code in the future? Also readability. Sometimes I like to just wrap some code in functions to make the code look neater. Other considerations are how often will this function be called? The overhead of calling a function is tiny but if a program is used by millions, everyday for many years, it's sort of like not littering a bit to make the code a bit more inline. It is kind of nice to be able to mostly see what a piece of code does in a glance other than when it's just wasteful.

[–] kryptonianCodeMonkey@lemmy.world 2 points 4 hours ago* (last edited 3 hours ago)

Concise readability is usually my goal. Like if I have 12+ lines of code with a loop and some nested conditionals, recursively digging into buried directories, that probably takes a bit of thought to parse. So it is probably is better to move that to a function with a descriptive name like, "size, depth = get_directory_size_and_depth(filepath)", that way the function name itself serves as it's own comment/documentation describing what's being done and, if you don't really care about how the size and depth is aggregated, it abstracts that process into one line of code in the calling function that the reader can instantly understand without parsing the whole process. That goes doubly so when the function is generic like get_directory_size_and_depth(filepath) would be, and can be put in its own shared utilities file.

[–] Gonzako@lemmy.world 7 points 13 hours ago* (last edited 13 hours ago) (3 children)

I personally go by the monocre that if it's something important, it'd be all on one file as not to lose the train of thought when debugging it.

As jumping around between files

tends to break up thought lines

also, the compiler likes it better when there's less layers

[–] kryptonianCodeMonkey@lemmy.world 5 points 6 hours ago (1 children)

I said function, not file. You can have 40 functions in one file.

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

oh yeah, that's fair.

[–] LodeMike@lemmy.today 21 points 12 hours ago

The compiler can get fucked

[–] Johanno@feddit.org -2 points 9 hours ago (1 children)

Are those your arguments?

Train of thought is subjective

And the compiler doesn't care

[–] Gonzako@lemmy.world 3 points 7 hours ago (1 children)

Yeah? If something is important being able to have it all on one file is the best way to ensure you get the behaviour you want.

Having to file-hop is generally a strain on mental resources and it breaks the linearity of the project, ofuscating initial reads.

And yes, the compiler does care, there are no 0-cost abstractions.

[–] Johanno@feddit.org 1 points 2 hours ago

Yesnt.

If the alternative to changing into a new file is to search through a 40k lines file that has no structure, then I rather go to a new file. As my train of thoughts is interrupted by the size of the file.

And a good compiler is capable of a lot these days. However if you are working on low end hardware that has to perform good and fast then you should of course think about the compiler.

In 99% of software that isn't the case though

[–] TheWonderfool@lemmy.world 101 points 21 hours ago (2 children)

And what's beautiful is that the one right under has a comment "we don't use thi..."

This code looks like so much fun to debug...

[–] niartenyaw@midwest.social 41 points 20 hours ago (2 children)

i like to imagine it says

we don't use this, but if you delete it everything in this file breaks

[–] RaivoKulli@sopuli.xyz 4 points 1 hour ago

Load bearing code

[–] Taldan@lemmy.world 12 points 18 hours ago (1 children)

we don't use this without first writing proper unit tests for our changes, integrating them with the regression tests, and thoroughly documenting our changes for the next developer that has to work on this

I'm an optimist, and it's technically possible

Ok cool now write some unit tests for a 13,000 line function

🙃

[–] Blackmist@feddit.uk 20 points 18 hours ago

There's one I found today that just reads "this is a fucking abortion"

I don't remember doing it, but it was almost certainly me.

[–] zr0@lemmy.dbzer0.com 60 points 21 hours ago (3 children)

Is the function called is_even()?

[–] kryptonianCodeMonkey@lemmy.world 16 points 15 hours ago
def is_even(num:int) -> bool:
    if x < 0:
        x = x * (-1)
    if x == 0:
        return True
    elif x == 1:
        return False
    elif x == 2:
        return True
    elif x == 3:
        return False
    elif x == 4:
        return True
    elif x == 5:
        return False
    elif x == 6:
        return True
    elif x == 7:
        return False
# ...
[–] railwhale@lemmy.nz 26 points 18 hours ago (1 children)

Here, I optimised it:

private function is_even(integer): 
    integer = 2;
    return True;
[–] olenkoVD@lemmy.dbzer0.com 7 points 4 hours ago

what unholy combination of programming languages is this

[–] Taldan@lemmy.world 15 points 18 hours ago

Yes, and it only returns, "I can't even"

[–] vane@lemmy.world 7 points 15 hours ago

get date switch case

[–] Gladaed@feddit.org 40 points 22 hours ago (1 children)

That's just some hard coded lookup table. Nothing to see here.

[–] Diplomjodler3@lemmy.world 37 points 22 hours ago (1 children)

It's the lookup table for odd and even numbers.

[–] boonhet@sopuli.xyz 7 points 21 hours ago (1 children)
[–] Taldan@lemmy.world 4 points 18 hours ago

Each line is 10,000 characters and the function only supports short primitives

[–] ChaoticNeutralCzech@feddit.org 22 points 20 hours ago

Cannot be expanded, it's private. Proprietary blob.

[–] abbadon420@sh.itjust.works 28 points 22 hours ago

Holy mother of functions

that's some PTSD right there. just leave that closed as long as you can

[–] Winter_Oven@piefed.social 22 points 22 hours ago (3 children)

imagine if the entire function is a single if-else statement which they kept adding onto, but could never refactor lest everything crashes down and burn.

[–] _stranger_@lemmy.world 4 points 5 hours ago* (last edited 5 hours ago)

You're dredging up some bad memories 😅

Saw one once called something dangerously innocent like "run_validation" that turned out to be a 5K line hand built deserializer (no libraries used when then absolutely should have) with so many nested levels the editor put "expand this line?(2kb)" warnings at the end of most lines.

In the original author's defence the garbage being deserialized was an Eldritch horror. We eventually moved to JSON.

[–] Daedskin@lemmy.zip 13 points 21 hours ago (1 children)

I once worked on a project doing firmware that a lot of people have likely used (printer firmware for a big-name company). One of the more trafficked functions was something like 1500 lines of "if-elseif-elseif..." with something like 13 or 14 different cases.
It did end up getting refactored to something polymorphic and based on a configuration file to cut out any unnecessary steps, but it was like that for a while before I got there, and was like that for most of the year that I was part of the project.

[–] thebestaquaman@lemmy.world 4 points 11 hours ago

To be fair, I think massive "switchboards" can be relatively clean. The key is that each step contains little enough logic. 1500 lines of 13-14 cases means the average block was > 100 lines, and at that point I definitely agree that it should probably have been refactored a long time ago. Just splitting that into 13-14 smaller functions, and using the switchboard as a delegator could be completely fine.

[–] JargonWagon@lemmy.world 2 points 15 hours ago

4k+ nested if statements with comments.

[–] folekaule@lemmy.world 19 points 21 hours ago (1 children)

Those lines are mostly comments, right? Right?

[–] kibiz0r@midwest.social 7 points 18 hours ago (1 children)

Yeah, just comments… with chapters…

[–] Thorry@feddit.org 15 points 17 hours ago* (last edited 1 hour ago) (1 children)

// - - - - - - - - - - - - - - - - - -

// Note added by employee 871 - S. Sandler - 10-31-2003

// Chapter 1

// Dear reader, let me tell you all about this here function.

// You see it was a dark and rainy night, like the nights often were in the place I once called my home.

// My grandma used to tell stories about those nights, the nights where the cold creeps in and the fog rises up from all around.

// She used to tell us those nights were haunted, evil things happened which could not stand the light of day.

// I never put much stock into those stories, but when the rain beats against the window and the wind would rustle the trees, I figure she might have been onto something.

// So you see it was one of these typical nights where I learned evil does indeed come out. But not from outside as one might expect, no..... The evil comes from within

// Chapter 2

// Just like every other Friday, I got stuck with night duty. I wanted to go drinking with friends, but my manager told me I needed the extra shift since quarterly reviews were coming up.

// I was in a foul mood and cursed my manager, but like my grandma used to say curses can be a dangerous thing. They have a tendency to backfire when not used in moderation.

// Frankly I'm not sure my grandma knew what moderation meant, otherwise she would have cut down on the amount of beans she ate.

// Let me tell you; old folk and beans aren't a great combination. But I digress.

// Getting stuck with night duty wasn't bad, it didn't pay much, but you could work from home and usually nothing much happened, especially on a Friday.

// So I sat around watching some old X-Files episodes, keeping half an eye on my mailbox to see if any tickets came in. I do say that Scully chick is one hot mamajama, I kinda forgot about the story.

// It was at this moment I heard loud thunder rolling by and the familiar wee-woo sound of my email client getting a new mail.

// As I read the ticket number: EI-WA-98215-6-66 the hair on the back of my neck stood up.

// Chapter 3

// I wondered who could be submitting tickets at this hour, but it must be important so with one eye on Scully I checked out the ticket.

// For some reason the user name wasn't in the ticket, just the user number. I had complained about this to IT and they said they would "get to it" whatever that means.

// I swear to the gods if you think developers have their own code to make fun of users, IT guys are way worse. They probably just sit around crimping their cables or whatever they do.

// Anyway this ticket was really weird, the user said when they opened up the admin portal the menu would freak out.

// They said, I kid you not: "The menu is haunted and we need an exorcism"

// Must be some kind of joker who also got stuck with the night shift and doesn't have anything to do, so lets mess with the poor devs right?

// Chapter 4

// When I opened up the admin portal I didn't see anything weird at first, this dude was messing with me for sure.

// I got hungry so I wanted to make myself a quick snack, I found a buldak ramen packet in the kitchen.

// Perhaps I shouldn't have judged my grandma for eating beans, as I know these spicy ramen will be much worse.

// While waiting for the water to boil, I saw movement from the corner of my eyes, it was like there was someone in the room with me.

// When I walked over to investigate it was suddenly gone, but I saw on my screen the menu was freaking out, opening and closing like crazy.

// I turned to walk back to the kitchen and get my ramen going, but as I did suddenly I hear a loud bang in the apartment.

// Chapter 5

// As I investigated the noise I found a door had slammed shut due to the wind, I was pretty sure I had closed that door earlier...

// With my snack in hand I went in to investigate the code running the menu.

// After thorough investigation, I found no fault in the menu. The code hadn't been touched in months and nobody had ever complained before.

// But I had seen the menu misbehave myself, surely something must be wrong with it.

// Suddenly it was like my hands had a mind of their own, they started writing code like I had never seen before.

// With horror I saw what they were doing and I gasped. The only brief pause I got was when my hands turned to my ramen.

// I felt sick by the code they had written, but they forced the spicy buldak into my mouth and when I refused to swallow, poured the lukewarm Mt. Dew in my mouth.

// Chapter 6

// Even though I have no explanation for the code that now lays before you, in order to clear my conscience I will briefly try to explain what it does.

// My understanding isn't complete, but what I've been able to glean from beyond the veil is the following:

// Lines 8 - 26 deal with getting the user details, they appear to use the regular API for this but also some calls I'm not familiar with.

// Lines 43 - 78 seem to get the users actual GPS coordinates, I have no idea how?

// Around line 156 the weather.com API is used to get a current report at the users location.

// The rest of the code seems to deal with various time and weather related checks. As far as I can tell it checks if it's dark and stormy out.

// In the last part of the function there is some simple logic that cancels the menu animation if it triggers too often.

// Chapter 7

// It was with a heavy heart I pushed commit 54D3AD into production with the simple message "Fixes ticket EI-WA-98215-6-66"

// I went to close the ticket, but somehow I couldn't find it in the ticket system anymore. Probably those IT guys messing up again.

// The mail was gone as well, but with Microsoft Outlook that was pretty much par for the course, so I didn't think anything of it.

// Wanting to put this horrible experience behind me, I resumed watching X-Files, such a classic show.

// A few minutes later my VLC crashed and kept looping on Mulder saying "Thank you", but it was slowed down a bunch and distorted.

// In the few seconds I needed to get my hand free from my sweatpants, all my power went out. We really should invest more into infrastructure...

// - - - - - - - - - - - - - - - -

// Note added by employee 2548 - Martin (intern) - 07-02-2009

// New Weather.com API premium key added, no idea why we need this, but without it the menu breaks.

// Could not find contact info for employee 871 - presumably left the company.

[–] folekaule@lemmy.world 4 points 15 hours ago

Entertaining! Well done. LGTM and ⛴️

[–] SailorFuzz@lemmy.world 12 points 21 hours ago

oh look, it's the old codebase at my job

Legit, the company banned people from using #region in their scripts because too many people were using it to hide massive amounts of slop code. Just giant fucking IF trees. Even though using it is hugely beneficial to keep things organized, especially if you use a lot of interfaces.

[–] bacon_pdp@lemmy.world 6 points 21 hours ago

One sheet of paper rule exists for a reason

[–] owenfromcanada@lemmy.ca 6 points 22 hours ago

I can smell it from here

[–] Worx@lemmynsfw.com 3 points 20 hours ago

It's a private function and you weren't invited. No need to look closer