💾 Archived View for rawtext.club › ~sloum › geminilist › 007302.gmi captured on 2024-03-21 at 15:55:46. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2021-11-30)
-=-=-=-=-=-=-
Chris McGowan cmcgowan9990 at gmail.com
Thu Oct 14 00:53:02 BST 2021
- - - - - - - - - - - - - - - - - - -
Using RegEx this way is in effect doing the starts-with method I
mentioned in my other email.
Sort of, its actually technically less efficient since a startsWith method should simply loop over the string. Regex is admittedly a bit overkill for this but being a Perl developer and the problem statement being parsing, it was the first thing I reached for.
You can actually accomplish this slightly more efficiently in Perl using the index (and in the case of headers, rindex) functions.
Of course, gemini parsing is so light that the difference in execution speed/ memory use between either version is negligible in almost all cases.
Since this is "Perl but with C tactics" code: does Perl have a switch statement?
Yes and no. It does have a switch statement but its use is heavily discouraged as it was a (failed) experiment and will likely be removed in the near future. If you want a switch like construct in Perl, the general idiom is:
Of course there's several CPAN modules which also implement a switch statement, so you're free to use any of them if that's not to your liking. FWIW, the equivalent C version would not be shorter for using switch statements as switches in C can only work on integers and chars (which are also technically integers). You would have to either have nested ifs or nested switches, neither of which is pretty. > > In summary, I hardly think it's impossible or even difficult to > > unambiguously parse gemtext without having a mandatory space. > >I never claimed that it wasn't, just that it's easier to program. Ah I thought you meant that the first three characters were somehow not enough to unambiguously parse the line without the mandatory space. Apologies for the misunderstanding. Given that argument, I would say I'm not sure that it's worth adding a requirement which burdens the user (admittedly very minorly) just as a very small benefit to the programmer parsing it. If you're going to lay additional requirements on the user, the benefits of simplifying the parsing has to be fairly substantial (at least IMO). In this case we're talking about reducing a ~20 line function to a ~10 line function. Pretty small potatoes.