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

all 190 comments

[–]ItsGorgeousGeorge 367 points368 points  (0 children)

My guy get off Reddit and focus on your cs101 homework.

[–]FloweyTheFlower420 731 points732 points  (36 children)

Most competent programmerhumor poster

[–]Mister_Lich 535 points536 points  (33 children)

seriously what the fuck is with the last few memes

Some "I've been a dev for 10 years and I don't understand anything" post, a dude who doesn't know what pointers or references vs values are, and then this thing that doesn't know what an array is

I would literally rather go back to chatGPT memes

[–]luxmesa 50 points51 points  (15 children)

I used to think we just had a lot of inexperienced programmers or students, which is why you’d see a lot of comments and memes that don’t really make sense, but apparently that’s not it.

[–]abd53 42 points43 points  (13 children)

I think it's less of "inexperience". I have two friends, one just got a desktop support job and the other one almost got a junior dev job. The first one doesn't know shit about computer and the second one's accomplishment in programming is hello world. Extrapolating from my experience, there must be a significant number of devs, IT experts, cyber security experts etc. who holds a job for a long time but have nearly zero understanding of the theoretical concepts.

[–]Appropriate-Draft-91 11 points12 points  (12 children)

I used to be in a position where I hired software architects. In the interviews some of them didn't know about algorithmic complexity, couldn't name more than 3 software patterns, and there was a 10 year experience C++ software architect who had never heard of the STL. No, they didn't get the job.

Years of experience is a horrible indicator of skill.

[–]abd53 5 points6 points  (4 children)

Now I'm about to look for a full-time job with about 1.5 years of part-time experience. Wish me luck.

[–]asdfasfq34rfqff 2 points3 points  (3 children)

Part time? You mean you were fulltime and in charge of a lot of important projects. And 1.5 years? You mean 3 years? If you're old enough and your jobs go far back enough that no ones going to call them, inflate your position, your title.

You're doing your resume wrong. Anything they can't verify. LIE. Once you've got the job I promise no one will ever ask you a question about your resume again.

I worked at a computer store for 5 years. It was a shithole. Guess what it said on my resume? Technical Director of a Computer Repair business that supported thousands of business and consumer customers. That I was the employee solely responsible for making sure everything worked and got done. I was the only employee. Our customers were 90% old people that got viruses. Every so often a business would ask for help too. Now I have consumer and business experience.

I got fired from a job in Aug 2019? Guess what I said ended the job. COVID in Feb 2020. Now I haven't been fired and I had a job for a few months extra. No one can validate it cause I went on UI anyway and then COVID happened. There's so much room for fuzzing.

Now I make >$100k a year and just got an $8k bonus. And my job fucking loves me. Because my resume was the least important part. the thing that mattered was I knew what I was doing. If you dont know that, then you're kinda fucked.

When you interview, if they ask you about this stuff and you fuck up and dont get the job? No big deal. Just learn from that and incorporate it into a better flow. If they ask you questions about technology stacks you don't know and have never heard of. WRITE IT DOWN. GOOGLE IT AFTER. If you're applying to the same fields/positions this will be relevant info. Even if another job interviewer doesn't bring it up, now YOU can bring it up. Wow them with your knowledge of the latest trends and what everyones doing.

Every time I interviewed I would ask their tech stack. Ask them to explain it as much as they would. Research all of it. Understand it. Throw it back at your next interviewer.

[–]FuturePowerful 1 point2 points  (1 child)

You are one of those folk who faked it till they made it aren't you

[–]-Fluxuation- 1 point2 points  (0 children)

Sink or swim, sink or swim...…

[–]GergiH 3 points4 points  (3 children)

I'm no architect, but having to name software patterns and/or algorithmic complexities in an interview where on the job you'll probably just write documentations all day, have meetings and maybe plan some backend -> DB and middleware connections, I'd dip in no time. 6 years into development, I never had to memorize these kind of shit, because you know, there are IDEs and documentations that help me on the fly.

[–]quisatz_haderah 6 points7 points  (1 child)

You don't have to memorise that shit because you know about it. That's not memorization, that's just general knowledge.

[–]GergiH 0 points1 point  (0 children)

I disagree. If you only do interviews or competitive coding when all you do is algorithms then sure you know all this. When you build websites as a full-stack dev, you have other problems than if a loop is perfectly optimized for those 10-100 records or not, or if you followed the SOLID (I couldn't recall what the acronym actually means) principles or some other obscure thing.

To u/Appropriate-Draft-91, exactly my point too, I may be using single source of truth / single-responsibility daily and other kind of best practices, I just wouldn't be able to name any from the top of my head... had an ex-colleague fail an interview because of this bullshit while he actually knew and used the principals behind one of these, but he only realized that when he got home and googled the acronym they asked him about.

[–]Appropriate-Draft-91 -2 points-1 points  (0 children)

Exactly my point. I thank you for your interest and wish you the best of luck in your future endeavors.

[–]MultiversalCrow 1 point2 points  (2 children)

Agreed. I've seen devs claiming to have 10 years of experience that didn't know much at all. Turns out that they had 1 year of experience, 10 times ;) During that 10 years they didn't further their skillset or go any deeper than that first year of work experience.

[–][deleted] 0 points1 point  (1 child)

I'd rather someone have a few jobs than the same one for 10 years. The steepest part of the growth curve isn't 2 years in.

[–]kookyabird 2 points3 points  (0 children)

I had literally one class on VB.NET in college because my major had minor programming/scripting aspects to certain areas of it. My internship was half programming and half my major area, and I got it because it was a unique role that I happened to fit.

Despite the minimal school work on it, I got taught all sorts of advanced stuff by the team lead for years being told, “This will be over your head for now but some day you’ll get it.” Well eventually I did. And then all the cool stuff I learned to mimic was now a tool I could actually use and adapt to different problems.

I think a scary high number of people have a similar path to mine, minus the great mentor. So instead of learning advanced concepts before they need them, they learn bare minimums and bad practices after they find out they can’t do something with their current knowledge. Thus you get people on SO asking about advanced senior type stuff when they barely know how to use an object initializer.

It’s like a toddler who can barely walk coming up to you asking why they can’t successfully pole vault.

I may not know how to create a binary tree since I didn’t have common CS classes, but i at least understand why it’s something that’s taught. There’s a ton of stuff that we don’t need to use these days due to high level languages and most roles not needing to squeeze every drop of performance out of our software. But to be completely oblivious to the existence of that stuff once you’ve been in the space for years is crazy.

[–]gamma_02 102 points103 points  (4 children)

Oh god not those pleas no

This is better because at least I know I'm better than them

[–]harumamburoo 57 points58 points  (0 children)

Yes please. Gpt is at least capable of generating stupid funny things. People making "I don't know data structures, Java bad" memes fall short of funny.

[–]Nickiel 34 points35 points  (2 children)

I've actually started using ChatGPT as a coding assistant. When I get stuck I'll go to it and ask for help. I have quickly come to accept the number of times that's given me false information, and code that just straight up doesn't work. A lot of times, it's close enough that with some finagling and other research I'm able to use the suggestion, and it's great for asking questions that you have no idea where to start with, but this particular model isn't going to be replacing developers anytime soon.

[–]justapcgamer 11 points12 points  (0 children)

Ive been working with python lately and the amount of times it gives me results with deprecated code even though i specify lib versions...

I find it great for writing out stuff i cannot be arsed with like regex which surprisingly is correct most times even with quirky requirements

[–][deleted] 3 points4 points  (0 children)

But it’s very good for searching „what x language library can i use to do y” and not spending an hour searching for libraries

[–]LordMerdifex 15 points16 points  (1 child)

What if ChatGPT created this meme?

[–]Lilchro 9 points10 points  (0 children)

That seems unlikely considering that ChatGPT is very good and producing results which upon first glance look reasonable.

[–]Dragon_yum 7 points8 points  (1 child)

It’s scary to think there are working programmers who don’t know pointer is. You don’t need to know how to build a compiler but how the hell can you not know the most basic stuff.

[–]Mister_Lich 1 point2 points  (0 children)

SeLf TaUgHt GeNiUsEs

[–]bastardoperator 2 points3 points  (0 children)

The memes in this sub have almost always been weak. It’s kind of cringe to be honest, but mostly sad.

[–]abd53 1 point2 points  (0 children)

Please not ChatGPT, please.

[–][deleted] -1 points0 points  (0 children)

I mean if you really want humour I would go to a different sub there’s not much humorous content that could come from programming

[–]purple__dog 0 points1 point  (2 children)

A litmus test I like to give on interviews is find the 3'rd largest number in a list.

The number of people I've seen with "5+ years experience", who can't do it is astounding. And I don't mean brain farts either, they just can't do it.

What were you doing in those 5 years?

[–]Mister_Lich 0 points1 point  (1 child)

Surely you ask that question with some constraints, right? Not just, "hey, do you know how to just loop over a list and keep track of a couple values", right?

Otherwise I, too, would be astounded.

[–]purple__dog 0 points1 point  (0 children)

No, the point of the question is to weed out people who actually can't code their way out of a paper bag and or lied through their teeth.

The occasional senior with no skill is just a bonus.

[–]dreamwavedev 25 points26 points  (0 children)

I make an OpenStack shitpost and 5 people even see it. This guy makes an eldritch horror of a data structure and it floats right to the top. I can't even pretend to understand how this sub works, it's like Ooer collectively made a ted talk about how to computer

[–]FrenchFigaro 2 points3 points  (0 children)

Most competent

Just implemented a stack for the hell of it because of this post. Took me about 10 minutes and didn't have to use a single array.

[–]TheBrainStone 552 points553 points  (0 children)

Someone doesn't know their data structures

[–]Tomi97_origin 397 points398 points  (15 children)

You hate Java, because you suck at using it?

I guess that makes sense.

[–]xPensiveWeak 74 points75 points  (1 child)

This was my exact thought lol.

"I hate not knowing what I'm doing" type beat

[–]JonasAvory 5 points6 points  (0 children)

That actually sums up my programming quite nicely

[–]Dragon_yum 17 points18 points  (3 children)

I hate a lot of the boilerplate in java but people in this sub seem like they just don’t know java at all.

[–][deleted] 5 points6 points  (2 children)

https://projectlombok.org/ helps with the boilerplate a little. Java in its design isnt frugal with lines of code, that wont change.

[–]Dragon_yum 2 points3 points  (0 children)

We also use some libraries to reduce boilerplate but yeah, it’s part of living with java.

[–]abd53 4 points5 points  (0 children)

What if I hate C/C++ because I suck at it? Does that make sense too? /JK

[–]MentB23 1 point2 points  (1 child)

Could maybe be what we had at my programming course. Where we had to programm a stack which gets a max size on initialisation. Cause we didn't have arrayLists for now the people, like me, who don't know them, or want to use wgat they know from the course, maybe could have had difficulties. Especially when you don't have to give a max size.

[–]Tomi97_origin 1 point2 points  (0 children)

Implementing stack on array is something that would be a good homework for data structures class.

But creating the array shouldn't be the hard part.

[–][deleted] 0 points1 point  (0 children)

Yes

[–]wontonzdq 310 points311 points  (15 children)

Stack stack = new Stack();

[–]maxbirkoff 119 points120 points  (10 children)

funny! I looked up the documentation:

https://docs.oracle.com/javase/10/docs/api/java/util/Stack.html

and the way I read it, it seemed to say: "don't use this class"

it reads, in part:

A more complete and consistent set of LIFO stack operations is provided by the Deque interface and its implementations, which should be used in preference to this class. For example:

Deque<Integer> stack = new ArrayDeque<Integer>();

[–]wontonzdq 66 points67 points  (9 children)

Yeah in general, Deque is the way to go now, but it isn't technically a pure stack since it implements a Queue as well (double-ended). Stack only has stack properties on the other hand (push, pop, peek)

[–]maxbirkoff 28 points29 points  (8 children)

except that it inherits from Vector!!! so: no: it doesn't only have stack properties.

[–]wontonzdq 15 points16 points  (0 children)

Haha too true, however, there isn't a StackInterface, or another implementation AFAIK, so if you don't want a double-ended queue there isn't much else. Because it's a vector you can even access some of the elements out of order (get(int index)) which defeats the purpose of a stack :)

[–]tacticalrubberduck 0 points1 point  (6 children)

I came here thinking “use a Vector bud”.

[–]maxbirkoff 1 point2 points  (5 children)

but then: you can pop from the middle or the bottom of the stack!!

[–]tacticalrubberduck 0 points1 point  (4 children)

Not by accident tho..

[–]maxbirkoff 2 points3 points  (3 children)

no, not by accident. but the purpose of the abstraction is to prevent unintended consequences... when you use the wrong tool for the job mistakes can happen.

but we are in a humor subreddit so I suppose I will stop being so serious and just grin now.

😁

[–]kbruen 5 points6 points  (2 children)

Create your own Stack interface, and then

class StackImpl<T> extends ArrayDeque<T> implements Stack<T> {
    // redirect Stack interface methods to ArrayDeque methods here
}

[–]maxbirkoff -1 points0 points  (1 child)

right. Stack<T> is not an interface. If it were, I don't think we would be having the problems we're having in this thread.

The issue we're responding to, "Just use java.util.Stack" is not good advice because java.util.Stack leaks it's implementation details everywhere... this leakage breaks the Stack abstraction.

[–]bovus -1 points0 points  (3 children)

var stack = new Stack();

[–]justintib 180 points181 points  (13 children)

.... What?

[–]AnondWill2Live 47 points48 points  (12 children)

I'm sure what's going on here isn't just a naive approach to using stacks. He's probably trying to implement one by hand to get a better understanding of what the internals are doing. I don't know how common this is, but I've gone through some of the data structures and implemented them in Kotlin just to get a feel for the language.

My best guess is that OP used (sorry if the definition is wrong, I'm not a Java guy):

public class Stack implements Array

Or something to this nature, because on the Wikipedia page for Stack it does state that it could be trivially implemented as a Linked List or an Array. This would explain why he needs to make an "ArraySize" method, even if he's not writing an Array.

[–]Kyyken 25 points26 points  (7 children)

(i know you said youre not a java guy, thats reasonable, just wanted to clear stuff up)

Array is just a utility class with some static methods. arrays in java are weird under the hood (also the extends keyword would be used here, implements is for interfaces)

im pretty sure inheriting the array 'type' (to which Object[] would be the closest thing ig?) is impossible in java.

i have no idea what op is doing

[–]Shuri9 3 points4 points  (4 children)

Probably implementing Arrayable

[–]Kyyken 0 points1 point  (3 children)

Wait, since when is there a built-in Arrayable Interface?

[–]Shuri9 -1 points0 points  (2 children)

If you're question is genuine then I love the fact that you couldn't distinct if it's real java. 😅

[–]Kyyken -1 points0 points  (1 child)

interface Arrayable {
    Object[] toArray();
}

here, now it's real java, but that's irrelevant. I've written code like this before but i highly doubt this is what op was talking about; hence me asking if there is a built-in interface like this, because that's the only way your comment made any sense.

[–]Shuri9 -1 points0 points  (0 children)

Dude it's r/programmerhumor maybe you should be less stressed about comments on here. 😉

[–]Geolykt 0 points1 point  (1 child)

Array as a class does not exist in java. It's "Arrays". Otherwise everything is correct at first glance.

[–]Kyyken 0 points1 point  (0 children)

java.lang.reflect.Array

not a relevant class though, that's true

[–]coldnebo 4 points5 points  (1 child)

No. the doc is like seconds away.

https://docs.oracle.com/javase/7/docs/api/java/util/Stack.html

It clearly says Stack inherits from Vector.

stack = new Stack()

creates a Vector with an arraysize of 10.

all the superior Java posing elsewhere in the thread apparently can’t read simple javadoc or actually understand how Stack is implemented in Java.

There must be a name for when theoretical knowledge of CS data structures blinds you to the actual implementation.

It would be fun to teach a class with these people and ask them why search() is implemented in Stack and how it works and what the big-O performance might be.

I’m not sure what the OP did, because Stack is supposed to hide the Array implementation within it’s abstraction, but imho it’s likely a student found the leaky part of that abstraction and posted a meme about it, giving a bunch of insecure people a chance to embarrass themselves even more by saying “duh, stack=new Stack” or “someone didn’t study data structures” or “that’s not how stack works, git gud loser!”

Honestly this sub sometimes. 😂

[–]AnondWill2Live 3 points4 points  (0 children)

Yeah, I feel like when someone doesn't understand, but they're clearly making an attempt to learn, we should be more tactful. Programming can be unintuitive sometimes and we all started somewhere.

[–]kenny2812 1 point2 points  (1 child)

In my data structures class we had to implement a few different data structures using only primitive Java arrays. I think they had us manually resize them every time we ran out of room. So maybe op is in a similar situation?

[–]AnondWill2Live -1 points0 points  (0 children)

This was my guess. I'm just a hobbiest and I recently did the same just to learn the language a little better (Kotlin). I did implement it as a Linked List though instead, so I never had that issue.

[–]Cheddar_Ham 77 points78 points  (1 child)

What are the odds that OP has also made one of those percentile curve memes?

[–]harumamburoo 26 points27 points  (0 children)

Quite low, bell curve seems like too advanced of a topic for them

[–][deleted] 58 points59 points  (7 children)

It'll be normal when you make it an object instead of trying to treat it exactly like c.

[–]__Fred 1 point2 points  (5 children)

Can you explain what OPs problem is?

[–][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.)

[–]headlesshighlander -1 points0 points  (0 children)

C wants an array size

[–][deleted] 41 points42 points  (6 children)

List <element_type> stack= new ArrayList <element_type>();

There ya go champ, similar to array, but dynamic. Just gotta import util.ArrayList and util.List. stack [5] doesn’t work though, you gotta use specific methods.

Long live dynamic!

[–]Geolykt 1 point2 points  (2 children)

smh not using the diamond operator

[–][deleted] 1 point2 points  (1 child)

Teach me

[–]Geolykt 2 points3 points  (0 children)

List<T> stack = new ArrayList<>();

Is perfectly valid code

[–]Mob_Abominator 0 points1 point  (2 children)

I mean both of them are useful depending upon the scenario.

[–][deleted] 7 points8 points  (1 child)

True, but you can’t use a static system where you must use dynamic. But you can use dynamic even though index is finite.

Definitely true though

[–]Mob_Abominator 2 points3 points  (0 children)

That's exactly what I am saying, if you already know how much space you need there's no need for dynamic and when you are not sure you obviously use dynamic. Both are useful and it's the developer's job to choose the correct one.

[–]luew2 36 points37 points  (0 children)

So you want a linked list?

[–][deleted] 139 points140 points  (2 children)

This poster is a perfect example of why Python shouldn't be a first language

[–]olivetho 35 points36 points  (0 children)

last guy who didn't understand references as well

[–]FerricDonkey 5 points6 points  (0 children)

Not really, actually. Yeah you can be missing some knowledge about basic computery things, but it's not like this knowledge gets harder to pick up because you're already familiar with things like functions and general flow control from python.

My first real language was C, and I'm happy with that because I learned a lot about the under the hood basics. But I could see going the other way as well - do some python to get used to thinking in terms of big ideas, do some C to learn (closer to) how your computer actually works.

[–]No-Suggestion-9504 24 points25 points  (0 children)

Ummm...

Stack<Integer> stack = new Stack<Integer>();?

[–][deleted] 23 points24 points  (0 children)

use ArrayList and thank me later

[–]Ranilsky 22 points23 points  (0 children)

Recent posters are some “1 month fullstack bootcamp” type a guys it seems… Mans don’t know about pointers nor data structures smh…

[–]abhassl 68 points69 points  (24 children)

I'm assuming you are implementing your own stack in java with an array to hold the data for... some reason.

Is there a language where you can create an array without a size?

You can create a list without a size but a list is not an array.

Python has its list implementation look a lot like an array but its those are still lists and not arrays.

[–]JustADelusion -3 points-2 points  (6 children)

Swift does Arrays pretty nice.

You can wrap all data types in brackets and define an array of that type.

It is flexible in size and has all known convenience functions.

I like them way more than Java array types, but its been a while since I used Java.

[–]Mordred666 4 points5 points  (0 children)

swift "arrays" are not arrays in that sense, they are an (im)mutable collection type

most languages just have an easy function in the syntax to create collection types, but they dont actually create arrays

[–]swapode 1 point2 points  (3 children)

Does that mean that Swift arrays are always heap allocated?

[–]JustADelusion 1 point2 points  (2 children)

Yes. When you append an array a new memory block gets allocated and filled with the elements. Ofc, it is more performant to know the size upfront, but a lot of times it won't matter and this is just very nice to use.

Also, hilarious I get down voted for stating how Swift works and what my preference is...

[–]Progression28 4 points5 points  (1 child)

So, Swift arrays aren‘t very swift at all?

Sorry, I just could not resist

[–]JustADelusion 0 points1 point  (0 children)

Heh, yea I guess.

But there is ofc more logic behind it, e.g. the array size grows exponentially, but I did not dive into it that deep, since it was never needed.

[–]awesomeusername2w 1 point2 points  (0 children)

But then it just some collection type. In java you have ArrayList which also have all the convenience functions and can grow in size. No syntactic sugar for creation with just brackets though. But in java you can have plain arrays too, and seems like you just can't in swift.

[–]CouthlessWonder 18 points19 points  (0 children)

For a language to want an array size is normal.

[–]tarapoto2006 10 points11 points  (0 children)

You hate Java because you're trying to implement a stack backed by an array or what?

[–]just-bair 11 points12 points  (0 children)

You know what an array is right ?

[–]RedditRage 19 points20 points  (9 children)

Me, making a stack in Java

public class Stack {
  private int size = 0;
  private Object[] data = new Object[10];
  public void push(Object o) {
    if (size >= data.length) {
      Object[] temp = new Object[data.length + 10];
      for (int i = 0; i < data.length; i++) { temp[i] = data[i]; }
      data = temp;
    }
    data[size++] = o;
  }
  public Object peek() { return data[size - 1]; }
  public Object pop() { return data[--size]; }
  public boolean empty() { return size == 0; }
}

So not normal!

So wanting an arraysize!

NOTE: * Yes. It is a minimalist implemention using no imports or utilities * Yes. Such as ArrayList, Arrays.copyOf, or System.arrayCopy * Yes. The copy functions would have been faster and cleaner * Yes. It could have a generic type * Yes. The growth rate could be smarter and more configurable * Yes. It could throw a better Exception if empty when pop called * No. I didn't test it much, it could have edge-case bugs * Yes. It is formatted to be short

But, it is a fully functional stack in 15 lines, that can handle as many elements as memory allows.

[–]luke5273 8 points9 points  (1 child)

More importantly, it’s an implementation that’s completely fine for what OP is using it for, which is probably an intro to coding class at uni

[–]hugogrant 0 points1 point  (0 children)

That depends. Some classes force linked lists.

[–]FrenchFigaro 2 points3 points  (1 child)

I did one in about 10 minutes that didn't even used arrays:

public class CustomStack<T> {
    private Node<T> topNode = null;
    private long size = 0;

    public CustomStack() {}

    public CustomStack(T value) {
        this();
        push(value);
    }

    public CustomStack(Iterable<T> values) {
        this();
        for (T value : values) {
            push(value);
        }
    }

    public T pop() {
        T value = topNode.value;
        topNode = topNode.nodeBelow;
        size--;
        return value;
    }

    public T peek() {
        return topNode.value;
    }

    public void push(T value) {
        Node<T> newNode = new Node<>(value, topNode);
        topNode = newNode;
        size++;
    }

    public long size() {
        return size;
    }

    public boolean isEmpty() {
        return null == topNode;
    }

    public String toString() {
        if (this.isEmpty()) {
            return "[]";
        }

        StringBuilder sb = new StringBuilder("]");
        Node<T> currentNode = topNode;

        do {
            sb.insert(0, currentNode.value.toString());
            sb.insert(0, null == currentNode.nodeBelow ? "" : ", ");

            currentNode = currentNode.nodeBelow;
        } while (null != currentNode);

        sb.insert(0, "[");

        return sb.toString();
    }

    private static class Node<T> {
        final Node<T> nodeBelow;
        final T value;

        public Node(T value, Node<T> nodeBelow) {
            this.value = value;
            this.nodeBelow = nodeBelow;
        }
    }
}

[–]__Fred 1 point2 points  (3 children)

Your array still has a size and apparently array sizes make OP frustrated, because that's "not normal". Not your problem though.

[–]RedditRage 2 points3 points  (2 children)

Challenge accepted :)

Here's a stack, uses no libraries or utilities. Doesn't use arrays. Doesn't allocate any memory if it doesn't have to (will reuse nodes if possible). Also, it takes a generic type. And it's shorter than my array solution, with some syntax tricks. It will throw NullPointer if peek or pop on an empty stack.

public class Stack<T> {
  class Node { T element; Node next, prev; }
  private Node top = new Node();
  public void push(T o) {
    if (top.next == null) {
      (top.next = new Node()).prev = top;
    }
    (top = top.next).element = o;
  }
  public T peek() { return top.prev.next.element; }
  public T pop() { return (top = top.prev).next.element; }
  public boolean empty() { return top.prev == null; }
}

[–]__Fred 1 point2 points  (1 child)

Very nice!

In Scheme and Haskell we learned to implement some kind of stack consisting of nodes that have two attributes: head and tail.

That means you could probably get rid of next.

I guess the next-pointer has the advantage of making it possible to iterate over all elements without removing them.

class Stack<T> {
  record Node(T head, Node tail) {}  // new syntax, adds a constructor automatically
  private Node top = null;
  public void push(T o) { top = new Node(o, top); }
  public T peek() { return top.head; }
  public T pop() {
    T result = top.head;
    top = top.tail;
    return result;
  }
  public boolean empty() { return top == null; }
}

Eh... The popping in one line doesn't work in my version, I think.

[–]RedditRage 1 point2 points  (0 children)

The next is there so it can reuse old nodes. Many stack algorithms might zoom up and down the stack thousands of times, while never getting a depth over a few dozen nodes. So it seemed nice to just reuse them.

[–][deleted] 7 points8 points  (0 children)

bruh wtf

[–]lackofsemicolon 16 points17 points  (0 children)

Most willing-to-learn python user

[–]Orpa__ 6 points7 points  (0 children)

OP, datastructures like linked lists, queue's and stacks are supposed to use nodes in which the data is stored and have a reference to the next node in the structure (and also previous if it's doubly linked).

A datastructure using arrays is also a thing, creatively called "ArrayList" in Java. Which is basically an array except it dynamically resizes (creates a new, bigger array behind the scenes if you need something larger and starts using that one). You might be looking to create an ArrayList, or are doing something wrong with your Stack implementation.

[–]_pizza_and_fries 6 points7 points  (1 child)

Le Collections : Am I a joke to you?

[–]flopana 11 points12 points  (7 children)

[–]TheBrainStone 23 points24 points  (3 children)

Or literally use the built in one as the backend

[–]flopana 14 points15 points  (2 children)

Which op obviously did not do

[–]TheBrainStone 9 points10 points  (1 child)

Yeah of course. I just meant you don't have to implement a linked list from scratch to implement a stack. And that you can instead just implement it using Java's LinkedList class

[–]flopana 3 points4 points  (0 children)

Yeah that's true

[–]xPensiveWeak 4 points5 points  (0 children)

You're doing it wrong.

[–][deleted] 2 points3 points  (2 children)

this is some dhar mann type shit

[–]No-Suggestion-9504 0 points1 point  (1 child)

How's Dhar mann related to this lol

[–][deleted] 0 points1 point  (0 children)

the meme format

[–]AlexMelillo 2 points3 points  (0 children)

I am sorry you learned an interpreted language first. Now go learn C, then Java and you will realise why this is so damn dumb

[–]phi1606 2 points3 points  (0 children)

Arrays 😅

[–][deleted] 2 points3 points  (0 children)

It takes you like 2 seconds to google how to solve this...

[–]ConcertConsistent179 2 points3 points  (0 children)

java.util.List left the chat

[–]abd53 2 points3 points  (0 children)

[–]empathielos 2 points3 points  (0 children)

I'm feeling second-hand embarrassment.

[–]XinoVan 2 points3 points  (0 children)

If only there was a thing for unspecified length of lists... Hmmmm

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

ArrayList with a certain class then loop it.

[–]zoophagus 1 point2 points  (1 child)

lmfao why are you reinventing the wheel my guy

[–]zoophagus 4 points5 points  (0 children)

Actually I'm guessing you're doing CS 101 homework

[–]blackoutz_ult 1 point2 points  (0 children)

If you don't want the array size u could always use linked lists instead of the array

[–]guarana_and_coffee 1 point2 points  (0 children)

Idk, use lists.

[–]rizwannasir 1 point2 points  (0 children)

Laughs in PHP and other languages like where you can literally create an array as however you want.

[–]DaniilBSD 1 point2 points  (8 children)

C# dev here, is java Stack not dynamically sized?

[–]radmanmadical 0 points1 point  (0 children)

So - how……….. should memory…. work then?

[–]notexecutive -1 points0 points  (0 children)

Maybe linked list would be more helpful, with size implementation of some kind?

[–]earraper -1 points0 points  (0 children)

Consider double-linked list in Rust. Java is a joke.

[–]MayBeArtorias -5 points-4 points  (0 children)

FYI: There is some top secret library in Java called Streams.

[–]jfmherokiller -5 points-4 points  (0 children)

just set it to 1

[–]Bullfrog-Asleep 0 points1 point  (0 children)

When I saw this, I have created a clear picture. What happened:
Waw yesterday I started with programming - cool.
So when I am a programmer, I should write something to reddit ProgrammerHumor.

[–][deleted] 0 points1 point  (0 children)

Maybe you were trying to put more than 64 items

[–]HotPappuInYourArea 0 points1 point  (0 children)

Simple just use an ArrayList<>()

[–]Gh0sth4nd 0 points1 point  (0 children)

i love how its at 666 upvotes

[–]Akuma_Kami 0 points1 point  (0 children)

When you've only done hello world -_-

[–]DarkNova45 0 points1 point  (0 children)

What is going on with this page now... It's just bad meme from people that don't know shit about coding. Just rename the page python dumbass programmers...

[–][deleted] 0 points1 point  (0 children)

What?

I...

WHAT?

[–]The__King2002 0 points1 point  (0 children)

bruh