Skip to content
DevMeme
4963 of 7590
CS Fundamentals Post #5430 · source on Telegram

When you forget how loops work in the middle of a linked list problem

Description

A close-up photograph of a laptop screen displaying C code in a dark-themed editor, likely Visual Studio Code. The code shows an egregiously long chain of 'if-else if' statements. The programmer is attempting to add a new file to a directory, which is structured as a linked list. Instead of iterating through the list with a loop to find the end, they are manually checking each 'next' pointer one by one, from 'current->file->next' to 'current->file->next->next->next...' and so on. A prominent comment in the code reads, '// I give up so I hardcode this part', perfectly capturing the developer's moment of defeat. The final 'else' block prints an error 'Too many files in directory'. This is a humorous example of an anti-pattern, showcasing a complete misunderstanding or abandonment of fundamental data structure traversal, and is something that would make any experienced programmer cringe or laugh in recognition of past struggles

Comments

15
Anonymous ★ Top Pick It's not a bug, it's a feature: the directory has a hard-coded file limit, which is directly proportional to the developer's rapidly depleting sanity
  1. Anonymous ★ Top Pick

    It's not a bug, it's a feature: the directory has a hard-coded file limit, which is directly proportional to the developer's rapidly depleting sanity

  2. Anonymous

    Nothing says “enterprise-ready” like unrolling your linked-list traversal by hand until the diff reviewer scrolls for longer than the algorithm actually runs

  3. Anonymous

    This is what happens when you realize writing a while loop would've taken 30 seconds, but you're already 10 levels deep in copy-paste commitment and sunk cost fallacy has entered the chat. The '// I give up' comment is the software equivalent of a white flag planted in a field of pointer dereferences

  4. Anonymous

    When your linked list traversal looks like you're playing 'next->next->next->next->next' telephone with yourself, you know you've reached that special moment in Advent of Code where proper data structures become 'tomorrow's problem.' The comment '// I give up so I hardcode this part' is the developer equivalent of a white flag - honest, relatable, and a perfect encapsulation of the 3 AM debugging mindset where O(1) lookup suddenly seems less important than O(1) sanity preservation. At least they capped it at 15 levels deep; somewhere a CS professor just felt a disturbance in the force

  5. Anonymous

    Turning linked-list traversal into a 20-level else‑if ladder: congrats, you achieved O(1) - as long as the directory has ≤19 files and your cyclomatic complexity has its own SLO

  6. Anonymous

    Manually unrolling a linked‑list insert: O(1) until file #17, then O(outage) with an SLA of fprintf(stderr, "Too many files...")

  7. Anonymous

    Hand-rolled exclusions: because array.includes() allocates too much 'technical debt memory'

  8. @tgarkbit 2y

    задания школы 42, нет?

    1. @sylfn 2y

      Please use English in ths chat

      1. @tgarkbit 2y

        never even paid attention that all messages here are in english, lol this is tasks of school 42(ecole 42), no?

        1. @sylfn 2y

          lmao

        2. Deleted Account 2y

          It’s either school 42 or adventofcode

      2. @megapro17 2y

        I hate English

        1. @sylfn 2y

          Well, that's probably your problem There are rules in this chat (they also apply to comments) and they prohibit using any language except English when no translation or explanation is given

        2. @endisn16h 2y

          this do be lowkey kinda true tho, still good enough for me tho(i just dont know other languages)

Use J and K for navigation