8

What would be the best tips for keeping code clean?

I recently noticed how "unclean" my code is, I try to organize it as much as possible but through that I manage to make the code very messy :/
What are your best tips, advise, tricks... lalala?

Note:
This problem mainly applies to long projects and games :P

Comments
  • 9
    My advice would be: try to break down things into tiny functions where those functions actually do something, you know you have done it right when you can name them appropriatly becuse you would know what it's doing regardless of how big or tiny they might be.
  • 10
    Just don't write code at all, keeps it clean :)

    I try to follow SOLID principles
  • 3
    @desirous okay sounds pretty clean, cheers!
  • 2
    @alexbrooklyn what do you mean by solid principles
  • 4
    @hamolicious Single responsibility, Open-closed principle, Liskov substitution principle, Interface segragation and Dependency inversion
  • 5
    @hamolicious https://www.wikiwand.com/en/SOLID

    Ooohhh boy, there's soo much you should know about clean code.

    Here's a very brief summary:
    https://medium.com/mindorks/...

    But you should really have look at https://amazon.com/Clean-Code-Handb...
  • 5
    forget SOLID and clean code, it’s for java devs who can’t code shit without a pattern.

    the advice of @desirous is good 👍🏻
  • 3
    @alexbrooklyn i got fired, now what
  • 4
    @351483773 not really java specific, plus a pattern approach makes it easier for a large team to maintain things as everyone has the same ideology for creating maintainable code.

    This might be of use to you @hamolicious

    https://williamdurand.fr/2013/07/...
  • 4
    @351483773 I suggest to first get familiar with clean code paradigms before making statements like that.

    The "breaking down into small functions" is talked about in [if my memory serves] the 4th chapter of R.C.Martin's "clean code". It's classified as the very fundamentals :)

    and no, it is not only applied to java. It should be applied to all the languages, to some extent incl. asm.

    P.S. @desirous is talking about S in Solid.
  • 1
    I find many problems because of bad file organization. Wether you code in java with packages or just plain files in e.g. pyhthon.
    If your files aren't organized well you will eventually put code into the wrong classes/files because "there is no good place"

    Best way I found is organizing your files/packages whatever by the features and inside those by layers like controllers, ui, ...

    This helps extremely to identify where to put a new class or if a method used by more than one object should be put in a package/folder above both.
Add Comment