I recently had to deal with debugging chatgpt code, and though it was written clearly, it just seemed so ugly and hard to read to me. So I started to think about what I like and what I don't like when reading code. My personal guidelines for beautiful code are:

  • space out code into functionally similar chunks. That way it's easy for my eyes to separate the steps of the code. (Often this is code that is only used once, so there is no need to put it in it's own function)
  • comments are for clarity, and too many make clarity worse.
  • similarly, doc comments in 2024 need to be completely rethought. I already have the actual documentation open on my screen most likely, no need to put the same information in your code. (yes, I know that java and others generate documentation from doc comments, and I don't like it)
  • functions should be ordered by order of execution. Reading down the code should be like reading a book, telling the story of the code's execution. For an OOP language this should pretty well line up with layers of abstraction as well.
  • python should be wiped from the face of the earth.
  • self-documenting code (which is to say code with very long variable names) is bad practice. Once again, the code should be able to be read like a book, you wouldn't name the protagonist of Lord of the Rings 'Ring_barer_to_mordor_hobbit' just name variables something memorable and useful and move on.
  • of course, the opposite, variables just named something meaningless like 'a' should only be used in the most limited of scopes. Loops, lambda functions, etc.
  • There should be consideration for how the code flows on the screen
  • curly brackets in C-like languages should always have their own line, with the exception of the start of functions and short if/else statements.

I don't know, these are just things that I have noticed I like to see in code. This could be the ravings of a lunatic as well.

spoiler

a tab is 2 spaces

  • KnilAdlez [none/use name]
    hexagon
    ·
    edit-2
    5 days ago

    I have absolutely written code that looks like

    if () {

    } else {

    }

    So maybe my judgement on curly brackets shouldn't be trusted

    • Flyberius [comrade/them]
      ·
      5 days ago

      That is how I like to do it. Otherwise everything just takes up to much vertical height and I get sad