AspDotNetDev wrote:
I was just thinking that it seems a bit odd that "string" is so commonly used by programmers to refer to some text. I would think "text" would be more appropriate.
you have to take into consideration the fact that string
refers to a very specific thing, depending on the language:
- A sequence of
char
s, terminated in a NULL
(0x00
)
- A sequence of
char
s, pre-pended with their length as a uint8
(This is how Pascal and .NET BinaryReader
s do it)
- A fixed-width space that is assumed to have character data in it (MySQL VARCHAR)
- an N-Length columnar space containing character data (SQLite's TEXT field)
- a String literal, in C* defined as a sequence of characters wrapped in
'"'
.
- a Verbatim String in C#, allowing for
'\n'
and other punctuation to be preserved.
- A descriptive element attached to an object (Z-Code/Inform)
String, I feel, is used to encompass more of an idea, since "text" is ambiguous (is it a certain length? A certain kind? UTF?
AspDotNetDev wrote:
If we are using "string" just because it refers to a string of characters (aka, a sequence of characters), then why not also call numbers "strings" (as they are strings/sequences of digits and some other characters)?
Because int
s aren't strings of numbers. Sure, in TCL and a few other languages, things are natively strings, but that counts only for convencience (and in the case of TCL, efficiency). In C* languages (this includes Java, Python, etc), int
and float
are stashed as their binary values -- the value 128 isn't stored as "128" -- its as 0x80
. If we did store them as char
s, think of how much memory it would take to store the Uint64 maximum value: 18,446,744,073,709,551,615 (thanks, MSDN!). That's 0xFFFFFFFFFFFFFFFF in hex, a much, much smaller value in-memory.
---- "Pinky, are you thinking what im thinking?" "I Dunno brain, how many licks DOES it take to get to the tootsie roll center of a tootsie pop?" "You want me to calculate that? or should we take over the world?" "ooh! OooooOOOooH! lets find out!"