3 ms·
I think this article is missing the forest for the trees. I've found that dividing software into layers, and making sure that each file relies on the same set
by hedora 4y ago
I think this article is missing the forest for the trees.
I've found that dividing software into layers, and making sure that each file relies on the same set of invariants from its dependencies, and also maintains a (different) consistent set of invariants for its callers works much better.
For instance, I'd prefer a function that takes a string and confirms it is a valid URL.
That would delegate to URL character esacaping logic and DNS validation. (Are & or ? valid DNS name characters? Will they be in the future? I neither know nor care.)
On top of that, there would be a parser for key=value config file lines.
Then, the example in the article becomes something like:
keyvalue = parseConfLine(input)
URL(keyvalue.value).params[-3]
Plus a few more lines to confirm key is as expected and that value has enough query parameters.
Alternatively, I'd use a perl oneliner with a regexp. I see no purpose for code that lands in the middle ground between these extremes.