Jump to page: 1 2
Thread overview
[Issue 4909] New: Two suggestions for std.algorithm.schwartzSort()
September 21, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4909

           Summary: Two suggestions for std.algorithm.schwartzSort()
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2010-09-21 12:58:38 PDT ---
Both my experience with Python and some practice with D v2 shows me that in script-like programs schwartzSort() is useful very often. Python 3 has even removed the "cmp" argument for its built-in sort, so it always performs a Schwartz sorting using the "key" argument, because it's simpler to use.

This an usage example of schwartzSort usage, to sort an array of arrays according to the second item in the sub-arrays:


import std.algorithm;
void main() {
    auto arr = [[5,9],[5,3],[4,12],[7,8],[12,2],[5,8]];
    schwartzSort!((e){ return e[1]; })(arr);
    assert(arr == [[12,2],[5,3],[7,8],[5,8],[5,9],[4,12]]);
}


To improve the usage of schwartzSort a support for transform function expressed as string may be added.

For non-English speaking programmers the spelling of schwartzSort is not easy, and a so commonly used function may enjoy a shorter name any way, so a "keySort" name may be better ("key" refers to the key argument function of the Python sort, that's named "transform" in Phobos):


import std.algorithm;
void main() {
    auto arr = [[5,9],[5,3],[4,12],[7,8],[12,2],[5,8]];
    keySort!q{a[1]}(arr);
    assert(arr == [[12,2],[5,3],[7,8],[5,8],[5,9],[4,12]]);
}


To help the understanding of this "keySort" name, in the signature of keySort the "transform" argument may be renamed "key".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 16, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4909



--- Comment #1 from bearophile_hugs@eml.cc 2011-09-16 04:49:47 PDT ---
See also: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=144557

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 16, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4909


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei@metalanguage.com
         AssignedTo|nobody@puremagic.com        |andrei@metalanguage.com


--- Comment #2 from Andrei Alexandrescu <andrei@metalanguage.com> 2011-09-16 09:07:36 PDT ---
Omitting a string form for the transform is an oversight that should be fixed.

Regarding naming, searching google etc. for schwartz sort yields relevant results whereas key sort does not. Please refrain from suggesting name changes of public APIs unless they add significant value.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 16, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4909



--- Comment #3 from bearophile_hugs@eml.cc 2011-09-16 09:58:00 PDT ---
(In reply to comment #2)

> Regarding naming, searching google etc. for schwartz sort yields relevant results whereas key sort does not.

Schwartz sort is a common name and it's meaningful, but I am never able to remember its correct spell. Being it a very common operation (I use it about as often as the normal sort), I think it's better to rename it with a name that's simpler to remember (in spell) and maybe shorter too. Maybe Kagamin is not the only person that agrees on this.

If you don't like keySort (I was just a quick idea), then we may search for something else, that possibly uses only short and easy to spell English words.

Google is handy in many situations, but it's not the Alpha and Omega when you have to give names to things.

"Schwart sort" gives 9,500 hits.
"Decorate Sort Undecorate" gives 7,270 hits.


> Please refrain from suggesting name changes of public APIs unless they add significant value.

Sorry, I'll keep suggesting what I think is better/right.

Also, this enhancement request if from 2010-09, and I think I have said that schwartzSort is a bad name from the beginning, from the first time I have seen it. So it was not really a "name change". It's a name change now.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 16, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4909



--- Comment #4 from Andrei Alexandrescu <andrei@metalanguage.com> 2011-09-16 10:20:10 PDT ---
(In reply to comment #3)
> (In reply to comment #2)
> 
> > Regarding naming, searching google etc. for schwartz sort yields relevant results whereas key sort does not.
> 
> Schwartz sort is a common name and it's meaningful, but I am never able to remember its correct spell. Being it a very common operation (I use it about as often as the normal sort), I think it's better to rename it with a name that's simpler to remember (in spell) and maybe shorter too. Maybe Kagamin is not the only person that agrees on this.

If you are using schwartzSort heavily, it makes sense to define a local alias for it. At any rate, you may be overstating your case; if you use something as frequently as you claim, you _will_ know the spelling.

> If you don't like keySort (I was just a quick idea), then we may search for something else, that possibly uses only short and easy to spell English words.

It's not about what I like or not. It's about doing sensible things. It doesn't seem sensible to simply decree that schwartzSort is inadequate to the extent it affects the productivity of people using it, and then solve the remaining problem of finding a different name for it.

> Google is handy in many situations, but it's not the Alpha and Omega when you have to give names to things.
> 
> "Schwart sort" gives 9,500 hits.
> "Decorate Sort Undecorate" gives 7,270 hits.

What would be the argument here? (That you unsubtly insert a typo, thus underlining how you can't remember the right spelling?)

> > Please refrain from suggesting name changes of public APIs unless they add significant value.
> 
> Sorry, I'll keep suggesting what I think is better/right.

You are of course welcome to do so, but I'm just suggesting to invest energy in things that may actually improve the state of affairs. You are suggesting a change of name from a name that is easily searchable and memorable to a name that you haven't even found yet but are sure is better.

> Also, this enhancement request if from 2010-09, and I think I have said that schwartzSort is a bad name from the beginning, from the first time I have seen it. So it was not really a "name change". It's a name change now.

The change didn't add value then, either.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 16, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4909



--- Comment #5 from bearophile_hugs@eml.cc 2011-09-16 10:49:07 PDT ---
(In reply to comment #4)

> (That you unsubtly insert a typo, thus
> underlining how you can't remember the right spelling?)

I have not done that on purpose, I am sorry.

But please trust me when I say I have problems with spelling that word :-)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 01, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4909



--- Comment #6 from bearophile_hugs@eml.cc 2011-10-01 12:58:40 PDT ---
In Clojure language the sort with a key function is named "sort-by": http://clojuredocs.org/clojure_core/1.2.0/clojure.core/sort-by

In Mathematica it is named "SortBy": http://reference.wolfram.com/mathematica/ref/SortBy.html

In Scala it is named "sortBy": http://www.scala-lang.org/docu/files/collections-api/collections_5.html

I suggest to deprecate "schwartzSort" name. In Phobos the "sortBy" name (as in Scala) will be better than "schwartzSort".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=4909



--- Comment #7 from Andrei Alexandrescu <andrei@erdani.com> 2013-03-10 19:53:33 PDT ---
https://github.com/D-Programming-Language/phobos/pull/1197

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=4909



--- Comment #8 from bearophile_hugs@eml.cc 2013-03-10 20:18:10 PDT ---
(In reply to comment #7)
> https://github.com/D-Programming-Language/phobos/pull/1197

> The naming issue will have to wait.

I still hate the "schwartzSort" name, after more than two years I am not able to remember its spelling. So I still think any other name will be better, like "keySort", "sortBy" or what else you prefer.

(On the other hand to tell the truth nowadays I write that swartz name kind of randomly, compile the module, and dmd suggests me the right name, that I copy & paste (in 2010 there was no spelling corrector). So now the situation is bearable).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 23, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=4909



--- Comment #9 from github-bugzilla@puremagic.com 2013-03-23 02:07:32 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/aeaf0cadeddce486337423e7c05ca73f703a8b50 Fix issue 4909

https://github.com/D-Programming-Language/phobos/commit/7cba78d5db6451de170f9d287fdbbfe25b47aaee Merge pull request #1197 from andralex/4909

Fix issue 4909 - Two suggestions for std.algorithm.schwartzSort()

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2