JavaScript core bug: Array.sort
-
sgunhouse Moderator Volunteer last edited by
12.16 is Presto, and will not be updated further. Opera 15 through 20 (so far) are based on Google's Blink engine, and will obviously produce the same results as Chrome. Yes, that's right - I did say 12.16 will not update to the latest stable version (18 ... 19 and 20 are still in development), you have to install it manually.
But as missingno says, since your sort does not order any element other than "three", Opera's answer is not wrong.
-
missingno last edited by
Originally posted by softmoonwebware:
If a JavaScript interpreter does not follow them, how can you write cross-browser code?
Like I said ECMAScript neither dictates a specific sorting algorithm, nor expects it to be stable.
Originally posted by softmoonwebware:
And in the technical definition of sort, I am sorting the one item as being _less_ than all the others, in this case.
Which gives you the correct result (as both are correct).
Originally posted by softmoonwebware:
But the technical definition of sort says that when two items are deemed equal, their order should not change!
Wrong. That only goes for stable sorting algorithmns. If stability isn't an issue, you can achieve better runtime and/or memory usage using an unstable sorting algorithmn. But as a writer of assembly language code you sure know that, right?
Fun fact: InsertionSort and MergeSort (used by Apple and Mozilla) are stable, QuickSort (Google Chrome) is not (by default). Chrome will sort arrays using InsertionSort if the array has 10 or less elements. So I suppose your code abovewillmay give another result if using 11 or more items in the array in Chrome. (Or Google already changed to another sorting algorithmn.)Originally posted by softmoonwebware:
Well, your Bank has a web-portal. You transfer money through it. To me that is a very serious application.
My bank has a web-portal that doesn't rely on JavaScript.
-
softmoonwebware last edited by
If I have an array of things my customers ordered:
orders=[
{count: 4, name: "John", item: "foo"},
{count: 7, name: "Jack", item: "bar"},
{count: 12, name: "Kelly", item: "baz"},
{count: 4, name: "Bob", item: "bar"},
{count: 3, name: "Tim", item: "buz"},
{count: 7, name: "Sara", item: "bar"} ]now I sort them by customer name:
orders.sort(function(a,b) {
if (a.name<b.name) return -1;
if (a.name>b.name) return 1;
else return 0; });I expect:
orders===[
{count: 4, name: "Bob", item: "bar"},
{count: 7, name: "Jack", item: "bar"},
{count: 4, name: "John", item: "foo"},
{count: 12, name: "Kelly", item: "baz"},
{count: 7, name: "Sara", item: "bar"},
{count: 3, name: "Tim", item: "buz"} ]Now I take the array and sort it further by number of items ordered, so I can fill my big$$$ orders first:
orders.sort(function(a,b) {return a.count-b.count;});I expect the names to remain ordered when the count is the same:
orders===[
{count: 3, name: "Tim", item: "buz"},
{count: 4, name: "Bob", item: "bar"},
{count: 4, name: "John", item: "foo"},
{count: 7, name: "Jack", item: "bar"},
{count: 7, name: "Sara", item: "bar"},
{count: 12, name: "Kelly", item: "baz"} ]In a situation where my program requires and relies on two-step ordering (perhaps two separate functions are called in order, with the choice of functions dependent on program state, to deliver a final ordering) Opera will fail.
-
softmoonwebware last edited by
reply to missingno:
points taken.
but points given, also.
At what point can we then create browser-based cross-platform applications when one JavaScript engine takes the "slack" road?
That is what modern HTML5 - ECMAScript 5 browsers are supposed to be about, yea?
So then my complaint is that Opera is just slack.
-
softmoonwebware last edited by
Originally posted by sgunhouse:
12.16 is Presto, and will not be updated further. Opera 15 through 20 (so far) are based on Google's Blink engine, and will obviously produce the same results as Chrome. Yes, that's right - I did say 12.16 will not update to the latest stable version (18 ... 19 and 20 are still in development), you have to install it manually.
But as missingno says, since your sort does not order any element other than "three", Opera's answer is not wrong.
OHHHH so that's why I'm wondering about Opera 17 references.
Seems I even browsed "recently" to opera.com and did not find anything that said Opera 17.
how lame is that? My browser won't even tell me there is something better going on. Instead it tells me _Oh, you're up to date!_
So when I update to 17 (a link or hint from the Opera moderator would have been nice) will it delete all my favorites as updates in the past have? I lost a lot of old links that were important to me going from 10 to 11; despite repeated bug notices 11 to 12, 12.0 to 12.1, all deleted my favorites. By then I backed up regularly, and turned OFF auto-update, only update notice.
Will Opera 17 allow me to use high-definition desktop colors? Or will its interface show me yellow letters on a white background?
The bright-white screen is hard on my eyes. -
A Former User last edited by
Originally posted by softmoonwebware:
My browser won't even tell me there is something better going on.
There's not. Opera 12.16 is still the most recent version of Opera for Presto. Opera 18 is the latest version for Blink, but it is still missing most of the features that make Opera better than other browsers.
-
softmoonwebware last edited by
Hey! It didn't loose my bookmarks!
Why? It doesn't even HAVE bookmarks!
Absolutely useless browser Opera 18 is.
Force me to use YOUR pictures via a theme? LAME and SLACK.
No tab-control?
I want tabs to be grouped together.
I want a newly opened tab to be active (why wouldn't I, I just opened it?!?)JUNK
-
softmoonwebware last edited by
Originally posted by Pesala:
Originally posted by softmoonwebware:
My browser won't even tell me there is something better going on.
There's not. Opera 12.16 is still the most recent version of Opera for Presto. Opera 18 is the latest version for Blink, but it is still missing most of the features that make Opera better than other browsers.
It is missing features that make Opera decent browser at all, let alone a better one.
-
A Former User last edited by
- It does have a bookmarks bar. Please search the forum for 100s of previous threads
- You can select new themes and create your own
- Tab-grouping would be nice.
- Open new tabs in the background is weird indeed. Shift + Click or Middle-click can be used.
-
serious last edited by
aaanyhow, we are already flaming 15+ in enough other threads, so btt (though I think that has been exhaustively discussed) or lets close the thread.
PS: OT: "relying on js" discussion: There is a distinct difference between relying on JS (as in: webapp using only an API to communicate with the server) which is not a big deal these days vs. relying on JS for validation of user input (which is very bad).
-
softmoonwebware last edited by
Originally posted by serious:
aaanyhow, we are already flaming 15+ in enough other threads, so btt (though I think that has been exhaustively discussed) or lets close the thread.
PS: OT: "relying on js" discussion: There is a distinct difference between relying on JS (as in: webapp using only an API to communicate with the server) which is not a big deal these days vs. relying on JS for validation of user input (which is very bad).
I just want to create a desktop application that never even needs a server.
But I may want to create an application that does most of its work on the browser, unloading the server, to deliver some pieces of data, secure or not. Securing data sent to the browser has nothing to do with JavaScript. I can forge a web form response with or without JavaScript. But if I want to process the data on-page (not necessarily validating it without server validation) I need JavaScript to function reliably. Again, point taken on what is and is not the real spec, and what I expected.Originally posted by Pesala:
- It does have a bookmarks bar. Please search the forum for 100s of previous threads
- You can select new themes and create your own
- Tab-grouping would be nice.
- Open new tabs in the background is weird indeed. Shift + Click or Middle-click can be used.
I really must be blind. I still don't see any bookmarks bar options going through all menus, right clicking everywhere, etc. But I'll spend another 2 hours going through all the bellyaching posts to find the answer. Oh wait, I DID, and still don't have a clue where to find it. Perhaps you would be kind enough to point me to the right discussion that actually gives instructions as to where to find this functionality.
And I specifically looked for a way to create my own theme, but not finding a link in Opera's menu, nor a link on the site to download theme, I felt like my time was better spent than to try to outguess the poorly conceived and designed user-interface and documentation of Opera 18. -
softmoonwebware last edited by
Originally posted by Pesala:
- It does have a bookmarks bar. Please search the forum for 100s of previous threads
- You can select new themes and create your own
- Tab-grouping would be nice.
- Open new tabs in the background is weird indeed. Shift + Click or Middle-click can be used.
In the "Where are the Opera 18 bookmarks post" you give advice that does NOT work in the copy of Opera 18 that I just downloaded. I can import 1000 bookmarks to my speed-dial, but there is NO bookmarks bar offered to import to.
-
frenzie last edited by
Originally posted by missingno:
Fun fact: InsertionSort and MergeSort (used by Apple and Mozilla) are stable, QuickSort (Google Chrome) is not (by default). Chrome will sort arrays using InsertionSort if the array has 10 or less elements. So I suppose your code above
willmay give another result if using 11 or more items in the array in Chrome. (Or Google already changed to another sorting algorithmn.)I thought Opera/Presto 10+ is also stable. Although I guess the OP proves that wrong?
Originally posted by softmoonwebware:
I expect:
orders===[
{count: 4, name: "Bob", item: "bar"},
{count: 7, name: "Jack", item: "bar"},
{count: 4, name: "John", item: "foo"},
{count: 12, name: "Kelly", item: "baz"},
{count: 7, name: "Sara", item: "bar"},
{count: 3, name: "Tim", item: "buz"} ]Now I take the array and sort it further by number of items ordered, so I can fill my big$$$ orders first:
orders.sort(function(a,b) {return a.count-b.count;});I expect the names to remain ordered when the count is the same:
orders===[
{count: 3, name: "Tim", item: "buz"},
{count: 4, name: "Bob", item: "bar"},
{count: 4, name: "John", item: "foo"},
{count: 7, name: "Jack", item: "bar"},
{count: 7, name: "Sara", item: "bar"},
{count: 12, name: "Kelly", item: "baz"} ]In a situation where my program requires and relies on two-step ordering (perhaps two separate functions are called in order, with the choice of functions dependent on program state, to deliver a final ordering) Opera will fail.
Umm, all of that works exactly that way in Opera 12.16 for me.
-
softmoonwebware last edited by
Originally posted by Frenzie:
Originally posted by softmoonwebware:
I expect:
orders===[
{count: 4, name: "Bob", item: "bar"},
{count: 7, name: "Jack", item: "bar"},
{count: 4, name: "John", item: "foo"},
{count: 12, name: "Kelly", item: "baz"},
{count: 7, name: "Sara", item: "bar"},
{count: 3, name: "Tim", item: "buz"} ]Now I take the array and sort it further by number of items ordered, so I can fill my big$$$ orders first:
orders.sort(function(a,b) {return a.count-b.count;});I expect the names to remain ordered when the count is the same:
orders===[
{count: 3, name: "Tim", item: "buz"},
{count: 4, name: "Bob", item: "bar"},
{count: 4, name: "John", item: "foo"},
{count: 7, name: "Jack", item: "bar"},
{count: 7, name: "Sara", item: "bar"},
{count: 12, name: "Kelly", item: "baz"} ]In a situation where my program requires and relies on two-step ordering (perhaps two separate functions are called in order, with the choice of functions dependent on program state, to deliver a final ordering) Opera will fail.
Umm, all of that works exactly that way in Opera 12.16 for me.
Gotta admit I never tried it. But then it must be how that specific Array-arrangement ends up sorting anyway; when the Array has more or less entries, or a different starting order, will it still work? If the original example that started this post changes the original order due to lazy-quick algorithms, then it MAY change any other ordered-Array that has random entries and random ordering functions.
But if Opera 18 were just a descent browser as a user's browser goes, then the comment by the moderator would be relevant, that Opera 18 is NOT lazy. But I won't be using 18 because it doesn't even have bookmarks! How many others will still use 12.16 like me? When will HTML5 applications be truly possible? Why would Opera release a less-powerful browser that should be a BETA release for testing, not the primary download available for new users? The answers are all blowing in the wind... -
frenzie last edited by
Originally posted by softmoonwebware:
How many others will still use 12.16 like me?
Most of the posters in this thread. Possibly even all if you replace 12.16 with Presto.
-
Deleted User last edited by
Originally posted by softmoonwebware:
But I won't be using 18 because it doesn't even have bookmarks! How many others will still use 12.16 like me? When will HTML5 applications be truly possible? Why would Opera release a less-powerful browser that should be a BETA release for testing, not the primary download available for new users? The answers are all blowing in the wind...
- Opera 18 (Blink) isn't a BETA release for testing. It is a final version as were 15, 16 and 17.
Opera ASA believes that their new product is mature enough to satisfy the needs of the masses (average users) which it is primarily aimed for. - Developement of Opera 12.16 (Presto) has ceased.
- Opera 12.16 (Presto) and the new Opera (Blink) 15, 16, 17, 18, .... are totally different products. Only thing they have in common is the Opera-logo.
The new Opera (Blink) is basically Google Chrome with a different shell.
BTW, I'm also using the defunct Opera Presto and it doesn't look like I'll make the switch to the new product anytime soon if ever.
- Opera 18 (Blink) isn't a BETA release for testing. It is a final version as were 15, 16 and 17.
-
missingno last edited by
Originally posted by softmoonwebware:
So then my complaint is that Opera is just slack.
Depends. I would assume Carakan (Opera's JS-engine) uses QuickSort-algorithmn because it is a good general purpose sorting algorithmn to begin with. (Although I don't have any insight on this.)
Originally posted by serious:
PS: OT: "relying on js" discussion: There is a distinct difference between relying on JS (as in: webapp using only an API to communicate with the server) which is not a big deal these days vs. relying on JS for validation of user input (which is very bad).
I would differentiate between "using JS" and "relying on JS". You should never rely on JS, but you might use it for some parts. For example, if you have to sort an array to display it in your frontend, I wouldn't mind if the client manipulates the result as that only affects his side. But if you store the array back on the server side and "rely" on the data in it, I would have to validate anyways. So in this case, it doesn't make sense to do the sorting on the client side, but rather do everything on the server side and only send the results (which the client may manipulate, but I don't care as the server is still consistent).
-
frenzie last edited by
Originally posted by missingno:
But if you store the array back on the server side and "rely" on the data in it, I would have to validate anyways. So in this case, it doesn't make sense to do the sorting on the client side, but rather do everything on the server side and only send the results (which the client may manipulate, but I don't care as the server is still consistent).
+1
-
softmoonwebware last edited by
Originally posted by missingno:
I would differentiate between "using JS" and "relying on JS". You should never rely on JS, but you might use it for some parts. For example, if you have to sort an array to display it in your frontend, I wouldn't mind if the client manipulates the result as that only affects his side. But if you store the array back on the server side and "rely" on the data in it, I would have to validate anyways. So in this case, it doesn't make sense to do the sorting on the client side, but rather do everything on the server side and only send the results (which the client may manipulate, but I don't care as the server is still consistent).
Amazing how you miss the point altogether.
You are still in the era of using _area- -/area_ tags:
The server sends an image-area and a JavaScript form.
{subsection A}
The user clicks on several check/radio buttons on the form, and types in data in input fields.
The user hits submit button.
The server validates the data.
The server processes the data and sends a new modified image-area, along with the entire page, most of which has nothing to to with this image-area.
--repeat subsection A --several times-- (overworking an already overloaded server) until the user is satisfied with the state of the image.
Now the user clicks on the image-area (it is a color picker).
The data of the user-click is sent to the server, processed into a hex-color, rgb color, etc. in a computationally intense process, again overworking the server (unnecessarily, because __we can't rely on JavaScript__), and the entire web page is resent, but with another form field filled in with the user-selected color from the image-area.
And we still haven't even mentioned that somehow this process has to keep track of WHICH color-selection-input is getting filled. Remember, we cannot rely on js!
Now the user does all this over and over again, waiting patiently for the server all along..... In fact, every "live" action like this needed must be sent to the server for processing.
After half-an-hour of back-and-forth data transfer, the user finally has a complex web-form filled out (with many fields being being the selected colors mentioned above). The form is dynamic to properly represent all the needed data, so every time the form needs new fields added or fields removed, a special submit button must be pressed by the user, and the server will add or remove the proper (new or old) fields, and send the page back to the server, keeping track of every POSTed variable to properly set the form inputs to the previous user-selections.
The user finally submits the fully completed form with another separate submit button (the form has 100 or so throughout that do various different things - a real swamp of an _application_ if you can really call it that)
The server validates and processes the data, refills the form with the POSTed data, and sends a new web page including a new graphical-image (besides the color-picker image mentioned above) developed from the user-sent data.
The entire process repeats until the user is finished, an hour later.Or we could _rely_ on JavaScript. All this could be done on the user's machine without pestering the server. In fact, we don't even need the server, a static HTML page can reside on the user's harddrive and used anywhere, anytime. We can save the final image to hard drive, or perhaps send it to a server, fully processed.
Relying on JavaScript to do the job, the user is done in 10 minutes, and the server is free to serve pages not process sub-data for every little user-interaction.We USE JavaScript to _enhance_ the user's browsing experience on a public server-sent __web-page__ that MUST work for every poor user with a computer from the year 2000 with MSIE6 and/or JavaScript turned off. HTML5 desktop apps _rely_ on JS.
Any time an __app__ needs to do some work, the server should be minimally involved, if at all.