19

Classes are not namespaces!!

Comments
  • 1
    And this bothers you how?
  • 2
    @BigBoo
    It bothers me that some people use them as if they were namespaces. And then implement singleton patterns or write one class for an entire set of responibilities.
  • 0
    @simulate Reject their pull requests? Or, what am I missing. Who is doing this and how does it impact you?

    Or are you just bothered that some people do things differently than you?

    See, I still don't have any context to if there is a story here or you are just irritated by some code that someone wrote somewhere.
  • 2
    @2lazy2debug
    well i cant post the entire class, but we have a class in our project which does just EVERYTHING regarding the functionality an entire namespace is supposed to represent.

    The class provides interfaces to talk with 10 other modules, connects to a server using tcp, has helpers to quickly do some stuff directly which is actually part of what other classes should do, ... heck i dont even know what else it does! The header file is 700 lines long, eg ~500 functions and variables, in ONE CLASS... I am saying that because I feel like people sometimes treat classes as if they were namespaces (why else would the singleton pattern exist?) while a class should really only be a template for one worker with one job. managers should usually just be a namespace.
  • 1
    @2lazy2debug
    I had too and said so in teamchat and all the devs basically started laughing tears as if to say "good luck pal". I have now dedicated myself to at least break off the part of it that is involved in my ticket, and I hope i dont run into spaghetti...
  • 1
    @simulate Good luck! The world always needs the brave few who are willing to charge into apparent lost causes. Hopefully you survive the experience.
  • 1
    That's a nice class you got going 😂😂😂
    I know that Python's pylint linter warns on such abundances (whrn method can be a function i.e.), so maybe there's a similar type of tool for your lang that you could enforce in your CI?
  • 0
    In ES5 they actually are..there is no other way to namespace your code other than:

    Namespace = {};
    Namespace.SomeObject = {};
    or
    NamespaceSomeObject = {};

    Still better than having naming collisions I guess..
  • 0
    @psukys
    I am already sure that it would mark a lot of possible improvements... 😂😂
    Nah, all that would help there is to rewrite the class. But of course my boss doesnt want to "waste time on things that dont directly help the customer", although I would bet that many of our bug reports are related with that class, because it is so central (actually, it is one entire tool in the toolchain of our main product), but who cares.
Add Comment