DEV Community

Carlos Galarza
Carlos Galarza

Posted on • Edited on

How to write accessible code?

accesible code image

  1. Group code blocks in a logical way:

    • Keep your variables close to where they are used.
  2. Use short names:

    • Naming a variable “a” or “b” is fine.
    • But … I lose context, right? … DO NOT! If you respect rule 1, there is no problem, you will reduce the redundancy and the cognitive load of your code.
  3. Use names that speak for themselves:

    • Nothing of “mVal”, “tRows”, etc …
  4. Use the new lines intentionally:

    • In the same way that you divide a text into paragraphs, make the new lines in your code communicate something.

If you want to expand this information I recommend this video, it is based on Go but it applies to other languages as well ->
⚡️⚡️⚡️

Do you wanna know more about this topic and other interesting tech topics?

Follow me on Twitter: https://twitter.com/carloslfu

Thanks! and happy learning.

Top comments (1)

Collapse
 
craigmc08 profile image
Craig McIlwrath

That first rule is so important. Trying to read a part of a long function (a problem in itself) but ALL of the variables are declared at the beginning of the function. Then you have to read a line, scroll up to figure out the variables, then scroll back down and find your place.

Exhausting.