0
if flask.request.form['token'] == stored_token:
    if size_of_file > 10000:
        logging.info('data ' + filename + ' is compressed and sent')
        return gzip_compress(resp(200, data))
    else:
        logging.info(filename + ' data copy')
        return resp(200, data)
else:
    logging.info(' data ' + filename + ' is not compressed, but copied and sent')
    return resp(401, {})

I do not like how this code looks to help fix it. Or tell me that this is a good code.

3
  • 1
    you think does not mean it is bad. This is just a nested if statement. who said it is bad?? Commented Sep 24, 2018 at 7:06
  • If you have questions about the quality of code, consider posting your question the code review forum. Commented Sep 24, 2018 at 7:07
  • Anyway I do not see any problem with this code... Commented Sep 24, 2018 at 7:10

1 Answer 1

3

Here you go:

if flask.request.form['token'] != stored_token:
    logging.info(' data ' + filename + ' is not compressed, but copied and sent')
    return resp(401, {})

if size_of_file <= 10000:
    logging.info(filename + ' data copy')
    return resp(200, data)

logging.info('data ' + filename + ' is compressed and sent')
return gzip_compress(resp(200, data))

In google testing blog there is an article describing why nested if statements are considered bad and how can you reduce your code complexity.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.