When I started programming in Java, I was taught to always use the API and not reinvent the wheel by writing an own implementation of an already existent concept in it. The general way of programming I learned was, if I need something:
- Check whether it's in the standard API. If so, use that.
- If only a part of it is implemented, extend that class.
- If nothing like that exists, write an own implementation.
Now I get the point of improving readability and that it's easier to understand a class when it's uses only the standard API's concepts. Though, for the 2nd case, eventually, it became really hard to stick to that because classes in Java usually have a lot of general or extra functionality and I don't even need most of it for my purposes..
This has driven me to a point at which I am too tired of programming because, to me, it looks like I'm wasting most of my time trying to guess whats the best way to reimplement the methods of the class I'm extending in a way that
- fits to my needs for this "extension",
- sticks to it's rules defined by the standard API and
- works out with it
and in the end have a class I'm only using two methods of.
So my question is if it's really that bad to not always use the standard ways and to sometimes reinvent the wheel that way. I'm probably making a big thing out of nothing here but, over time, this really became a big thing for me and limits me in my possibilities. I'm a real nit-picker when it comes to programming..
I hope I'm not the only one experiencing that.
EDIT: Okay I see I will have to give an example.
I'm the type of person worried about memory usage when storing integers in a HashSet. So I'm creating a new class IntSet.java
extending AbstractSet and trying to make it work with primitive ints. Now I have no access to it's underlying variables. So I can't actually do anything without defining new variables that would allocate more memory than I'm trying to safe with the class, meaning I have to write an own implementation of it which would then "reinvent the wheel".
Another example: IntBuffers. What if I need everything an IntBuffer offers (like a mark, a position and a limit) on an array but want to combine it with growing and shrinking functionality. I would then have to rewrite the whole class because the constructors of it are private.