Home >Backend Development >PHP Tutorial >Why Is a String Called a String?
Core points
This is the editorial for the July 25 edition of the SitePoint PHP newsletter.
Why is a string called a string? Have you ever thought about this question? Apart from programming, we have never used such a word in other contexts to represent a set of letters glued together, however—in programming, it is as common as the word “variable.” Why is this, where does it come from?
To figure it out, we must first solve some related terms. History class time!
Wordfont (font) comes from French font——the melted thing; casting. Given that the letters of the press are indeed made of metal and melted at the Lead Foundry, this makes sense.
The terms uppercase (uppercase) and lowercase (lowercase) refer to the literal part of the font box used for font transportation. Therefore, the printer (man) has a heavy font box that he carries with him or sets on a press, in which there are two "levels" - one uppercase letter box and one lowercase letter box. The capital letter box only contains — you guessed it right — capital letters, while the lowercase letter box only contains lowercase letters.
You will notice that there are more lowercase letters than uppercase letters. This is expected – a letter can only be used once on a page, after all, there are much more lowercase letters in written text than uppercase letters, as there were no Youtube comments and case locks at that time.
So what does all this have to do with strings?
Well, as printing becomes more mainstream, presses are starting to provide services to individuals, not just newspapers and publishers, who are said to decide to charge based on the length of the printed material (in feet). Of course, many are speculative, but if they string the printed materials produced together, they can easily estimate the cost and charge the customer. Therefore, we can conclude with fair certainty that they use the word string (string) to represent a sequence of characters in this case. July 26, 2017 Edit: As pointed out in the comments below, it does seem that there is an actual rope for bundling the character blocks together, as they are shipped to the press after assembly! A Twitter fan even sent me the following video demonstrating the process!
Nevertheless, what does this have to do with the field of programming? I mean, you can say a string about anything
anything What if we look at the academic community’s records of the first reference? In the 1944 "Recursive Enumerable Positive Integer Sets and Its Decision Problems", we mentioned something that might be roughly similar to modern definitions:
For the purpose of working, we introduce letter 6 and consider "strings" 1 and b, such as 11b1bb1.
Then, 14 years later, in 1958's "A Programming Language for Mechanical Translation", the word was used in this way, and only once:
Each continuation string between punctuation marks or spaces is looked up in the dictionary.
Okay, a little bit like our concept of strings, but it looks like he's just describing, um,
word
. Obviously, this doesn't apply – it's too general. However, for some reason, it seems to have become popular.(String) is used exactly the same way we are today, although there is noIn 1958's "A Command Language for Handling Symbol Strings", the word
string
definition 🎜>For this. We found another reference in the 1959 "COMIT System for Mechanical Translation": If we want to replace D SIN(F) with COS(F) D (F), where F is not limited and can be any arbitrary component sequence, we use the symbol $ to represent this string. Funny! This is the dollar sign we all know from PHP, it is actually a string sign in BASIC. Also in 1959, we obtained a more direct definition in "Share 709 System: Machine Implementation of Symbol Programming": Text is a linearly sorted bit string that represents other information needed during loading and listing. In fact, it was through the April 1960 ALGOL that strings seem to take their modern abbreviation form "string" (before this, people said string of [something]). See the abstract of this paper. Then, in May 1960, the Report on Algorithm Language ALGOL 60 mentioned it in a form that touches the core content. Since then, it has spread as quickly as modern memes. 1963's METEOR: A LISP Interpreter for String Conversion uses a rather unspecific "[...] But the simple conversion of some linear lists (strings) is very good in this symbol Difficult to define." The 1964 "On Declaration of the Arbitrary Encoding Alphabet" mentioned "character string". Search ACM shows many other resources from the 1960s and beyond, all of which now use the term regularly, so the 1960s seem to be the catalyst for the evolution of this term and make it what it is today, slowly, through Its system needs. Interestingly, it ultimately represents a similar concept to the typography era—a set of characters with meaning and brings some cost (just this time in memory). As a side note - consider all these papers from more than 60 years ago. Sixty years ago, they used perforated cards to solve computer science problems and wrote about them in their academic papers. And we are now 2017, with the 2017 JavaScript framework, arguing about who can have sex with whom in Drupal's community and trying to redefine the word Facade over and over again. When we argue about the rocket science of modern web-developed “things go into boxes, things come out of boxes”, those people shape the entire world by transforming the analog environment they are in to digital, by essentially cheating on a small squeezing of sand Remember the numbers. Conclusion So now we know—or at least think we know—string (string) comes from. Computer science has always been a dark space full of mystery and slow evolution, just as we now know that the human eye has half-stage and half-eye in its past, and terms in computer science have also transcended and evolved around its original meaning until they gave What we have today. The same concept of the same name was born in various places at the same time in the 1960s until it evolved into a unified term that we all understood and used, and most importantly, we all agreed. When you think about it carefully, can we use a better word? While strings (strings) almost feel unnatural due to a complete disconnect from similar terms in the "real world" (we won't call the text on the page "strings"), I can't think of anything more suitable for this popular data Type of terms. Can you? tell me. FAQ for Strings in Computer Programming The word "string" in computer science is believed to originate from the phrase "character string". It was first used in programming when data was often represented as a sequence or "string" of alphanumeric characters. This term is used to describe the data types as character sequences in programming languages, and it has been used to this day. Stands are sequences of characters that can include letters, numbers, and special characters. Unlike other data types such as integers or booleans (representing numerical or true/false values, respectively), strings are used to represent and manipulate text. They are basic data types in almost all programming languages, and they come with a variety of built-in methods for operation and analysis. In some programming languages such as Java and Python, strings are immutable. This means that once a string is created, it cannot be changed. This design choice is mainly for efficiency and safety reasons. Since strings are often used in large quantities in programs, making them immutable can enable the system to optimize memory usage and processing speed. It also prevents potential security risks associated with mutable strings. Stands are usually stored in memory, as a character sequence, each character takes up a certain number of bytes, depending on the character encoding used. For example, in ASCII encoding, each character occupies one byte of memory, while in Unicode encoding, a character can occupy two or more bytes. The end of a string is usually marked with special empty characters. Many operations can be performed on strings, including concatenation (concatenation of two strings together), substring extraction (get part of a string), string comparison (checking whether two strings are equal), and characters String search (find a specific character or substring in a string). These operations are usually provided as built-in methods in programming languages. Most programming languages provide functions or methods to convert strings to other data types. For example, in Python, you can use the int() function to convert a numeric string to an integer, or use the float() function to convert it to a floating point number. However, if the string does not represent a valid number, these conversions will fail. String interpolation is a programming technique in which variables or expressions are inserted directly into strings. This is often used to format strings in a more readable and convenient way. The syntax of string interpolation varies by programming language. Strings are sequences of characters, and character arrays are arrays where each element is a character. In some programming languages such as C, strings are represented as characters ending with null characters. However, in many high-level languages, strings are a separate data type with their own methods and properties. Stand literals are strings written directly to the program source code. It is usually enclosed in quotes, and whether it is single or double quotes depends on the programming language. String literals are treated as constant values, and in some languages, they are immutable. Special characters in strings, such as line breaks, tabs, or quote characters, are usually represented by escape sequences. An escape sequence is a backslash () followed by a character or character sequence. The exact syntax and available escape sequences vary by programming language.
What is the historical origin of the word "string" in computer science?
How is strings different from other data types in programming?
Why are strings immutable in some programming languages?
How are strings stored in memory?
What common operations can be performed on strings?
How to convert a string to another data type?
What is string interpolation?
What is the difference between a string and a character array?
What are string literals?
How to represent special characters in strings?
The above is the detailed content of Why Is a String Called a String?. For more information, please follow other related articles on the PHP Chinese website!