Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

We've a call stack in our project. The program is written for microcontroller, the language is C. The call stack is basically an array of integers. The variable that represents this call stack ends with the string _stack.

I was reviewing the implementation. The feature is reset recovery, not the call stack, but the call stack is part of the feature. When I first saw the variable, I thought it is used as a stack. So I assumed the following:

  • No entries other than the last entry can be accessed.
  • There will be PUSH/POP/CLEAR/TOP operations.

Next, I found that the first entry (index 0) is always checked in a special condition. I also found a function where all elements of the array are read sequentially from index 0 to top. Both of them are invalid stack operation.

I am thinking that the variable name should not contain the string stack as it is not a stack, rather it is used as a list. But the coder is showing valid logic, that according to semantic meaning, it's a stack and there is in fact PUSH operations.

Should the variable be named with *stack*?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

In your case, the difference between calling the structure a list which it apparently is and a stack which it is effectively being used as, is the debate between Systems & Apps Hungarian notation.

Depending on the situation and context, one might be more appropriate than the other. Generally Apps Hungarian provides the reader with a greater context of the use of the variable based on the name alone than Systems Hungarian, thus leading so somewhat self-documenting code.

share|improve this answer
    
I don't understand your last paragraph: "Generally Apps Hungarian provides the reader with a greater context of the use of the variable based on the name alone than Apps Hungarian". I'm assuming the first is supposed to be Apps Hungarian and the second is supposed to be System notation. –  Thomas Owens Jan 23 '12 at 12:45
2  
Sorry, I just woke up... –  Glenn Nelson Jan 23 '12 at 12:46
    
No problem. I was going to edit it, since I was pretty sure I knew what you were trying to say, but I wanted to be 100% sure that my assumption was right rather than have a wrong answer. –  Thomas Owens Jan 23 '12 at 12:55

SHUZAN held up his staff and waved it before his monks.

"If you call this a staff," he said, "you deny its eternal life. If you do not call this a staff, you deny its present fact. Tell me just what do you propose to call it?"

If it's a variation or embellishment of a stack, I'd be fine with calling it a stack.

But I do hope that there is a bit of commentary or documentation that explains what information it represents, what the normal stack-like operations mean, and why it's necessary to have the others that don't follow the stack discipline.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.