Interesting USES block sorting behaviour with JEDI Code Format lazarus / 9-Editor ---------------------------------------------------------------------- Aistis · 2024-02-09 08:34 I don't know if it's a bug or if I have mis-configured something, so I'm hoping you guys will help me out with my issue. I constantly use JEDI Code formatting and have no qualms with it. Apart from an interesting behaviour when it comes to uses unit sorting. As an example, my Windows machine sorts these units like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses SysUtils, StdCtrls; while my Linux machine sorts it like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses StdCtrls, SysUtils; On both machines I have configured English to be the computer's display language while using Lithuanian for regional settings (dates, currency, etc.). It seems that it uses the English alphabet for sorting on Linux (as one would expect) with Y going after T, while on Windows it uses (I assume) the Lithuanian alphabet, where Y comes before T. The thing is, my whole Windows machine, be it user locale or system wide locale is set to English, yet it still seems to sort by the Lithuanian alphabet. And the reverse is true on Linux as shown above. It's not a huge problem, but it's still an annoyance as I'm running code formatting constantly, and it keeps showing up in git diff. Obviously, I can turn off sorting completely, but I'd rather have it on and sort alphabetically (preferably in English) if possible. ---------------------------------------------------------------------- Thaddy · 2024-02-09 08:39 Any code beautifier should NEVER sort the uses clause differently from what the programmer defined, because unit order can be extremely important, e.g. mem managers and the like. If it sorts, it is a bug and not a small one.. Another reason is that some structures are defined differently in the rtl and e.g. the Windows unit and then the order is also important for which is chosen by the compiler. Or what if on unix cthreads is sorted away? So turn sorting off, even if you don't like it....... Sorting should be removed from any code beautifier that "supports" it! It is neigh impossible for a beautifier to analyse every single unit's code to determine the order of the units in the units clause to the extend that the order is proper for the program or library or unit at hand. Even the compiler can not do that. To paraphrase Asterix and the Helvatians: 7 lashes with a baguette for the idiot that implements that. ---------------------------------------------------------------------- Aistis · 2024-02-09 09:02 Quote from: Thaddy on February 09, 2024, 09:39:25 amAny code beautifier should NEVER sort the uses clause differently from what the programmer defined, because unit order can be extremely important, e.g. mem managers and the like. If it sorts, it is a bug and not a small one.. Another reason is that some structures are defined differently in the rtl and e.g. the Windows unit and then the order is also important for which is chosen by the compiler. So turn sorting off, even if you don't like it....... Sorting should be removed from any code beautifier that "supports" it! It is neigh impossible for a beautifier to analyse every single unit's code to determine the order to the extend that the order is proper for the program or library or unit at hand. What you're saying does make sense. However, I believe uses sorting was on by default with both my Lazarus installs (or I might be mis- remembering). Whatever the case might be, if the order matters so much I wonder why the JEDI code formatting comes with such a function to begin with. ---------------------------------------------------------------------- Thaddy · 2024-02-09 09:08 Sheer Incompetence? Leave out the question mark. Sorting, both on program level and unit level, can and will eventually break your code. Period. Reported as issue 40756 on the Lazarus bug tracker with the request to entirely remove it. Well, at least not present it in the dialog may do... ---------------------------------------------------------------------- DomingoGP · 2024-02-09 23:18 As Thaddy has explained very well, these are potentially dangerous options  so I have added a warning in the configuration dialog in trunk. Quote from: Aistis on February 09, 2024, 09:34:21 amObviously, I can turn off sorting completely, but I'd rather have it on and sort alphabetically (preferably in English) if possible. I have also changed the code so that it does not take into account the "locale" when sorting. Quote from: AistisI believe uses sorting was on by default with both my Lazarus installs (or I might be mis-remembering). No, its disabled by default in Lazarus. ---------------------------------------------------------------------- Thaddy · 2024-02-10 06:57 Labas, Aistis, One further note on unit order, apart from sorting, is that it is good practice to put the FreePascal units before the Lazarus units. Lazarus does that already automatically for you when you create a project. That means in your example that sysutils should always be before stdctrls. ---------------------------------------------------------------------- Aistis · 2024-02-11 12:36 Quote from: Thaddy on February 10, 2024, 07:57:32 amLabas, Aistis, One further note on unit order, apart from sorting, is that it is good practice to put the FreePascal units before the Lazarus units. Lazarus does that already automatically for you when you create a project. That means in your example that sysutils should always be before stdctrls. Thanks. I'll keep it in mind.