I hate that I'm spending way more time figuring out my lead dev spaghetti code than actually coding. Again this is my first job as dev and first code base that I work with (almost entirely written by lead dev). A couple days ago I used polymorphism on a model and he's reaction was like "wow that's neat I should have used that here and there..." I guess I don't have to wonder why there's a lot of duplicated shit anymore.... It's hard too apply all the good practices I've learned on my online courses working this way.

  • 5
    Prefer composition over inheritance. Especially inheriting shit code 😝
  • 2
    My lead dev is the opposite, he uses inheritance and adds unneeded interfaces fucking everywhere. It seem he's unable to write code without splitting it into IThing, AbstractThing and ThingImpl.

    When I tell him inheritance isn't meant just for code reuse and control flow jumping up and down in the hierarchy is hard to follow he doesn't believe me. 🤦‍♂️

    Maybe we can put your and my lead devs and all the other idiot coders into their own company, so we can write good code without them messing it up? One can dream...
  • 2
    @VaderNT I know right? I believe there has to be a balance between readability and complexity. And not to add layers of complexity just because you can, I think many times is an overkill. I don’t mind having 3 lines instead of 1 if it’s more readable.
  • 0
    That's your job.after several years you will start feeling confident with spaghetti code and salad too..
  • 3
    @cyberpro4 spaghetti and salad is your job iff you're a cook.
  • 0
    What kind of monster serves salad with spaghetti? 😵
  • 0
    @SortOfTested what if I told you in Germany they have pasta salads?

    @VaderNT the interfaces are actually kinda good if well done... Of course depends on the project you are on, but if there is code re-use in different projects I assure you interfaces are a life saver
  • 0
    They have that in the southern US too, doesn't make it right 😝
  • 1
    @SortOfTested I forgot the key detail: they usually swim in mayo!

    Yeah it was more to horrify you rather than proving it is good :P
    I dislike them too cause... Well, if I am going for pasta it better be good, if I am going for salad I am avoiding carbs, soooo...
  • 1
    @piratefox I don't argue against interfaces in general. Yes they're good if used correctly. That's true for anything, including the "harmful" goto.

    In my case, we don't write a library. Just a bog-standard Java Spring REST backend. Interface definitions for its inside classes are noise. Java got rid of header files, now devs reinvent them. They say each class should have an interface because it "specifies the contract". That sounds really fancy, but thinking about it there's nothing actually there. Take this class:

    public class Point {
    public final int x, y;
    public Point(int x, int y) { ... }

    Does it have an interface without "implements IPoint"? Sure it does! The public members of a class form its interface. Public classes of a package form a package's interface. Public endpoints of a REST service form its interface.

    A separate API definition can be useful (e.g. a Swagger file). Similarly the duo "IThing+ThingImpl" can be. But most of the time I see it in code, YAGNI.
Add Comment