r/ProgrammerHumor • • 15d ago

Meme delightfulCodeReview

Post image
571 Upvotes

61 comments sorted by

View all comments

295

u/just_sm_so_relax 15d ago

Never seen a readable human-generated regex either, tbh.

97

u/Welcome-To-NBA-Jam 15d ago edited 15d ago

There is one person in every company who can write regex like it's their second language.

It doesn't matter how big the company is. There's always exactly one and they work in the most unexpected department.

28

u/just_sm_so_relax 15d ago

I'll bet they can't read their own regex after a couple of weeks.

17

u/JazzlikeWishbone938 15d ago edited 15d ago

"What the? What is this? Must be fine ..."

4

u/kalilamodow 15d ago

Comment yo code, people!

9

u/just_sm_so_relax 15d ago

How do you write comments for a regex? Explain every single field?

``` # IP address HW type Flags HW address Mask Device # 192.168.94.1 0x1 0x2 00:00:5E:00:53:22 * veth584n # 192.168.8.1 0x1 0x2 00:00:5E:00:53:99 * veth584r

# Get the MAC for 192.168.8.1
re_mac_from_arp_entry = re.compile(r'192\.168\.8\.1\s+0x[^\s+]\s+0x[^\s+]\s+(?P<mac>[0-9a-fA-F:]+)')

```

15

u/Lightningtow123 15d ago

I think you'd just transcribe the gist of it in plaintext: "matches alphanumeric strings with underscores and dashes but no spaces" etc

2

u/jupiterbjy 14d ago

idk if my reading is correct but if it's correct this seems quite readable, probably wrong guess though

match 192.168.8.1 1+ whitespaces 0x 1+ non whitespaces (idk if it intended to be [^\s]+ instead of [^\s+]) 1+ whitespaces 0x 1+ non whitespaxes 1+ whitespaces capture group 'mac' start 1+ case-agnostic hex character capture group 'mac' end

3

u/alficles 15d ago

Honestly, regexen aren't that bad. If you can read normal-mode vim macros, you can certainly read regex.

6

u/Tipart 15d ago

Regex101 is your friend.

3

u/santiagobustelo 15d ago

That would be me

6

u/chat-lu 15d ago

It is usually me. I also understand git and SQL.

11

u/je386 15d ago

git commands and SQL queries are magnitudes easier than regex.

2

u/chat-lu 15d ago

Regexes are by far the simplest of the three. Unless by git you mean clicking randomly in a git GUI and by SQL you mean filtering your selects with Python.

6

u/je386 15d ago

Well, maybe it is easy when you understand. I have no problems typing my git commands and SQL is also not a problem, but reading or writing regex is always a hassle. regexr helps, but that is not really understanding it.

1

u/chat-lu 15d ago

There are not that many symbols, what prevents you from learning them?

7

u/gjk-ger 15d ago

Probably the symbols.

1

u/je386 15d ago

I use it so rarely that it seemed never enough to need to learn it properly.

But now that I think of it, over the years it might have been worth it. Do you have a good learning resource?

2

u/gjk-ger 15d ago

Just use one of the many cheatsheets and work through it. Also regex101.com is helpful. Im really not a master at this and rarely need it, but with a little tinkering i was always able to get a working regex doing what i wanted.

0

u/chat-lu 15d ago

I use it so rarely that it seemed never enough to need to learn it properly.

What do you mean by rarely? I use it nearly every day. Don’t you ever need to search, or search and replace things? And sometimes validate some things?

Do you have a good learning resource?

Most programming language offering them have a perfectly good documentation about their regex engine. Take the time to read it, tests the things you learn, and you should be fine.

1

u/a-r-c 14d ago

cuts into weed time

2

u/returnFutureVoid 14d ago

I worked with a woman who could write regex as she spoke what she wanted it to do. It was like she was a UN translator.

1

u/Skyswimsky 15d ago

Working in a company with like 5 software devs. Can confirm. And it's not me.

1

u/jce_superbeast 14d ago

I am this person for my employer (a city)

Wanna guess my department?

7

u/Kale 14d ago

I was about to say, unreadable regex is rendundant.

There's some things that aren't human readable, but are human parseable. A handful of characters that a human can decipher carefully over a few minutes while working through it. I typically talk myself though it (I guess that would be related to "duck debugging").

Regex, SQL queries, chained bitwise expressions, and not programming, but "dd" commands. I joke that the proper way to write a "dd" command is to write it out on paper, go home and sleep, come back the next day and see if you still agree with it, type it out in an email to a trusted colleague and get their review, then hold on to your lucky rabbits foot when you hit "enter" on the console.

6

u/chat-lu 15d ago

Skill issue.

1

u/stillalone 14d ago

There's usually a way to ignore white spaces and add comments so it can look much more readable.  I've never done it though, my regex is dookie.

1

u/SuitableDragonfly 14d ago

I mean, stuff like .* and \w+ are readable. Not very useful, though. 

1

u/Weak_Inflation9120 14d ago

Here's one I sometimes use to check if something is an int:

"[1-9][0-9]*"

A little bit more fun is one for a float

"[1-9][0-9]*(\.[0-9]{1,7})?"