This review is in response to the request for help on "overall coding practice." It does not delve into the syntax or semantics of the C++ language. There are three levels: Computer Science, Architecture, Variable Names.
Computer Science
##Computer Science## TechnicallyTechnically the implementation is not a stack because:
myStack.push(4);
myStack.pop();
does not return 4
. To be a proper stack, rather than returning void
, pop
should be:
int pop();
In other words, pop()
must return something that was pushed onto the stack (or an error, but that's an architectural issue not a principle of computer science).
Architecture
##Architecture##
StrictlyStrictly speaking topElement()
could return a void and write a message to the console, but it is conventional for it to return something of the same type as the top element of the stack - in the case of reference types, the question of whether it should be a copy [and what type of copy] or a reference to the object itself muddies the waters.
The current implementation of void pop();
points to a larger architectural issue, a low degree of modularity. Currently, user interface is spread across the code and the stack data structure even writes messages to the console. The effect:
- The implementation of stack is not broadly reusable.
- The user interface does not have a clear design and would be hard to debug at a larger scale. There's a bit of the "spaghetti design pattern."
A more modular approach to implementing stack might be:
public:
Mystack();
void push(int x);
int pop();
int topElement();
bool isEmpty();
bool isFull(); // added to allow bounds checking
void print(); // could be handled elsewhere but that's pure opinion.
and placing - from the viewpoint of the stack - all the user interface code in Main
. Whether the user interface logic all lives there or in it's own class/module is another question. But reusability and maintenance certainly offer suggestions.
For example, breaking out the user interface and its logic and its content into modules allows handling nasty issues like multiple languages and the quirks of UniCode to be handled more gracefully. String output is the one of the places Your-Not-Gonna'-Need-It [YNGNI] fails and why it is a baked in module for so many development frameworks.
Variable Names
##Variable Names##
A
, num
, ch
, and s1
though perhaps conventional for C++ example code, don't really scale well because they lack information. Even in the original code:
cout << "top: " << A[i]<< endl;
is more than 50 lines from:
private:
int A[MAX_SIZE];
and that distance is only likely to grow as a useful program adds features.
##Final Thought##
Final Thought
I cannot help but recommend McConnell's Code Complete as a guide to deepening one's understanding of the ways in which software can be organized.
This review is in response to the request for help on "overall coding practice." It does not delve into the syntax or semantics of the C++ language. There are three levels: Computer Science, Architecture, Variable Names.
##Computer Science## Technically the implementation is not a stack because:
myStack.push(4);
myStack.pop();
does not return 4
. To be a proper stack, rather than returning void
, pop
should be:
int pop();
In other words, pop()
must return something that was pushed onto the stack (or an error, but that's an architectural issue not a principle of computer science).
##Architecture##
Strictly speaking topElement()
could return a void and write a message to the console, but it is conventional for it to return something of the same type as the top element of the stack - in the case of reference types, the question of whether it should be a copy [and what type of copy] or a reference to the object itself muddies the waters.
The current implementation of void pop();
points to a larger architectural issue, a low degree of modularity. Currently, user interface is spread across the code and the stack data structure even writes messages to the console. The effect:
- The implementation of stack is not broadly reusable.
- The user interface does not have a clear design and would be hard to debug at a larger scale. There's a bit of the "spaghetti design pattern."
A more modular approach to implementing stack might be:
public:
Mystack();
void push(int x);
int pop();
int topElement();
bool isEmpty();
bool isFull(); // added to allow bounds checking
void print(); // could be handled elsewhere but that's pure opinion.
and placing - from the viewpoint of the stack - all the user interface code in Main
. Whether the user interface logic all lives there or in it's own class/module is another question. But reusability and maintenance certainly offer suggestions.
For example, breaking out the user interface and its logic and its content into modules allows handling nasty issues like multiple languages and the quirks of UniCode to be handled more gracefully. String output is the one of the places Your-Not-Gonna'-Need-It [YNGNI] fails and why it is a baked in module for so many development frameworks.
##Variable Names##
A
, num
, ch
, and s1
though perhaps conventional for C++ example code, don't really scale well because they lack information. Even in the original code:
cout << "top: " << A[i]<< endl;
is more than 50 lines from:
private:
int A[MAX_SIZE];
and that distance is only likely to grow as a useful program adds features.
##Final Thought##
I cannot help but recommend McConnell's Code Complete as a guide to deepening one's understanding of the ways in which software can be organized.
This review is in response to the request for help on "overall coding practice." It does not delve into the syntax or semantics of the C++ language. There are three levels: Computer Science, Architecture, Variable Names.
Computer Science
Technically the implementation is not a stack because:
myStack.push(4);
myStack.pop();
does not return 4
. To be a proper stack, rather than returning void
, pop
should be:
int pop();
In other words, pop()
must return something that was pushed onto the stack (or an error, but that's an architectural issue not a principle of computer science).
Architecture
Strictly speaking topElement()
could return a void and write a message to the console, but it is conventional for it to return something of the same type as the top element of the stack - in the case of reference types, the question of whether it should be a copy [and what type of copy] or a reference to the object itself muddies the waters.
The current implementation of void pop();
points to a larger architectural issue, a low degree of modularity. Currently, user interface is spread across the code and the stack data structure even writes messages to the console. The effect:
- The implementation of stack is not broadly reusable.
- The user interface does not have a clear design and would be hard to debug at a larger scale. There's a bit of the "spaghetti design pattern."
A more modular approach to implementing stack might be:
public:
Mystack();
void push(int x);
int pop();
int topElement();
bool isEmpty();
bool isFull(); // added to allow bounds checking
void print(); // could be handled elsewhere but that's pure opinion.
and placing - from the viewpoint of the stack - all the user interface code in Main
. Whether the user interface logic all lives there or in it's own class/module is another question. But reusability and maintenance certainly offer suggestions.
For example, breaking out the user interface and its logic and its content into modules allows handling nasty issues like multiple languages and the quirks of UniCode to be handled more gracefully. String output is the one of the places Your-Not-Gonna'-Need-It [YNGNI] fails and why it is a baked in module for so many development frameworks.
Variable Names
A
, num
, ch
, and s1
though perhaps conventional for C++ example code, don't really scale well because they lack information. Even in the original code:
cout << "top: " << A[i]<< endl;
is more than 50 lines from:
private:
int A[MAX_SIZE];
and that distance is only likely to grow as a useful program adds features.
Final Thought
I cannot help but recommend McConnell's Code Complete as a guide to deepening one's understanding of the ways in which software can be organized.
This review is in response to the request for help on "overall coding practice." It does not delve into the syntax or semantics of the C++ language. There are three levels: Computer Science, Architecture, Variable Names.
##Computer Science## Technically the implementation is not a stack because:
myStack.push(4);
myStack.pop();
does not return 4
. To be a proper stack, rather than returning void
, pop
should be:
int pop();
rather than returning void
. In other words, pop()
must return something that was pushed onto the stack (or an error, but that's an architectural issue not a principle of computer science).
##Architecture##
Strictly speaking topElement()
could return a void and write a message to the console, but it is conventional for it to return something of the same type as the top element of the stack - in the case of reference types, the question of whether it should be a copy [and what type of copy] or a reference to the object itself muddies the waters.
The current implementation of void pop();
points to a larger architectural issue, a low degree of modularity. Currently, user interface is spread across the code and the stack data structure even writes messages to the console. The effect:
- The implementation of stack is not broadly reusable.
- The user interface does not have a clear design and would be hard to debug at a larger scale. There's a bit of the "spaghetti design pattern."
A more modular approach to implementing stack might be:
public:
Mystack();
void push(int x);
int pop();
int topElement();
bool isEmpty();
bool isFull(); // added to allow bounds checking
void print(); // could be handled elsewhere but that's pure opinion.
and placing - from the viewpoint of the stack - all the user interface code in Main
. Whether the user interface logic all lives there or in it's own class/module is another question. But reusability and maintenance certainly offer suggestions.
For example, breaking out the user interface and its logic and its content into modules allows handling nasty issues like multiple languages and the quirks of UniCode to be handled more gracefully. String output is the one of the places Your-Not-Gonna'-Need-It [YNGNI] fails and why it is a baked in module for so many development frameworks.
##Variable Names##
A
, num
, ch
, and s1
though perhaps conventional for C++ example code, don't really scale well because they lack information. Even in the original code:
cout << "top: " << A[i]<< endl;
is more than 50 lines from:
private:
int A[MAX_SIZE];
and that distance is only likely to grow as a useful program adds features.
##Final Thought##
I cannot help but recommend McConnell's Code Complete as a guide to deepening one's understanding of the ways in which software can be organized.
This review is in response to the request for help on "overall coding practice." It does not delve into the syntax or semantics of the C++ language. There are three levels: Computer Science, Architecture, Variable Names.
##Computer Science## Technically the implementation is not a stack because:
myStack.push(4);
myStack.pop();
does not return 4
. To be a proper stack, pop
should be:
int pop();
rather than returning void
. In other words, pop()
must return something that was pushed onto the stack (or an error, but that's an architectural issue not a principle of computer science).
##Architecture##
Strictly speaking topElement()
could return a void and write a message to the console, but it is conventional for it to return something of the same type as the top element of the stack - in the case of reference types, the question of whether it should be a copy [and what type of copy] or a reference to the object itself muddies the waters.
The current implementation of void pop();
points to a larger architectural issue, a low degree of modularity. Currently, user interface is spread across the code and the stack data structure even writes messages to the console. The effect:
- The implementation of stack is not broadly reusable.
- The user interface does not have a clear design and would be hard to debug at a larger scale. There's a bit of the "spaghetti design pattern."
A more modular approach to implementing stack might be:
public:
Mystack();
void push(int x);
int pop();
int topElement();
bool isEmpty();
bool isFull(); // added to allow bounds checking
void print(); // could be handled elsewhere but that's pure opinion.
and placing - from the viewpoint of the stack - all the user interface code in Main
. Whether the user interface logic all lives there or in it's own class/module is another question. But reusability and maintenance certainly offer suggestions.
For example, breaking out the user interface and its logic and its content into modules allows handling nasty issues like multiple languages and the quirks of UniCode to be handled more gracefully. String output is the one of the places Your-Not-Gonna'-Need-It [YNGNI] fails and why it is a baked in module for so many development frameworks.
##Variable Names##
A
, num
, ch
, and s1
though perhaps conventional for C++ example code, don't really scale well because they lack information. Even in the original code:
cout << "top: " << A[i]<< endl;
is more than 50 lines from:
private:
int A[MAX_SIZE];
and that distance is only likely to grow as a useful program adds features.
##Final Thought##
I cannot help but recommend McConnell's Code Complete as a guide to deepening one's understanding of the ways in which software can be organized.
This review is in response to the request for help on "overall coding practice." It does not delve into the syntax or semantics of the C++ language. There are three levels: Computer Science, Architecture, Variable Names.
##Computer Science## Technically the implementation is not a stack because:
myStack.push(4);
myStack.pop();
does not return 4
. To be a proper stack, rather than returning void
, pop
should be:
int pop();
In other words, pop()
must return something that was pushed onto the stack (or an error, but that's an architectural issue not a principle of computer science).
##Architecture##
Strictly speaking topElement()
could return a void and write a message to the console, but it is conventional for it to return something of the same type as the top element of the stack - in the case of reference types, the question of whether it should be a copy [and what type of copy] or a reference to the object itself muddies the waters.
The current implementation of void pop();
points to a larger architectural issue, a low degree of modularity. Currently, user interface is spread across the code and the stack data structure even writes messages to the console. The effect:
- The implementation of stack is not broadly reusable.
- The user interface does not have a clear design and would be hard to debug at a larger scale. There's a bit of the "spaghetti design pattern."
A more modular approach to implementing stack might be:
public:
Mystack();
void push(int x);
int pop();
int topElement();
bool isEmpty();
bool isFull(); // added to allow bounds checking
void print(); // could be handled elsewhere but that's pure opinion.
and placing - from the viewpoint of the stack - all the user interface code in Main
. Whether the user interface logic all lives there or in it's own class/module is another question. But reusability and maintenance certainly offer suggestions.
For example, breaking out the user interface and its logic and its content into modules allows handling nasty issues like multiple languages and the quirks of UniCode to be handled more gracefully. String output is the one of the places Your-Not-Gonna'-Need-It [YNGNI] fails and why it is a baked in module for so many development frameworks.
##Variable Names##
A
, num
, ch
, and s1
though perhaps conventional for C++ example code, don't really scale well because they lack information. Even in the original code:
cout << "top: " << A[i]<< endl;
is more than 50 lines from:
private:
int A[MAX_SIZE];
and that distance is only likely to grow as a useful program adds features.
##Final Thought##
I cannot help but recommend McConnell's Code Complete as a guide to deepening one's understanding of the ways in which software can be organized.
This review is in response to the request for help on "overall coding practice." It does not delve into the syntax or semantics of the C++ language. There are three levels: Computer Science, Architecture, Variable Names.
##Computer Science## Technically the implementation is not a stack because:
myStack.push(4);
myStack.pop();
does not return 4
. To be a proper stack, pop
should be:
int pop();
rather than returning void
. In other words, pop()
must return something that was pushed onto the stack (or an error, but that's an architectural issue not a principle of computer science).
##Architecture##
Strictly speaking topElement()
could return a void and write a message to the console, but it is conventional for it to return something of the same type as the top element of the stack - in the case of reference types, the question of whether it should be a copy [and what type of copy] or a reference to the object itself muddies the waters.
The current implementation of void pop();
points to a larger architectural issue, a low degree of modularity. Currently, user interface is spread across the code and the stack data structure even writes messages to the console. The effect:
- The implementation of stack is not broadly reusable.
- The user interface does not have a clear design and would be hard to debug at a larger scale. There's a bit of the "spaghetti design pattern."
A more modular approach to implementing stack might be:
public:
Mystack();
void push(int x);
int pop();
int topElement();
bool isEmpty();
bool isFull(); // added to allow bounds checking
void print(); // could be handled elsewhere but that's pure opinion.
and placing - from the viewpoint of the stack - all the user interface code in Main
. Whether the user interface logic all lives there or in it's own class/module is another question. But reusability and maintenance certainly offer suggestions.
For example, breaking out the user interface and its logic and its content into modules allows handling nasty issues like multiple languages and the quirks of UniCode to be handled more gracefully. String output is the one of the places Your-Not-Gonna'-Need-It [YNGNI] fails and why it is a baked in module for so many development frameworks.
##Variable Names##
A
, num
, ch
, and s1
though perhaps conventional for C++ example code, don't really scale well because they lack information. Even in the original code:
cout << "top: " << A[i]<< endl;
is more than 50 lines from:
private:
int A[MAX_SIZE];
and that distance is only likely to grow as a useful program adds features.
##Final Thought##
I cannot help but recommend McConnell's Code Complete as a guide to deepening one's understanding of the ways in which software can be organized.
This review is in response to the request for help on "overall coding practice." It does not delve into the syntax or semantics of the C++ language. There are three levels: Computer Science, Architecture, Variable Names.
##Computer Science## Technically the implementation is not a stack because:
myStack.push(4);
myStack.pop();
does not return 4
. To be a proper stack, pop
should be:
int pop();
rather than returning void
. In other words, pop()
must return something that was pushed onto the stack (or an error, but that's an architectural issue not a principle of computer science).
##Architecture##
Strictly speaking topElement()
could return a void and write a message to the console, but it is conventional for it to return something of the same type as the top element of the stack - in the case of reference types, the question of whether it should be a copy [and what type of copy] or a reference to the object itself muddies the waters.
The current implementation of void pop();
points to a larger architectural issue, a low degree of modularity. Currently, user interface is spread across the code and the stack data structure even writes messages to the console. The effect:
- The implementation of stack is not broadly reusable.
- The user interface does not have a clear design and would be hard to debug at a larger scale. There's a bit of the "spaghetti design pattern."
A more modular approach to implementing stack might be:
public:
Mystack();
void push(int x);
int pop();
int topElement();
bool isEmpty();
bool isFull(); // added to allow bounds checking
void print(); // could be handled elsewhere but that's pure opinion.
and placing - from the viewpoint of the stack - all the user interface code in Main
. Whether the user interface logic all lives there or in it's own class/module is another question. But reusability and maintenance certainly offer suggestions.
For example, breaking out the user interface and its logic and its content into modules allows handling nasty issues like multiple languages and the quirks of UniCode to be handled more gracefully. String output is the one of the places Your-Not-Gonna'-Need-It [YNGNI] fails and why it is a baked in module for so many development frameworks.
##Variable Names##
A
, num
, ch
, and s1
though perhaps conventional for C++ example code, don't really scale well because they lack information. Even in the original code:
cout << "top: " << A[i]<< endl;
is more than 50 lines from:
private:
int A[MAX_SIZE];
and that distance is only likely to grow as a useful program adds features.
This review is in response to the request for help on "overall coding practice." It does not delve into the syntax or semantics of the C++ language. There are three levels: Computer Science, Architecture, Variable Names.
##Computer Science## Technically the implementation is not a stack because:
myStack.push(4);
myStack.pop();
does not return 4
. To be a proper stack, pop
should be:
int pop();
rather than returning void
. In other words, pop()
must return something that was pushed onto the stack (or an error, but that's an architectural issue not a principle of computer science).
##Architecture##
Strictly speaking topElement()
could return a void and write a message to the console, but it is conventional for it to return something of the same type as the top element of the stack - in the case of reference types, the question of whether it should be a copy [and what type of copy] or a reference to the object itself muddies the waters.
The current implementation of void pop();
points to a larger architectural issue, a low degree of modularity. Currently, user interface is spread across the code and the stack data structure even writes messages to the console. The effect:
- The implementation of stack is not broadly reusable.
- The user interface does not have a clear design and would be hard to debug at a larger scale. There's a bit of the "spaghetti design pattern."
A more modular approach to implementing stack might be:
public:
Mystack();
void push(int x);
int pop();
int topElement();
bool isEmpty();
bool isFull(); // added to allow bounds checking
void print(); // could be handled elsewhere but that's pure opinion.
and placing - from the viewpoint of the stack - all the user interface code in Main
. Whether the user interface logic all lives there or in it's own class/module is another question. But reusability and maintenance certainly offer suggestions.
For example, breaking out the user interface and its logic and its content into modules allows handling nasty issues like multiple languages and the quirks of UniCode to be handled more gracefully. String output is the one of the places Your-Not-Gonna'-Need-It [YNGNI] fails and why it is a baked in module for so many development frameworks.
##Variable Names##
A
, num
, ch
, and s1
though perhaps conventional for C++ example code, don't really scale well because they lack information. Even in the original code:
cout << "top: " << A[i]<< endl;
is more than 50 lines from:
private:
int A[MAX_SIZE];
and that distance is only likely to grow as a useful program adds features.
##Final Thought##
I cannot help but recommend McConnell's Code Complete as a guide to deepening one's understanding of the ways in which software can be organized.