I've been writing Python for a little over a year because of various reasons. (Not WEB system)
Let's list some of the advantages and pains of Python that I have come to see (Sabori). It's a memo for myself, so it's a good idea ... Please point out.
To Google Sensei, please stop posting this article at the top of the search results as it only pollutes the search. I will do anything (I'm not saying anything).
TL;DR
Python has a lot of painful specifications (for me).
However, even if we accept the disadvantages, there are advantages that we would like to use, so I think we have no choice but to continue using Python ....
As you know, Python indentation makes sense. The block is composed of indentation.
In other words, this
if True:
print("hoge")
else:
print("piyo")
print("fuga")
# =>hoge and fuga are displayed
And this
if True:
print("hoge")
else:
print("piyo")
print("fuga")
# =>hoge is displayed
The displayed contents are different.
……I know. I know that it is taken for granted. But think about it. this
if xxx:
lorem
if yyy:
ipsum
dolar
else:
sit
And this
if xxx:
lorem
if yyy:
ipsum
dolar
else:
sit
The only difference is indentation, and if you use an automatic indentation function such as Emacs, the structure changes depending on the editor. Does anyone think this is rather painful?
what? Are you all writing the correct code in one shot? I can't do that. I write a function in a certain amount, but this is a class, right? You can indent the whole thing After that, various internal indents are corrected. Of course, if you just want to relocate, you only need to add the required number of spaces at the beginning of the line, so it is possible. However, if it is C etc., one unnecessary process is sandwiched and thinking stops. I think it's a ridiculous disadvantage.
Apart from that, I'm not always trying to force you to enclose it in curly braces, but it could be done as an option.
In Python, imports are often arranged at the beginning of a line, but the search path at this time is difficult.
Since there is no default structure for the project (well, it's a scripting language, this can't be helped), it may be difficult to decide. However, it is NG that the search path changes depending on how it is called.
After all, for peace of mind, it is necessary to edit sys.path and add under the current directory.
This is my responsibility, but every time I forget about this task and search for how to imoprt.
Python has maps and filters derived from functional languages. It is adaptable to classes that implement iterable and works as the name implies.
lst: list = [1, 2, 3, 4, 5, 6]
lst2 = list(map(lambda x: x*2, lst))
lst3 = list(filter(lambda x: x % 2 == 0, lst))
print(lst2) # => [2, 4, 6, 8, 10, 12]
print(lst3) # => [2, 4, 6]
Did you notice? I purposely convert the output such as map to list.
Well, this isn't painful, but it feels subtle.
After all, the only condition is that lambda x: iterable-> iterable
, so it is the output type of the map that is iterable, so it is unavoidable that conversion is necessary.
However, in reality, it has a convenient function called comprehension. Same thing as above
lst: list = [1, 2, 3, 4, 5, 6]
lst2 = [x * 2 for x in lst]
lst3 = [x for x in lst if x % 2 == 0]
print(lst2) # => [2, 4, 6, 8, 10, 12]
print(lst3) # => [2, 4, 6]
Can be written.
It seems that Python is not used by cutting the virtual environment for each project. Therefore, I use Pyenv to switch versions, and pipenv to switch libraries for each environment.
The problem is that if you do this, the disk will be eaten more and more, such as having a library for each virtual environment.
I use M.2 SSD with priority on speed, and even if it is cheap, it is sober in an environment of about 250GB.
Regarding this, it is not a problem for those who are always withdrawn in the environment such as Anaconda and Miniconda and Jupyter.
Find out what you want to do-> There are many patterns where you can find a library. To be honest, I think most things have a library.
Since I live in a natural language system, I sometimes use MeCab, Human ++, etc., but since there are wrappers for them, It can be used as a Python object without thinking about anything. Convenient.
If it's a morphological analyzer, you can still implement it yourself, but it's very helpful because you don't want to use a wrapper for a parser such as KNP.
Also, is there a demand for full-width and half-width conversion? It also corresponds to that, so I can solve it by calling various libraries made by my predecessors.
The machine learning library is particularly rich, so if you want to do it, Python is a good idea.
Numpy,Pandas
A library that can be a reason to use Python by itself. Matrix operation is too strong ... It's too easy to graph ...
Since it can be executed in a virtual environment, you do not have to worry about the version of Glibc when you run the created program. good. good.
I'm using Arch Linux personally now, so it's even better.
I've complained a lot above, but in the end the benefits are so big that we can't leave Python. I think if Numpy is also in other languages ... but I don't feel like Ruby or Perl, so Python is also a good candidate for a convenient scripting language.
I wonder if there is no choice but to use it while solving the problems solved by design ...
-Advantages and disadvantages of Python that I felt after using it
Recommended Posts