DEV Community

Carlos Galarza
Carlos Galarza

Posted on • Edited on

2 1

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.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

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.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs