Count me among those. At best, panic/recover would be an uglier version of throw/catch with even worse performance.
That said, I hope someday Go adds the "?" return-operator that kotlin and Rust use. Won't really change anything besides adding syntactic sugar for an already recommended pattern. But development ergonomics would improve a lot.
in all the production code I've written in go since then, I haven't used panic/recover because its not considered proper. But I'm still a bit skeptical as do think it can make code a bit cleaner when writing a library (I'd 100% agree though that the panic should never escape the library though and only a plain error returned to the caller, i.e. need strong library boundaries for this).
Same here. I think this is my biggest code-reading pain point as a go developer. I'm toying with the idea of playing more with Go+
https://github.com/goplus/gop/blob/main/doc/docs.md#error-ha...
Works quite well because it can take advantage of the host of optimizations inside the regex engine.
If I remember correctly I was asked to be able to do a regex that handled . ? and *
The problem I have with this question is that if you spend 10-15 minutes going down a very wrong path, it's very very difficult to correct yourself in a pressurized environment.
I've tried to take the question and reformat it.
i.e.
I ask, what language do you want to program in (presuming I'm comfortable with the languages they want to use, otherwise I wouldn't be in the room, as wouldn't be a fair evaluation).
I give them the basic "strcmp" from pike's implementation (i.e. move character by character matching). i.e. something like
int match(char *s, char *r) {
if (*s == '\0' && *r == '\0') {
return 1;
} else if (*s == *r) {
return match(s+1, r+1);
} else {
return 0;
}
}
First Q. What does this do? (explained above)Second Q. how could we modify it work to match a substring (my explanation would be to just iterate over text like pike, but as with everything need to be open to where the interview takes you, but sometimes might need to say "that works for this, but for the future Qs, might want to think of it in this way", and give them some code, as again, I dont want them to code themselves into a corner that they don't have time to get out of).
Third Q. how could we add anchor support (ala regex, with a bit of explanation if they don't know what they are) (ala pike, determines where we are in the text, ala for ^ no iterating, and for $ we should be at a '\0' in the text
Fourth Q. how could we add "." support (just a || change to the primary matching condition, with being smart to check for '\0' which shouldn't match, but in a pressurized environment they might not get that without prodding right away)
Fifth Q. how could we add "?" support (now we have to look ahead a bit ala what pike does with )
Sixth Q (and the hardest), how could we add support.
I want to see if they can take some existing code, digest it and then see how they think to expand it. As there are many deliverables along the way, I'd hope I'd get a decent amount of "signal" even if they can't get to "?" or "*"
I also give them the link to kernighan's discussion on pike's code at the end.
if people have critiques of this approach to the Q (or further ways to improve it, I'm open)
I refuse to believe anyone could imagine it's possible. Either that or there's a whole bunch of hidden talent wasting away at Google - which sounds unlikely.
(I did interview training at Google twice)
I still think it's a terrible interview format, though.
I had an interview at google years ago where I basically I was asked to come up with this on my own. In my opinion, a terrible interview Q (per Kernighan's blog, linked in original post, it took pike an hour or two alone in his office), and I bombed it. It was either my just before or just after lunch interview and it stuck with me for the rest of the day and I couldn't give my entire focus to the rest of the sessions.
anyways, after it was done, I found kernighan's blog post and decided I should try to implement this in java as it will allow me to even get some practice with things like junit and more experience with object oriented programming as I had been living in the C world at that time). so I did, but I then found this regular expression page ( https://www.regular-expressions.info/) and learned many more things about "regular expressions" that i hadn't learned in school (because they aren't regular) and wondered if I could extend pike's simplicity to them in a relatively simple manner. So I did.
which I created this https://github.com/sjpotter/regex.
Not meant to be "performant" but meant to be educational to me and perhaps others.
Then when I was learning go, I rewrote it in Go. I did things that are not "normal" go patterns (i.e. using panic and recover to make error handling cleaner (in my opinion, if an error path is simply if (err) { return err } all the way up, I personally think panics/recover at the top can be cleaner, but it seems most disagree), but it was educational on how to rewrite my java code to an object oriented style in Go and to explore the limitations of interfaces and how one might get around them (also perhaps in ways that go against what might be considered proper go programming)
https://github.com/sjpotter/regex-go
though now that I look at that repo, wondering if all the work was done elsewhere and then I just pushed a single commit there, might need to go back and look at it