-
Notifications
You must be signed in to change notification settings - Fork 77
Implement the pushContext & popContext methods
#18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
6725d74 to
70b6ce5
Compare
70b6ce5 to
9c6e047
Compare
|
Documentation is missing too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initial pushContext would only make sense, if a popContext would also be triggered "automatically". but this seems to be not possible, so I would assume the caller should call both explicitly so the callers' code is more logical.
wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can call the popContext in the destructor, but when the object is destructed, the SplStack will be destructed just before, so no need to pop the first (so the latest) context :-). Nop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
popContext in the descructor would not be a good design (because it might never be called, e.g. when the object is assigned e.g. to a property). Therefore I think the __construct should not have side-effects like this. The class should define in its contract that pushContext and popContext need to be called etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the first push is to set elementMap because its default value is null. So where is the problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm think you are right.. didn't read carefully enough to see that there is a "init" case for that on pushContext
|
I'd like to take a stab at this myself a bit later in the day =) there's a few other things I would like to change up a bit... |
1dc9c05 to
3aed114
Compare
|
@evert As you like :-). I have added inheritance and the stack includes |
|
I looked into SplStack. It's kind of cool, but overall I think using it is a little bit less legible. So one reason to go for it, is that it perhaps has better performance features. So I wrote a benchmark : array vs SplStack. Doing a few pushes and pops. End result One thing tha'ts immediately obvious, is that the operations are so fast, that it's almost silly to optimize for. However, using a plain array is twice as fast so that means I have no argument for SplStack anymore aside from that it's kinda fun to use specialized spl objects. I didn't test for memory, but I doubt SplStack would come out well there. |
|
Good :-). |
Fix #16.
Tests are missing.