Schwartzian Transform

In computer science, the Schwartzian transform is a Perl programming idiom used to improve the efficiency of sorting a list of items. This idiom is appropriate for comparison-based sorting when the ordering is actually based on the ordering of a certain property (the key) of the elements, where computing that property is an intensive operation that should be performed a minimal number of times. The Schwartzian Transform is notable in that it does not use named temporary arrays.

The idiom is named after Randal L. Schwartz, who first demonstrated it in Perl shortly after the release of Perl 5 in 1994. The term "Schwartzian Transform" applied solely to Perl programming for a number of years, but it has later been adopted by some users of other languages, such as Python, to refer to similar idioms in those languages. However, the algorithm was already in use in other languages (under no specific name) before it was popularized among the Perl community in the form of that particular idiom by Schwartz. The term "Schwartzian transform" indicates a specific idiom, and not the algorithm in general.

The Schwartzian Transform is a version of a Lisp idiom known as decorate-sort-undecorate, which avoids recomputing the sort keys by temporarily associating them with the input items. This approach is similar to memoization, which avoids repeating the calculation of the key corresponding to a specific input value. By comparison, this idiom assures that each input item's key is calculated exactly once, which may still result in repeating some calculations if the input data contains duplicate items.

Read more about Schwartzian Transform:  The Perl Idiom, Efficiency Analysis, Example, History, Comparison To Other Languages

Famous quotes containing the word transform:

    But I must needs take my petulance, contrasting it with my accustomed morning hopefulness, as a sign of the ageing of appetite, of a decay in the very capacity of enjoyment. We need some imaginative stimulus, some not impossible ideal which may shape vague hope, and transform it into effective desire, to carry us year after year, without disgust, through the routine- work which is so large a part of life.
    Walter Pater (1839–1894)