[PYTHON] Reasons to think that the Greek letters of formulas should be used as variable names as they are

Earlier, I showed you how to enter Greek letters in Jupyter Notebook. How to easily enter Greek letters in Jupyter Notebook --Qiita

At that time, I happened to discover it and thought that it had a strange function, so I wrote an article for the time being, but I realized that it was unexpectedly convenient because I often write mathematical formulas in programs. Rather, I have come to think that small programs should be actively used.

Benefits of using Greek letters

1. It looks the same as the formula.

Since the program is almost the same as the mathematical formula, it is easy to understand the correspondence with the mathematical formula. I think it is necessary to specify the corresponding formula and the referenced material as comments.

2. The variable name becomes shorter.

Neither ʻalpha nor α` knows the meaning of variables by themselves. If you don't understand, the shorter the better, the easier it is to read the source code.

3. Helps you remember LaTeX input.

In the development environment listed below, the input method is LaTeX matched. You can use LaTeX with both Jupyter Notebook and Qiita, so it's worth remembering. Qiita Formula Cheat Sheet-Qiita

Disadvantages of using Greek letters

1. Problems may occur due to the character code

I don't know what problems can occur. If the programming language supports Unicode, I don't think there will be any problems with the program itself, but it is possible that problems will occur with libraries and peripheral tools. Also, be aware that the default character code for Windows is Shift-JIS. If you're not sure, it's best not to use Greek letters on Windows.

2. More keys to type

There is a slight increase in keystrokes than typing the alphabet. You need a backslash and a Tab key in addition to the alphabet. Since the completion is effective, key input may be reduced.

3. You may have trouble editing

When someone other than yourself edits, it is possible that you may be in trouble because you do not know how to enter characters.

Development environment where Greek letters can be used

--Programming language: - Python 3 - Julia

The input method is the same as the method described in the previous article. Enter the backslash followed by the alphabet and press the Tab key. Example: \ alpha + Tab → α

Prerequisites for using Greek letters

1. The programming language supports Unicode.

Of course, it doesn't matter if the programming language doesn't support Unicode. If it doesn't support Unicode, give it up.

2. There is a quick way to enter Greek letters.

It's really troublesome to input Japanese and convert it one by one. Use a development environment that has features that support input.

3. The program is small.

To avoid unexpected glitches, you should start with disposable or smaller programs.

Recommended Posts

Reasons to think that the Greek letters of formulas should be used as variable names as they are
I tried to summarize the operations that are likely to be used with numpy-stl
Heroku deployment of the first Django app that beginners are addicted to
[Python] A program that calculates the number of socks to be paired