This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: References to stack bottom are confusing
Type: Stage:
Components: Documentation Versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 2.7, Python 2.6, 3rd party
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, eli.bendersky, ezio.melotti, georg.brandl, techtonik
Priority: normal Keywords:

Created on 2013-03-20 16:28 by techtonik, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (9)
msg184771 - (view) Author: anatoly techtonik (techtonik) Date: 2013-03-20 16:28
If stack is saved in list and printed to the screen, it will be printed as:
[
  root,
  second,
  last
]

And the last elements is the bottom element. The documentation at http://docs.python.org/3/reference/datamodel.html#frame-objects refers "bottom element" to be the first one. That's confusing. It is better to avoid top/bottom and use first/last or root/terminal.
msg184847 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2013-03-21 06:20
Sorry, I find your suggested termini more confusing.

* first/last: the first that was put onto the stack (i.e. bottom) or the first to be popped off (i.e. top)?

* root/terminal: that makes you think of trees, but a stack is not a tree.

top/bottom is the established wording for referring to a stack's positions, and its internal representation as a list is secondary.
msg184880 - (view) Author: anatoly techtonik (techtonik) Date: 2013-03-21 16:11
stack = []
stack.append(item)
stack.append(item)
stack.append(item)

This is an appropriate explanation of the stack in Python, the first frame is the frame that was put in first.


root/terminal - if you know what a stack is, you won't confuse it with a tree, if you don't - then in my opinion your top/bottom terminology won't help to gain understanding. root/terminal removes the ambiguity.


right/left is also a good alternative. Nobody imagines a stack growing right to left.
msg184883 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-03-21 16:26
Using "first" makes some sense, since it's talking about "previous", but I agree it might be confused with the top frame too.  What about this wording then:
-f_back is to the previous stack frame (towards the caller),
-or None if this is the bottom stack frame;
+f_back is to the previous stack frame (towards the caller),
+or None if this is the first frame at the bottom of the stack;
msg184885 - (view) Author: anatoly techtonik (techtonik) Date: 2013-03-21 16:45
+or None if this is the first frame (at the bottom of the stack);

I'd avoid top/bottom altogether, but if it is what is needed to reach the consensus then I am fine with that.
msg184887 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-03-21 17:11
Top/bottom is accepted and understood nomenclature when talking about stacks. Think about a stack of plates in the kitchen. You put a new plate on top, you take it out from top. That's it.

Now, lists are just one way to implement stacks, and printing them is also inconclusive in direction. Therefore I don't think we should mix the implementation/definition here and keep top/bottom.
msg184889 - (view) Author: anatoly techtonik (techtonik) Date: 2013-03-21 17:23
It appeared that I always thought that stacks grow down towards the end of memory, but it appears that they are growing down towards the beginning (x86 and friends). Spent some years with assembly to miss that. A shame on me. =)

Even if title of the issue is still true, it is no more actual. I am closing this. Thanks for support.
msg184891 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-03-21 17:29
I actually find the growth direction confusing sometimes for the same reasons (too much x86 assembly). This is why I wrote this blog post a while back - mainly so I can always look at it and de-confuse myself: http://eli.thegreenplace.net/2011/02/04/where-the-top-of-the-stack-is-on-x86/
msg184898 - (view) Author: anatoly techtonik (techtonik) Date: 2013-03-21 18:57
@eli.bendersky: The article is awesome. One of the cases when I regret that many interesting Python posts don't have a +1 button. One more chapter about C stack overflow and it will get all top hits. ;)
History
Date User Action Args
2022-04-11 14:57:43adminsetgithub: 61696
2013-03-21 18:57:16techtoniksetmessages: + msg184898
2013-03-21 17:29:16eli.benderskysetmessages: + msg184891
2013-03-21 17:23:19techtoniksetstatus: open -> closed
resolution: remind -> works for me
messages: + msg184889
2013-03-21 17:11:52eli.benderskysetnosy: + eli.bendersky
messages: + msg184887
2013-03-21 16:45:56techtoniksetmessages: + msg184885
2013-03-21 16:26:03ezio.melottisetstatus: pending -> open
nosy: + ezio.melotti
messages: + msg184883

2013-03-21 16:11:44techtoniksetstatus: closed -> pending
resolution: rejected -> remind
messages: + msg184880
2013-03-21 06:20:08georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg184847

resolution: rejected
2013-03-20 16:28:29techtonikcreate