this post was submitted on 05 Mar 2025
1064 points (98.9% liked)

Programmer Humor

34266 readers
657 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 3 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] conditional_soup@lemm.ee 91 points 2 years ago* (last edited 2 years ago) (9 children)

Regex

Edit: to everyone who responded, I use regex infrequently enough that the knowledge never really crystalizes. By the time I need it for this one thing again, I haven't touched it in like a year.

[–] 9point6@lemmy.world 31 points 2 years ago

You get used to it, I don't even see the code—I just see: group... pattern... read-ahead...

[–] kameecoding@lemmy.world 18 points 2 years ago (1 children)

Most of regex is pretty basic and easy to learn, it's the look ahead and look behind that are the killers imo

[–] PoolloverNathan@programming.dev 7 points 2 years ago

(?=) for positive lookahead and (?!) for negative lookahead. Stick a < in the middle for lookbehind.

[–] Naich@lemmings.world 6 points 2 years ago
[–] Kissaki@programming.dev 4 points 2 years ago (1 children)

You always forget regex syntax?

I've always found it simple to understand and remember. Even over many years and decades, I've never had issues reading or writing simple regex syntax (excluding the flags and shorthands) even after long regex breaks.

[–] Akito@lemmy.zip 7 points 2 years ago (1 children)

It's not about the syntax itself, it's about which syntax to use. There are different ones and remembering which one is for which language is tough.

load more comments (1 replies)
load more comments (5 replies)
[–] SpaceNoodle@lemmy.world 49 points 2 years ago (3 children)

Clearly you don't write enough bash scripts.

[–] CrazyLikeGollum@lemmy.world 14 points 2 years ago (4 children)

Or scripts for basically any other variant of the Bourne shell. They are, for the most part, very cross compatible.

[–] Tinidril@midwest.social 6 points 2 years ago

That's the only reason I've ever done much of anything in shell script. As a network administrator I've worked many network appliances running on some flavor of Unix and the one language I can count on to be always available is bash. It has been well worth knowing for just that reason.

load more comments (3 replies)
[–] Thcdenton@lemmy.world 5 points 2 years ago (1 children)
load more comments (1 replies)
load more comments (1 replies)
[–] perishthethought@lemm.ee 42 points 2 years ago (3 children)

I don't normally say this, but the AI tools I've used to help me write bash were pretty much spot on.

[–] marduk@lemmy.sdf.org 22 points 2 years ago (1 children)

Yes, with respect to the grey bearded uncles and aunties; as someone who never "learned" bash, in 2025 I'm letting a LLM do the bashing for me.

[–] SpaceNoodle@lemmy.world 35 points 2 years ago (4 children)

Until the magic incantations you don't bother to understand don't actually do what you think they're doing.

[–] embed_me@programming.dev 35 points 2 years ago (1 children)

Sounds like a problem for future me. That guy hates me lol

load more comments (1 replies)
[–] MBM@lemmings.world 12 points 2 years ago (1 children)

I wonder if there's a chance of getting rm -rf /* or zip bombs. Those are definitely in the training data at least.

load more comments (1 replies)
[–] arendjr@programming.dev 9 points 2 years ago* (last edited 2 years ago)

In fairness, this also happens to me when I write the bash script myself 😂

load more comments (1 replies)
[–] SpaceNoodle@lemmy.world 17 points 2 years ago* (last edited 2 years ago)

Yeah, an LLM can quickly parrot some basic boilerplate that's showed up in its training data a hundred times.

[–] henfredemars@infosec.pub 6 points 2 years ago

For building a quick template that I can tweak to my needs, it works really well. I just don’t find it to be an intuitive scripting language.

[–] KazuchijouNo@lemy.lol 22 points 2 years ago (2 children)

Today I tried to write bash (I think)

I grabbed a bunch of commands, slapped a bunch of "&&" to string them together and saved them to a .sh file.

It didn't work as expected and I did not, at all, look at any documentation during the process. (This is obviously on me, I'll try harder next time)

[–] DeRp_DaWg@lemmy.world 5 points 2 years ago

I try to remember to use man when learning a new command/program. And I almost always half-ass it and press the search button immediately to find whatever flag i need.

load more comments (1 replies)
[–] umbraroze@lemmy.world 21 points 2 years ago (3 children)

There's always the old piece of wisdom from the Unix jungle: "If you write a complex shellscript, sooner or later you'll wish you wrote it in a real programming language."

I wrote a huge PowerShell script over the past few years. I was like "Ooh, guess this is a resume item if anyone asks me if I know PowerShell." ...around the beginning of the year I rewrote the bloody thing in Python and I have zero regrets. It's no longer a Big Mush of Stuff That Does a Thing. It's got object orientation now. Design patterns. Things in independent units. Shit like that.

[–] Kissaki@programming.dev 4 points 2 years ago (3 children)

I consider python a scripting language too.

[–] AnUnusualRelic@lemmy.world 5 points 2 years ago

They're all programming languages, they all have their places.

load more comments (1 replies)
load more comments (2 replies)
[–] 0x0@lemmy.dbzer0.com 17 points 2 years ago (2 children)

PSA: Run ShellCheck on your shell scripts. It turns up a shocking number of programming errors. https://www.shellcheck.net/

load more comments (2 replies)
[–] AI_toothbrush@lemmy.zip 15 points 2 years ago

Wait im not the only one? I think i relearned bash more times than i can remember.

[–] coldsideofyourpillow@lemmy.cafe 13 points 2 years ago* (last edited 2 years ago) (3 children)

That's why I use nushell. Very convenient for writing scripts that you can understand. Obviously, it cannot beat Python in terms of prototyping, but at least I don't have to relearn it everytime.

[–] AnUnusualRelic@lemmy.world 11 points 2 years ago (1 children)

So the alternative is:

  • either an obtuse script that works everywhere, or
  • a legible script that only works on your machine…
load more comments (1 replies)
[–] Akito@lemmy.zip 6 points 2 years ago (4 children)

Nu is great. Using it since many years. Clearly superior shell. Only problem is, that it constantly faces breaking changes and you therefore need to frequently update your modules.

load more comments (4 replies)
load more comments (1 replies)
[–] brokenlcd@feddit.it 10 points 2 years ago (1 children)

Knowing that there is still a bash script i wrote around 5 years ago still running the entirety of my high scool lab makes me sorry for the poor bastard that will need to fix those hieroglyphs as soon as some package breaks the script. I hate that i used bash, but it was the easiest option at the time on that desolate server.

[–] formulaBonk@lemm.ee 4 points 2 years ago

Bash scripts survive because often times they are the easiest option on an abandoned server

[–] dQw4w9WgXcQ@lemm.ee 10 points 2 years ago

Any no-SQL syntax for interacting with databases.

[–] Cold_Brew_Enema@lemmy.world 10 points 2 years ago

Me with powershell. I'll write a pretty complex script, not write powershell for 3 months, come back and have to completely relearn it.

[–] RecallMadness@lemmy.nz 9 points 2 years ago (2 children)

This. But Pandas and Numpy.

Pandas and Numpy and Bash.

[–] Ashelyn@lemmy.blahaj.zone 5 points 2 years ago

.loc and .iloc queries are a fun syntax adventure every time

load more comments (1 replies)
[–] Gobbel2000@programming.dev 9 points 2 years ago (1 children)

So true. Every time I have to look up how to write a bash for loop. Where does the semicolon go? Where is the newline? Is it terminated with done? Or with end? The worst part with bash is that when you do it wrong, most of the time there is no error but something completely wrong happens.

[–] ClemaX@lemm.ee 9 points 2 years ago* (last edited 2 years ago)

It all makes sense when you think about the way it will be parsed. I prefer to use newlines instead of semicolons to show the blocks more clearly.

for file in *.txt
do
    cat "$file"
done

The do and done serve as the loop block delimiters. Such as { and } in many other languages. The shell parser couldn't know where stuff starts/ends.

Edit: I agree that the then/fi, do/done case/esac are very inconsistent.

Also to fail early and raise errors on uninitialized variables, I recommend to add this to the beginning of your bash scripts:

set -euo pipefail

Or only this for regular sh scripts:

set -eu

-e: Exit on error

-u: Error on access to undefined variable

-o pipefail: Abort pipeline early if any part of it fails.

There is also -x that can be very useful for debugging as it shows a trace of every command and result as it is executed.

[–] cupcakezealot@lemmy.blahaj.zone 8 points 2 years ago (1 children)

every control structure should end in the backwards spelling of how they started

[–] grrgyle@slrpnk.net 6 points 2 years ago (1 children)

Once you get used to it it is kind of fun.

Shame about do though.

[–] cupcakezealot@lemmy.blahaj.zone 6 points 2 years ago

it could have been not since there's no try.

[–] Blackmist@feddit.uk 7 points 2 years ago (4 children)

Maybe applies more to regex, the write only language.

load more comments (4 replies)
[–] T156@lemmy.world 6 points 2 years ago (1 children)

Bash substitution is regex-level wizardry.

[–] SpaceNoodle@lemmy.world 6 points 2 years ago (5 children)

Slapping a $ before an environment variable name is "wizardry?"

[–] pelya@lemmy.world 4 points 2 years ago (1 children)

Nope, the whole ${variable/regex/replacement} syntax

load more comments (4 replies)
[–] synae@lemmy.sdf.org 4 points 2 years ago

Incredibly true for me these days. But don't fret, shellcheck and tldp.org is all you need. And maybe that one stackoverflow answer about how to get the running script's directory

[–] MechanicalJester@lemmy.world 4 points 2 years ago (4 children)

I mastered and forgot almost entirely RegEx several times now

load more comments (4 replies)
load more comments
view more: next ›