Are there any basic standards and methods for creating human readable code?

More specifically, is reading HTML, Java and python more readable? Anyone have any suggestions for this programming student?

+6
java python html human-readable
source share
9 answers
  • Use consistent casing and naming.

  • Use tabs (and brackets, if any) to provide visual flow.

  • Use comments that explain what happens both conceptually and technically. (e.g. // Do we have a valid user? no // Check that user_ID is not -1)

I'm sure some more experienced developers will have more suggestions, but these are my top 3.

+5
source share

Make sure your code is well-structured (right indentation, blank lines for separating code sections, etc.) and use standard, consistent, and fully named (not obscure abbreviated) variable names.

Others would suggest using the correct comments. I would not agree. If your code is well structured and the variables are well named, comments will just get in the way. The exception to the rule is that you must do something contrary to intuition in order to circumvent the error somewhere else (I had to resort to this in WCF and Entity Framework code in the past).

+5
source share

Correct indentation and noteworthy comments.

+5
source share

Use indentation, comments, and coding conventions (to test Python PEP8 )

+5
source share

Try reading your code out loud (or at least in your head).

+3
source share

Take a look at this book: Clean Code: A Guide to Agile Software Skill . The thing is to make the code understandable and understandable.

+3
source share

One tip is not to be lazy with names. For example, if you have a Java class that implements the Transformer interface, and it converts String to Date , feel free to call the StringToDateTransformerImpl class.

+2
source share

Well, you can always use the "ignorant test." Show your code to someone who knows nothing about programming. If he can see more or less what the function does, the code is probably readable.

+2
source share

Correct indentation when writing HTML can be a lifesaver, especially when you interact with any nested elements. Just accept indentation and be sure to update the surrounding lines when you move or delete an indented element. This makes page refreshing much easier, since the indentation level will give an idea of ​​where you are on the page without resorting to some kind of Ctrl + F maneuver.

It's also worth noting that if you use CSS in conjunction with HTML, proper naming is crucial! This will improve your workflow and the readability of your code.

I am also a big fan of indentation, spacing, and commenting when writing "real" code (Java, Python, C, etc.). I lean towards (x + 1) over (x + 1), because I personally believe that this is of great importance in readability. I highlight throws, increments, etc., and they catch my eye much easier. Be consistent with your indentation / indentation style and comment liberally - remember that rewriting a method name is not a comment!

+1
source share

All Articles