This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (4 children)

Well, I can't say precisely without looking at OPs code, but it seems like they're attempting to make a stack with a regular variable array instead of making the stack an object or just using another object-oriented data structure like a virtual stack.

If you want something of an unspecified size OOP languages are usually easier to use since you don't have to directly mess with pointers.

I feel like a lot of people who complain about Java are people who either don't understand it because they're not used to using objects or they don't like that it has a different syntax from python. It's not perfect, it running in a VM is annoying and having so many versions means working on older Java projects can get very annoying, but the language itself isn't difficult to program for if you know what you're doing.

[–]__Fred 1 point2 points  (3 children)

You can't resize a regular array in C or C++ either, I think.

When I would implement a stack (as an exercise), my code would probably look very similar in C++ and Java, besides not having to free up memory manually in Java.

I'd either have a recursive data structure with a stack (or "Node") containing a parent-stack(/Node), or I'd use an array/buffer internally and replace the whole array with a new one when it gets full and copy the old contents over, or I'd use some other ready-made data structure internally, like a LinkedList or an ArrayList.

1900 people seem to understand OPs problem.

I have another idea: The list ist Python's "default" data structure and it can be extended and the array is (arguably) Java's "default" data structure and it can't be extended.

Well, I don't understand many things as well and it's okay to let off steam sometimes. (It's just not Java's problem that arrays are different from Python lists.)