[PYTHON] Good and bad code to compare on a minimap

I compared the good code (refactored or rewritten code) with the bad code (original code) on a minimap.

environment

--Source is Python 2.7 --Display minimap with PyCharm's CodeGlance plugin --Color theme: Darcula --The minimap is 110 digits wide and the height of one line is 1 pixel and 3 pixels

Mini map

Which is better code, A or B, and which is worse?

Displayed in 1 pixel per line

minimap_1.png

Displayed in 3 pixels per line

A minimap_3_old.png

B minimap_3_new.png

Comparison

Total amount of characters

A is the impression that the letters are packed tightly as a whole. This is because there are few blank lines and the number of characters in one line is large.

B has a neat impression because it contains a moderate amount of blank lines.

Left side of the code

A has a lot of blank space on the left side and unevenness is conspicuous. This is because the nesting of for and if is deep, and there are many places where processing is written in a sloppy manner.

B has a shallow nest and the left side is flat overall.

Right side of the code

A has many characters on the right side, and lines with characters all the way to the right end stand out. This is because there are many places where calls to functions with many arguments are written on one line without line breaks.

In B, long lines are properly line-breaked, so whitespace is noticeable on the right side.

Amount of string literals

The color of ■■■ </ font> represents a string literal, which is very common in A. This is because we use dict to store data.

Since B uses classes to store data, it has fewer string literals.

What I found

--Good code is beautiful even if you look at the minimap --Bad code is oozing dirty even if you look at the minimap

Recommended Posts

Good and bad code to compare on a minimap
Good and bad code to compare on a minimap
Python 3.6 on Windows ... and to Xamarin.
Make a chatbot and practice to be popular.
Character code
Write python-like code
FFT pseudo code
VS Code settings
python character code
[Python] Algorithm-aware code
QR code display
Zip code geocoding
PyCharm code interpolation
Good and bad code to compare on a minimap
Steps to attach and debug from VS Code to Jupyter Lab on a remote server
Python 3.6 on Windows ... and to Xamarin.
Code to randomly generate a score
Simple code to call a python program from Javascript on EC2
Scraping and tabelog ~ I want to find a good restaurant! ~ (Work)
A story about trying to run JavaScripthon on Windows and giving up.
Steps to create a Python virtual environment with VS Code on Windows
[Python] Create a linebot to write a name and age on an image
Try to write python code to generate go code --Try porting JSON-to-Go and so on
I want to format and check Python code to my liking on VS Code
Build Linux on a Windows environment. Steps to install Laradock and migrate
How to split and save a DataFrame
Qiita (1) How to write a code name
A memo with Python2.7 and Python3 on CentOS
Run Python code on A2019 Community Edition
How to test on a Django-authenticated page
A story about trying to install uwsgi on an EC2 instance and failing
I want to drop a file on tkinter and get its path [Tkinter DnD2]
How to run a Django application on a Docker container (development and production environment)
Build a PYNQ environment on Ultra96 V2 and log in to Jupyter Notebook
On Linux (Ubuntu), tune the Trackpad and set the function to a three-finger swipe
A tool to insert the country name and country code in the IP address part
How to code a drone using image recognition
Is there a good sample code for nosetests?
Try using a QR code on a Raspberry Pi
Use boto3-stubs to enable code completion on boto3
Make a chatbot and practice to be popular.
Try to create a new command on linux
How to live a decent life on 2017 Windows
List of Python code to move and remember
[Rails] How to display multiple markers on Google Map and display a balloon when clicked
How to build a beautiful Python environment on a new Mac and install Jupter Notebook
How to create a Python 3.6.0 environment by putting pyenv on Amazon Linux and Ubuntu
Try running a Schedule to start and stop an instance on AWS Lambda (Python)
From installing Flask on CentOS to making it a service with Nginx and uWSGI
Memo A beginner tried to build a Java environment and Japaneseize it on Ubuntu 18.04.2 LTS.
How to build a Python virtual execution environment using Visual Studio Code and pipenv on a Windows machine (also Jupyter notebook)