Hacker News new | ask | show | jobs
by handoflixue 1840 days ago
> ‘*’ is fewer characters.

yes, but that produces false positives, whereas both 'apex|ibex|index' and '(ap|ib|ind)ex' do not.

Your original claim was that 'apex|ibex|index' was "simplest", which means it has some property you think that '(ap|ib|ind)ex' lacks, but you haven't yet articulated what that IS.

1 comments

It is the simplest to reason about.

And the simplest to produce algorithmically.

To prove it, extend each regex to include “indices”.

Being less clever, it is simpler to debug.

Depends on whether your relevant criteria is "those 3 words at random" or you have some reason to draw attention to the fact that they all end in "ex".

If I saw that list, I'd certainly assume there was something special about the "ex" ending since they don't otherwise have much in common and it's extremely unlikely for random chance to produce three "-ex" words just by chance. The shorter regex does a good job of highlighting that yes, "-ex" is the relevant criteria we care about.

It is easy to produce very brittle code by assuming a premise that allows one to rationalize being clever. Or as the British sometimes say “too clever by half.”

I just picked three words I fancied at the time I was illustrating my point. Not random, but not because -ex was important. The language game I was playing was writing an HN comment for amusement.

The finite state machine of my regular expression has one fewer nodes than yours. If that ain’t simpler it will do until simpler shows up.

Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? — Brian Kernighan

The language game we're playing is defining the rules for the language game we're playing. In your extension of the rules, adding a requirement of extensibility (to add 'indices') is a valid move; in your opponent's version it isn't. It could just as well be argued that it is adding the extensibility requirement that is “too clever by half.”