RCrandall 8 Posted August 31, 2023 I am returning to MMX after a long break and I'm exploring it all again. I dimly recall seeing that the order of the Uses clauses can affect compilation speed, a problem I'm having, but I'm far from sure of that. Is this the benefit of formatting the list of used units? Or is to improve readability, or some other reason? Inquiring minds want to know, thanks, Rob C Share this post Link to post
Uwe Raabe 2057 Posted August 31, 2023 It started with the request to expand the unit scope names, which gave a good boost to compile time in some cases. The idea of uses clause grouping and sorting crept in my mind when I noticed difficulties to quickly scan the list of used units. With a sorted and grouped uses clause the used libraries are clearly visible immediately. So its partly for compilation speed as well as a neat look (some call it OCD). 2 Share this post Link to post
Fred Ahrens 59 Posted August 31, 2023 Sorting units by name is dangerous. There are some units that need to be added at the end of the list, if they overwrite some behavior's of objects and functions of other units above in the list. There are other units that need to be placed on top of the list if they do some special initialization that needs to be done in the app as soon as possible, before any other parts of the app start to initialize. 4 Share this post Link to post
Uwe Raabe 2057 Posted August 31, 2023 43 minutes ago, Fred Ahrens said: Sorting units by name is dangerous. Albeit there actually is a request for that, MMX does not sort the units by name. They are grouped according to a user defined pattern, but inside the group the order stays intact. F.i. this is the Groups entry for one of my projects: After some Delphi units in a decent order based on dependency, there are the Raize and TMS units followed by VirtualTrees, PngComponents and the ZipForge units. The last four mimic the unit scopes and naming convention of the project itself also ordered by dependency. (TMS can improve their unit naming btw.) A typical uses clause looks like this: uses Winapi.Messages, System.Classes, System.Actions, System.Types, System.ImageList, Vcl.Graphics, Vcl.Menus, Vcl.ActnList, Vcl.Controls, Vcl.ExtCtrls, Vcl.Forms, Vcl.StdCtrls, Vcl.Tabs, Vcl.Dialogs, Vcl.ImgList, Vcl.VirtualImageList, Vcl.AppEvnts, RzTabs, RzForms, RzShellDialogs, RzPanel, RzButton, RzSplit, RzCommon, Common.Form, IpButton, IpMRU, IpMultiLanguageSupport, TcEditorTypes, TcGlbCfgSystem, TcGlbCfgVisualStyle, RNcCodeViewer, REditorStructure, REditorItems, RBasePalette, RStoragePalette, REditorPalette, RCustomPalette, REditorPanel, RBaseFrame, RObserver, RStandardStatus, REditorNesting, RBaseEditorFrame; The grouping algorithm is pretty flexible and I never had a case that could not be handled. If auto-sort a uses clause is automatically sorted whenever MMX modifies it - a very handy feature. 1 Share this post Link to post
mvanrijnen 123 Posted August 31, 2023 2 hours ago, Fred Ahrens said: Sorting units by name is dangerous. There are some units that need to be added at the end of the list, if they overwrite some behavior's of objects and functions of other units above in the list. There are other units that need to be placed on top of the list if they do some special initialization that needs to be done in the app as soon as possible, before any other parts of the app start to initialize. Actually this means there is a design flaw (i know, hard to not have this situations, we have them also, but in reallity it's something to fix i think). How you going explain 15years later that unit xyz has to be before unit abc, put some text in comments ? 1 Share this post Link to post
David Heffernan 2345 Posted September 1, 2023 9 hours ago, Fred Ahrens said: Sorting units by name is dangerous. There are some units that need to be added at the end of the list, if they overwrite some behavior's of objects and functions of other units above in the list. There are other units that need to be placed on top of the list if they do some special initialization that needs to be done in the app as soon as possible, before any other parts of the app start to initialize. Although the real problem is the language design that makes this order affect the meaning of the program. 2 Share this post Link to post
Lars Fosdal 1792 Posted September 1, 2023 I remember having this discussion with an american on LinkedIn. He had written a tool that sorted the uses clause, and he turned a darker shade of crazy when I pointed out the risks, "chanting" USA, USA, USA. No point in discussing with such people. 3 Share this post Link to post
RCrandall 8 Posted September 1, 2023 18 hours ago, Uwe Raabe said: It started with the request to expand the unit scope names, which gave a good boost to compile time in some cases. The idea of uses clause grouping and sorting crept in my mind when I noticed difficulties to quickly scan the list of used units. With a sorted and grouped uses clause the used libraries are clearly visible immediately. So its partly for compilation speed as well as a neat look (some call it OCD). "Expand unit scope names" - that was it. Thanks for the speedy reply and I appreciate all the other comments too. Rob C Share this post Link to post
Rollo62 536 Posted September 1, 2023 9 hours ago, Lars Fosdal said: ... "chanting" USA, USA, USA. No point in discussing with such people. Probably you misunderstood him a little, since this was his desired (world) sort order ... 🤔 1 Share this post Link to post
Attila Kovacs 629 Posted September 1, 2023 Make te uses list great again! Share this post Link to post
Fr0sT.Brutal 900 Posted September 4, 2023 On 9/1/2023 at 2:39 AM, mvanrijnen said: Actually this means there is a design flaw RTL itself suffers from this flaw for some identifiers (mostly WinAPI / generic types clash). Luckily these issues are detected by compiler but could cause serious issues if these types are used as untyped pointers Share this post Link to post
JonRobertson 72 Posted November 22, 2023 On 8/31/2023 at 5:00 PM, Uwe Raabe said: How do you configure groups like (ZipForge)? I could not find that in MMX Properties or MMX Project Options. I would like to do this for ImageEn and maybe others. ImageEn units do not have a consistent prefix suitable for grouping. Thanks! Thanks Share this post Link to post
Uwe Raabe 2057 Posted November 22, 2023 Brackets denote a list of unit names forming a group. I use it f.i. for keeping the ToolsApi units together: (ToolsApi,DesignIntf,DCCStrs,DockForm,TabDock) The example shows a glitch in the TMS unit naming: Adv* followed by (BaseGrid) keeps the TMS Grids unit together. The other example (ZipForge) is used when a group consists of a single unit name only. Omitting the brackets would take it as a unit scope name instead. 1 Share this post Link to post
ULIK 16 Posted November 23, 2023 (edited) Uwe, where do I find this groups dialog? Is this a new feature you are working on? Found it! Thanks! Edited November 23, 2023 by ULIK Share this post Link to post
haentschman 92 Posted November 23, 2023 @Uwe Raabe Hi...😎 Is it possible to start each group in a new line? uses Winapi.Windows, System.Classes, System.Generics.Collections, System.Generics.Defaults, System.SysUtils, ... Share this post Link to post
Uwe Raabe 2057 Posted November 23, 2023 26 minutes ago, haentschman said: Is it possible to start each group in a new line? That's default. Share this post Link to post
haentschman 92 Posted November 23, 2023 ...🤔 before: uses System.Classes, System.SysUtils, System.Variants, System.Generics.Collections, System.Generics.Defaults, System.DateUtils, System.Math, System.StrUtils, Vcl.Imaging.pngimage, Data.DB, FireDAC.Stan.Param, FireDAC.Stan.Option, FireDAC.Comp.Client, FireDAC.Comp.Script, DataModuleTextConstants, x.Classes.Common, x.Classes.Base, x.Classes.Data, x.Constants, x.Types, x.Tools.Mapping, x.Tools.DateTime, x.Tools.TryFinally, x.Tools.Json, x.Tools.Regex, x.Tools.IO, x.Tools.BitMask, x.Database.Common, x.Preferences; after: uses System.Classes, System.SysUtils, System.Variants, System.Generics.Collections, System.Generics.Defaults, System.DateUtils, System.Math, System.StrUtils, Vcl.Imaging.pngimage, Data.DB, FireDAC.Stan.Param, FireDAC.Stan.Option, FireDAC.Comp.Client, FireDAC.Comp.Script, DataModuleTextConstants, x.Classes.Common, x.Classes.Base, x.Classes.Data, x.Constants, x.Types, x.Tools.Mapping, x.Tools.DateTime, x.Tools.TryFinally, x.Tools.Json, x.Tools.Regex, x.Tools.IO, x.Tools.BitMask, x.Database.Common, x.Preferences; Share this post Link to post
Uwe Raabe 2057 Posted November 23, 2023 And for completeness: What are the defined groups? Share this post Link to post
haentschman 92 Posted November 23, 2023 (edited) Sorry...😉 PS: with "*" ("Form.*") also... PS: FireDAC and more are missing (first test) 😉 Edited November 23, 2023 by haentschman Share this post Link to post
Stano 143 Posted November 23, 2023 I have: Winapi;System.Win;System;Data;Vcl;obsidium;Adv*;(BaseGrid);Virtual*;FireDAC;REST;Xml;fcx*;VclTee;jst*;Vst*;sub*;u* Result: uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, System.Generics.Collections, System.Generics.Defaults, System.DateUtils, Data.DB, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, advofficepager, AdvMemo, advglowbutton, advpanel, advstyleif, advappstyler, FireDAC.Comp.Client, FireDAC.Stan.Param, jstAdvPanel, BasalForm, Htmlabel; Share this post Link to post
Uwe Raabe 2057 Posted November 23, 2023 Better remove the trailing dots in Frame and Form. Plain group names get that automatically appended when looking for a match. F.i. a simple entry like Form matches unit names Form, Form.Tools and Form.Test, but not FormTest. Assuming that the x stands for the obfuscated parts in your screenshot, I get the following results with this Groups: Winapi System.Win System Vcl Data FireDAC cx DM x x.Tools Frame Form uses System.Classes, System.SysUtils, System.Variants, System.Generics.Collections, System.Generics.Defaults, System.DateUtils, System.Math, System.StrUtils, Vcl.Imaging.pngimage, Data.DB, FireDAC.Stan.Param, FireDAC.Stan.Option, FireDAC.Comp.Client, FireDAC.Comp.Script, x.Classes.Common, x.Classes.Base, x.Classes.Data, x.Constants, x.Types, x.Database.Common, x.Preferences, x.Tools.Mapping, x.Tools.DateTime, x.Tools.TryFinally, x.Tools.Json, x.Tools.Regex, x.Tools.IO, x.Tools.BitMask, DataModuleTextConstants; Share this post Link to post
Attila Kovacs 629 Posted November 23, 2023 Each unit name belongs to a new line, with groups separated by an empty line. Share this post Link to post
Uwe Raabe 2057 Posted November 23, 2023 11 minutes ago, Attila Kovacs said: Each unit name belongs to a new line, with groups separated by an empty line. As that is a very personal preference, a similar feature is implemented on personal request in UsesCleaner branch FlixEngineering. It is available in the public repository for all those having individual formatting requests. Note that MMX will most likely not contain these for the near future. Share this post Link to post
dummzeuch 1505 Posted November 23, 2023 (edited) 3 hours ago, Attila Kovacs said: Each unit name belongs to a new line, with groups separated by an empty line. Actually, instead of an empty line, it could be a comment with the group, e.g. uses // Windows group Windows.WinApi // vcl group vcl.bla, vcl.blub; So it doesn't look like somebody forgot to remove an empty line. Edited November 23, 2023 by dummzeuch 1 Share this post Link to post
haentschman 92 Posted November 23, 2023 (edited) 😢 I put this in the groups... Quote Winapi System.Win System Vcl Data FireDAC cx DM x x.Tools Frame Form after: uses System.Classes, System.SysUtils, System.Variants, System.Generics.Collections, System.Generics.Defaults, System.DateUtils, System.Math, System.StrUtils, Vcl.Imaging.pngimage, Data.DB, FireDAC.Stan.Param, FireDAC.Stan.Option, FireDAC.Comp.Client, FireDAC.Comp.Script, DataModuleTextConstants, x.Classes.Common, x.Classes.Base, x.Classes.Data, x.Constants, x.Types, x.Tools.Mapping, x.Tools.DateTime, x.Tools.TryFinally, x.Tools.Json, x.Tools.Regex, x.Tools.IO, x.Tools.BitMask, x.Database.Common, x.Preferences; What ist wrong? PS: 15.1.8 Edited November 23, 2023 by haentschman Share this post Link to post