[PYTHON] Is "destructive method" a Ruby term?

Yesterday, I wrote an article "All the destructive methods that data scientists should know", and I got the following opinion from a friend. It was.

I'm a little worried, but "destructive method" and "non-destructive method" are not general programming but Ruby terms, and do not mean "method to change the receiver"? If you dare to call it by name, the replace method seems correct. (I can't find Japanese) https://discuss.pytorch.org/t/what-is-in-place-operation/16244 https://ja.wikipedia.org/wiki/In-place algorithm

Furthermore, for example, pandas also uses the argument name "inplace" (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.rename.html), so it is for data scientists. Then I was told that in place might be more familiar.

Certainly, most of the articles that come out as "destructive" are from Ruby. I was a little worried, so I looked up and compared the words "destructive" and "in-place" in documents in various languages.

For Python: in-place dominates

[Searched for documents](https://docs.python.org/ja/3.8/search.html?q=%E3%82%A4%E3%83%B3%E3%83%97%E3%83% AC% E3% 83% BC% E3% 82% B9 & check_keywords = yes & area = default) By the way, it seems that the word "in-place" is actually often used. For example, "[Programming FAQ](https://docs.python.org/ja/3.8/faq/programming.html?highlight=%E3%82%A4%E3%83%B3%E3%83%97%E3%" In "83% AC% E3% 83% BC% E3% 82% B9 # how-do-i-modify-a-string-in-place)", it is as follows.

How do I change a string to in-place? ¶

Strings are immutable, so you can't do that. In most cases, you should simply compose a new string from the individual parts you want to assemble.

On the other hand, the word "destructive" is also used to some extent. For example, the documentation for Python2.7 has the word "destructively". The latest version of the document says "Erase and return", but only the Japanese translation has changed.

Just as used in set algorithms, popitem () is useful for destructively iterating dictionaries. If the dictionary is empty, the call to popitem () will throw KeyError.

Even in Python 3.8, "curses --- Terminal operation for handling character cell display" contains "Non-destructive (non-destructive) The word "non-destructive)" was found.

Overlay the window over destwin. The windows do not have to be the same size, only the overlapping areas are duplicated. This copy is non-destructive.

There is also "destructive" at a distance.

Overwrite the contents of the window over destwin. The windows do not have to be the same size, only the overlapping areas are duplicated. This copy is destructive.

For Ruby: The term destructive method is explained

In the Official Ruby FAQ, there was an item "What is a destructive method?". No translation was found for the Japanese version.

The plain version creates a copy of the receiver, makes its change to it, and returns the copy. The “bang” version (with the !) modifies the receiver in place.

The word "in place" is also used in the description.

I didn't hit much in the documentation, so I'll take a look at Rubima. After all, the word "destructive" is often used. For example, from "Ruby Code Impressions [2nd] WikiR".

force_encoding is a destructive method, although it's hard to tell by name alone because it doesn't have a! Therefore, there is no need to assign the return value to text. This is enough.

In some places, the word in-place was used in the "June 10th morning session".

Grammatically, yield got in the way when yield came in first and introduced later arguments with blocks. Also, I don't mutate in-place with String, but it's not good to be messed up. I regret 98% of the built-in variables I got from Perl.

For PHP: Both are used together

It seems that both the words "in-place" and "destructive" are used. It seems that the translation of these parts into Japanese has not been done yet?

From "Ds \ Sequence :: sort"

Sorts the sequence in-place, using an optional comparator function.

From Ds \ PriorityQueue :: toArray.

Note:

This method is not destructive.

Other languages

I also wanted to look at Smalltalk, which influenced Ruby, but it wasn't clear. However, if you look at the documentation for Smalltalk-72, the word non-destructive is at least one. It was used in places.

Note that you can make non-destructive text by using xor ink which complements the background so that reshowing the text crases it while restoring what was underneath.

I also looked at Haskell, which basically has immutable variables, but found only those whose destructive was used to mean "an update to a language specification that was incompatible in the past". I gave up because reading itself seemed to be a pain for me now.

Also, in Ruby, it is used close to the proper noun "destructive method", while destructive in other languages seems to be used as a general adjective. Perhaps the term "destructive method" is a term that began to be used in the Ruby community, but was recognized and spread as a programming term in Japanese. I will check it again if I have a chance.

Recommended Posts

Is "destructive method" a Ruby term?
What is a distribution?
What is a terminal?
What is a hacker?
What is a pointer?
Is this string a decimal?
Is this a system trade?
What is a decision tree?
Python list is not a list
What is a Context Switch?
What is a system call
[Definition] What is a framework?
This is a webiopi question
What is a callback function?
Profile within a class method
The image is a slug
What is a python map?