Real sugar syntax in Python?

Andrés Gutiérrez
1 min readSep 19, 2021

--

The idea of sugar syntax is to provide an easier way to read and write code, but at some point, we lost the purpose.

In Python is easier to code using fancy methods to simplify our logic in one line or one instruction but we compromised the readability of our code. Remember, we are not alone, we usually work in teams and it is important to keep that in mind and avoid any complexity for the next person is going to read and modify our code.

Here you can find an example in which we want to filter from a payload all laptops with Ryzen processor and 16GB of memory.

NOTE: We are not taking into consideration performance (Big O notation)

Giving this .json as input

  1. Sugar syntax, readability compromised

An alternative

2. Not Sugar syntax, but readable

All codes above do the same, they search in payload what we need, but each code has different ways to read, probably, there are some people that doesnt understand the first two, but last one.

All in life are decisions, we can write short lines of code, but sacrificing readability, or we can increase the lines and ensuring readability for the rest of the team.

Is your call, choose what is better for you and your team.

End.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Andrés Gutiérrez
Andrés Gutiérrez

Written by Andrés Gutiérrez

Software developer, Pythonista, bug-resolver.I'm currently working in backend and frontend tasks. First steps in DevOps

No responses yet

Write a response