A
A
arver2018-10-09 12:18:16
Programming
arver, 2018-10-09 12:18:16

What does flat code mean?

Everywhere they write flat asynchronous code or written in a flat way. What does flat code mean?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Afanasy Zakharov, 2018-10-09
@arver

Code that is written and read as if it were not asynchronous at all (all calls are one after the other).
js example

const parseAdminsData = async ()=>{
  const token = await getToken();
  const users = await getUsers(token);
  const admins = users.filter(({isAdmin})=>isAdmin);
  return admins;
}

here are two asynchronous requests, but in the code they just look like function calls. (no callbacks)

A
Artyom Innokentiev, 2018-10-09
@artinnok

nested code (nested):

for a in range(10):
    for b in range(20):
        for c in range(30):
            for d in range(40):
                if d == 1:
                    if c == 1:
                        if b == 1:
                             if a == 1:
                                  print('nested code')

flat code (flat):
for a in range(10):
    print('flat code')

it is clear that the nested code is read very badly - therefore, you should try to write flat code, this will save you time in a few months and the other person who will read the code.
in addition, nested code is slower than flat code and is more likely to be reduced to flat code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question