Editing 1306: Sigil Cycle

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 8: Line 8:
  
 
==Explanation==
 
==Explanation==
In {{w|computer programming}}, a variable is a way of storing information temporarily, for use later in the program. There are different types of variables, called {{w|Data type|data types}}, such as integers, strings, characters, and booleans, all of them holding different types of information. Integers hold whole numbers, strings hold text, and so on. Variables traditionally have names that identify their purpose, and a programmer should usually be able to infer from this variable name what type of variable it is. For example, if you want to store the name of the customer in a catalogue service, you might store the text in a string variable called "NameOfCustomer". Because it is fairly clear that names are made up of text, it is logical that this variable would be a string variable - if you didn't have any other information about it.
+
{{incomplete|This is just a skeleton, every detail is missing and probably some parts are inaccurate or plain wrong}}
  
A {{w|Sigil (computer programming)|sigil}} in computer programming is a symbol that appears before the variable name. It is an alternative method of telling someone who is reading the program code what data type the variable is. Rather than relying on logic, then, to know that NameOfCustomer is a string, you might use a sigil "$" before the variable name, as in $NameOfCustomer, which would specify that the variable can hold text. Sigils can also specify the {{w|Scope (computer science)|scope}} of a variable, which refers to where the variable can be used in a program, and which parts of the program can access that variable. Sigils are useful in some ways because you don't have to refer to previous program code or find where the variable is declared (created) to know what data type it is. They also provide some level typing in languages that do not explicitly declare the type of the variable.
+
In computer programming, a {{w|Sigil (computer programming)|sigil}} is a symbol attached to a variable name, showing the variable's datatype or scope, usually a prefix, as in $foo, where $ is the sigil.
 
 
Most {{w|Programming language|programming languages}} have a different method for storing variables, although some languages may use the same variable types under different names. The following are the programming languages referenced in the comic and how they use variables.
 
  
 
;{{w|QBASIC}}
 
;{{w|QBASIC}}
:Variables of type string end with the $ symbol. Other symbols are used (% for integers, ! for single-precision, # for double-precision and, in some versions of BASIC, & for long integers), however the usual QBASIC program will use only the $ symbol and not any of the others, as the default type if no symbol is used is single-precision and that's OK for most numeric uses.
+
:Variables of type string end with the $ symbol. Other symbols are used (% for integers, ! for single-precision, # for double-precision and, in some versions of BASIC, & for long integers), however the usual QBASIC program will use only the $ symbol and not any of the others, as the default type if no symbol is used is double-precision and that's OK for most numeric uses.
  
 
;{{w|C++}}
 
;{{w|C++}}
:Pronounced "see plus plus." Variables are just words with regular letters. It is the name of the language itself that includes symbols.
+
:Variables have no strange symbol. They are just words with regular letters.
  
 
;{{w|bash (Unix shell)|bash}}
 
;{{w|bash (Unix shell)|bash}}
:This is not typically thought of as a full-featured programming language, but a Unix shell. However, the shell command syntax is rich enough to be able to write simple (and sometimes really complex) programs called shell-scripts. In this language, all variable dereferences start with the symbol $.
+
:This is not strictly a programming language, but a Unix shell. However, the shell command syntax is rich enough to be able to write simple (and sometimes really complex) programs, usually called shell-scripts. In this language, all variables start with the symbol $.
  
 
;{{w|Perl}}
 
;{{w|Perl}}
:In Perl, the initial character provides the context of the variable. Scalars (text, numeric and also to references to data) start with the $ character. An @ is for an array. With %, it is a hash (a loose non-sequential array, or 'dictionary' lookup). Functions ''can'' be given a preceding &, but rarely need this in straightforward use. You can use the variables $temp, @temp, %temp and &temp simultaneously and independently. There is also the * (not in a mathematical sense) which identifies a 'glob', a way to fuse or use all those types (and more!) in 'interesting' ways if you have a yen to.
+
:Variables of simple types in Perl start with $, and arrays start with @.
:A block, with {} surrounding some other suitable statement(s), can potentially be typed to (re)interpret the context within. If you have a $reference which currently points to an @array, @{$reference} will let you use it as a direct array. But in simple cases, like that, this can often be shortened to @$reference, as alluded to by the "@$PERL" of the comic. (Just as $$reference would be a valid way to dereference the $reference when it points to $scalar... or even to $anotherReference that itself points to a %hash, in which case you could even use %$$reference for 'direct' access to that. Perl can be complicated, if you let it!)
 
  
 
;{{w|Python (programming language)|Python}}
 
;{{w|Python (programming language)|Python}}
:Variables are just words with regular letters.
+
:Variables have no marker symbol.
  
 
;{{w|Google}}
 
;{{w|Google}}
:Once upon a time, Google added a social network called "[[918|Google+]]" (pronounced "Google plus") to its many offerings. On this network, accounts were identified and "mentioned" (linked in a message, and sent a notification) with a + prefix. For example, [[Randall]] was "+Randall Munroe". Google+ has been defunct since 2019, but it was active and growing in 2013 when this comic was posted.
+
:In the beginning of Google, it was a search engine. However, it now includes many things, in particular a social network called Google+.
  
 
;{{w|Twitter}}
 
;{{w|Twitter}}
:Twitter account IDs are identified by the leading symbol @. When an account is "mentioned" in a tweet using @, it triggers smart behavior. For example, account owners can configure Twitter to forward tweets that mention them. This feature was not present in the early days of Twitter.
+
:Twitter channels are identified by the symbol @.
  
 
;{{w|Hashtag}}s
 
;{{w|Hashtag}}s
:In 2007 Twitter users began a convention that a # sign (whose {{w|Number sign|many names}} include the "hash") can be prepended to words to mark them as keywords. Twitter could then be searched for those words. In 2009 Twitter recognized the existence of hashtags and began hyperlinking them. Some other microblogging services followed suit.  Google+ eventually added hashtag support as did Facebook.
+
:In some microblogging messages, a # sign can be prepended to important words to mark them as "keywords", so the message can be searched for those words.
 
 
As is noted by the comic, the use of sigils to indicate types of variables varies between programming languages, from strict enforcement in languages like Perl, to their complete absence in languages like C++ (but see {{w|Hungarian Notation}}). The comic notes that the use of sigils seems to be cyclic, especially if you count things like hashtags as extensions of the pattern.
 
 
 
The title text describes the two competing influences responsible for the cycle: The first impulse finds sigils useful to elucidate the type of the variable, especially when variable names are not very descriptive, while the latter impulse notes that descriptive variable names are much more useful for that purpose, especially in extensible languages where the built-in types form only a small part of the type system.
 
  
 
==Transcript==
 
==Transcript==
:A sinusoidal curve is shown.
+
{{incomplete transcript}}
:Y axis: Odds that the words I type will start with some weird symbol
+
*Y axis: Odds that the words I type will start with some weird symbol
:X axis: Time
+
*X axis: Time
:Data labels: [at first peak] $QBASIC, [at first trough] C++, [at second peak] $BASH, @$PERL, [at second trough] PYTHON, [at third peak] +GOOGLE, @TWITTER, #HASHTAGS
+
*Data labels: $QBASIC, C++, $BASH, @$PERL, PYTHON, +GOOGLE, @TWITTER, #HASHTAGS
  
 
{{comic discussion}}
 
{{comic discussion}}
 
+
[[Category:Charts]]
[[Category:Line graphs]]
 
 
[[Category:Computers]]
 
[[Category:Computers]]
 +
[[Category:Comics presenting a compromise]]
 
[[Category:Internet]]
 
[[Category:Internet]]
 
[[Category:Programming]]
 
[[Category:Programming]]
 
[[Category:Social networking]]
 
[[Category:Social networking]]
 
[[Category:Google Plus]]
 
[[Category:Google Plus]]

Please note that all contributions to explain xkcd may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see explain xkcd:Copyrights for details). Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel | Editing help (opens in new window)