Do more on the web, with a fast and secure browser!

Download Opera browser with:

  • built-in ad blocker
  • battery saver
  • free VPN
Download Opera

JavaScript core bug: Array.sort

  • 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.

  • 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

  • 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.

    1. It does have a bookmarks bar. Please search the forum for 100s of previous threads
    2. You can select new themes and create your own
    3. Tab-grouping would be nice.
    4. Open new tabs in the background is weird indeed. Shift + Click or Middle-click can be used.
  • 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).

  • 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:

    1. It does have a bookmarks bar. Please search the forum for 100s of previous threads
    2. You can select new themes and create your own
    3. Tab-grouping would be nice.
    4. 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.

  • Originally posted by Pesala:

    1. It does have a bookmarks bar. Please search the forum for 100s of previous threads
    2. You can select new themes and create your own
    3. Tab-grouping would be nice.
    4. 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.

  • 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.

  • 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...

  • 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.

  • Everyone who runs Linux has to be using Presto, as no Blink-based versions have been released for that platform yet. Me - on Windows I use the latest versions (including test versions), in Linux I use 12.16.

  • 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.

  • 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).

  • 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

  • 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.

  • 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).

    In my case, I _rely_ on JavaScript to sort an array of HTML Elements, moving one to the top, and then to apply individual CSS classnames to each one representing different CSS z-levels. If it doesn't work, the user cannot even use the application to let the server validate the final result.

    In your analysis, the data cannot even BE displayed to the user properly.

    And you would produce an application that displays mixed-up data to the user, asking him _is this data OK and ready to be submitted?_
    He says no, because things are out of order...but when he tries to fix it, it re-orders itself wrong again and again...until he goes to the competition's website and buys the product there.

    Originally posted by missingno:

    I wouldn't mind if the client manipulates the result as that only affects his side

    That is a poor excuse for work done. Take some pride in what you do, and do the best quality job you know how. Even if you clean toilets for a living.

  • Originally posted by softmoonwebware:

    In my case, I _rely_ on JavaScript to sort an array of HTML Elements, moving one to the top,

    Well, we can argue about terminology here. I would say you are _using_ JavaScript to move an element in an array. While your methology by "sorting" it gives you the result, the underlying algorithmn may change the order of other elements in the array which is an unwanted side-effect to you.

    Your other example of a color picker also doesn't need any server involved, because you're still _using_ JavaScript to do so. The server doesn't need to know if the client picks black or white or red or blue or any other color. Maybe the result is sent to the server, but then you cannot rely on the data to be accurate at all, because the client could send "banana" or "cat".

Locked