Fat comma
The fat comma (also termed hash rocket in Ruby and a fat arrow in JavaScript) is a syntactic construction that appears in a position in a function call (or definition) where a comma would usually appear.[src] The original usage refers to the " ) letters :( " construction in ALGOL 60.[src] Newer usage refers to the " => " operator present in some programming languages.[src] It is primarily associated with PHP, Ruby and Perl programming languages, which use it to declare hashes.[src] Using a fat comma to bind key-value pairs in a hash, instead of using a comma, is considered an example of good idiomatic Perl.[src] In CoffeeScript and TypeScript, the fat comma is used to declare a function that is bound to this .[src] # a typical, idiomatic use of the fat comma in Perl my %hash = ( first_name => "Larry", last_name => "Wall", );[src]
The fat comma (also termed hash rocket in Ruby and a fat arrow in JavaScript) is a syntactic construction that appears in a position in a function call (or definition) where a comma would usually appear.[src] The original usage refers to the " ) letters :( " construction in ALGOL 60.[src] Newer usage refers to the " => " operator present in some programming languages.[src] It is primarily associated with PHP, Ruby and Perl programming languages, which use it to declare hashes.[src] Using a fat comma to bind key-value pairs in a hash, instead of using a comma, is considered an example of good idiomatic Perl.[src] In CoffeeScript and TypeScript, the fat comma is used to declare a function that is bound to this .[src] a typical, idiomatic use of the fat comma in Perl my %hash = ( first_name => "Larry", last_name => "Wall", ); ===ALGOL 60=== The ALGOL "fat comma" is semantically identical to the comma.[src] In particular, whether letter strings are used, and what their contents are, need not match between the definition of a function and its uses.[src] The following are equivalent: S(s-5, T, P) S(s-5) t: (T) p: (P) S(s-5) Temperature: (T) Pressure: (P) ===Perl=== The "fat comma" forces the word to its left to be interpreted as a string.[src] Thus, where this would produce a run-time error under strict (barewords are not allowed): %bad_example = ( bad_bareword, "not so cool" ); the following use of the fat comma would be legal and idiomatic: %good_example = ( converted_to_string => "very monkish" ); This is because the token converted_to_string would be converted to the string literal "converted_to_string" which is a legal argument in a hash key assignment.[src] The result is easier-to-read code, with a stronger emphasis on the name-value pairing of associative arrays.[src] ===PHP=== In PHP, the fat comma is termed a double arrow, and is used to specify key/value relationships when declaring an array.[src] Unlike in Perl, the double arrow does not treat what comes before it as a bare word, but rather evaluates it.[src] Hence, constants used with the double arrow will be evaluated: $array = array("name" => "PHP", "influences" => array("Perl", "C", "C++", "Java", "Tcl")); ===Ruby=== In Ruby, the fat comma is the token to create hashes.[src] Ruby 1.9 introduced a special syntax to use symbols as barewords.[src] In Ruby, the fat comma is called a hash rocket.[src] Old syntax old_hash = { :name => 'Ruby', :influences => ['Perl', 'Python', 'Smalltalk'] } New syntax (Ruby >= 1.9) new_hash = { name: 'Ruby', influences: ['Perl', 'Python', 'Smalltalk'] } ==References==[src]
24 sentences · 24 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Fat comma." encyclopegia.org, 2023, https://encyclopegia.org/wiki/fat-comma. Accessed 30 November 2026.
Chicago
"Fat comma." encyclopegia.org. Accessed November 30, 2026. https://encyclopegia.org/wiki/fat-comma.
APA
encyclopegia.org. (2023). Fat comma. Retrieved November 30, 2026, from https://encyclopegia.org/wiki/fat-comma
Accessed November 30, 2026 · CC BY-SA 4.0 · citation page · JSON