Description
The bracket-push exercise is about determining whether the brackets in a given string are balanced.
So, one asks, why is the word "push" in the slug? I didn't see an explanation in exercism/DEPRECATED.javascript#31 where the exercise was added. Why is the exercise not called bracket-matching
or brackets
or something similar?
Well, okay, I can guess why: The name is meant to hint to the students that we can use a stack, because stacks have the "push" operation in the traditional literature. Aside: I wonder why that is so? I found http://stackoverflow.com/questions/420315/stacks-why-push-and-pop that may explain it - it's a spring-loaded stack of dishes.
In that case, I will half-jokingly note that this exercise name unfairly biases the solution space toward solutions that explicitly use a stack data structure and away from solutions using:
- recursive-descent parsers (well hey, the function call stack is, too, a stack!)
- some sort of state machine using the same grammar as the recursive-descent parser. Note that I can't really say "finite automaton" here (whether it be deterministic or not) because the language of nested brackets is not regular. But something similar, perhaps? Though of course its internal state will probably also be a stack of some sort.
- Iteratively attempting to remove any innermost pair of brackets until you can no longer do so. No stacks in this solution at all.
- Any other solutions that I have not even thought of or seen yet.
Now, remember that it is our policy that our exercises should not drive students toward any particular implementation and our exercises should not be over-prescriptive.
Since the name bracket-push does so, I considered proposing that we rename it.
Unfortunately, this is not my battle to fight today. But hey, if anyone ever comes along and makes the same proposal, you could let the proposer know that I agree, yeah?