Fat comma

Fat comma

Fat comma is a programming term primarily associated with the Perl and Ruby programming languages, though others doubtless also employ the token. It refers to an operator, indicated as "=>", that can be used as a substitute for the comma operator and is an example of good idiomatic Perl when used to bind key-value pairs in a hash.Cite book|last=Conway|first=Damian|authorlink=Damian Conway|editor=Allison Randal and Tatiana Appandi|title=Perl Best Practices|origyear=2005|publisher=O'Reilly Media, Inc.|isbn=0-596-00173-8|chapter=4: Values and Expressions|pages=66|quote=Whenever you are creating a list of key/value or name/value pairs, use the "fat comma" (=>) to connect the keys to their corresponding values.]
# a typical, idiomatic use of the fat comma in Perlmy %newHash = ( first_name => "Tom", last_name => "Auger" );

Subtleties

When working under strict mode (a solid programming practice that forces the developer to adhere to the highest standards of consistency, typing and declaration available to the language's compiler), the fat comma has one advantage over its comma (',') analogue: it forces the word to its left to be interpreted as a string [http://perldoc.perl.org/perlop.html#Comma-Operator-comma-operator%2c-comma-%2c] .

Thus, whereuse strict; # for the love of Larry, use strict!my %badHash = ( bad_bareword, "not so cool" );would produce a run-time error (barewords are not allowed under strict), the following use of the fat commause strict;my %goodHash = ( converted_to_string => "very monkish" );would be legal and idiomatic, 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.The result is easier-to-read code, with a stronger emphasis on the name-value pairing of associative arrays.

References


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • Scribal abbreviation — Sigla redirects here. For the village in Poland, see Sigła. Text sample from an early 15th century Bible manuscript. Scribal abbreviations (sigla [plural], siglum and sigil [singular]) are the abbreviations used by ancient and mediæval scribes… …   Wikipedia

  • Wikipedia:Manual of Style — This guideline is a part of the English Wikipedia s Manual of Style. Use common sense in applying it; it will have occasional exceptions. Please ensure that any edits to this page reflect consensus. Shortcuts …   Wikipedia

  • Mark Hoppus — Background information Birth name Mark Allan Hoppus[1] …   Wikipedia

  • Discworld geography — Überwald redirects here. For the area in Hessen, Germany, see Überwald (Bergstraße). The Discworld Mapp by Stephen Player (Dutch version) This article concerns the fictional geography of Terry Pratchett s Discworld, featured in the novel series… …   Wikipedia

  • Jade — Nephrite jade redirects here. For nephrite itself, see Nephrite. This article is about the gemstone. For other uses, see Jade (disambiguation). A selection of antique, hand crafted Chinese jade …   Wikipedia

  • Windows Registry — The Windows Registry is a hierarchical database that stores configuration settings and options on Microsoft Windows operating systems. It contains settings for low level operating system components as well as the applications running on the… …   Wikipedia

  • Louie Louie — is an American rock n roll song written by Richard Berry in 1955. It has become a standard in pop and rock, with hundreds of versions recorded by different artists. The song is written in the style of a Jamaican ballad; and tells, in simple verse …   Wikipedia

  • Family name — Last name redirects here. For the song, see Last Name. Family name Frankenstein, an example of compound German family names which were typical for Jews (New Jewish Cemetery, Prague) A family name (in Western contexts often referred to as a last… …   Wikipedia

  • List of file formats — This is an incomplete list, which may never be able to satisfy particular standards for completeness. You can help by expanding it with reliably sourced entries. See also: List of file formats (alphabetical) This is a list of file formats… …   Wikipedia

  • JSON — infobox file format mime = application/json extension = .json genre = Data interchange standard = RFC 4627JSON (pronEng|ˈdʒeɪsɒn, i.e., Jason ), short for JavaScript Object Notation, is a lightweight computer data interchange format. It is a text …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”