dummzeuch 1608 Posted Sunday at 01:04 PM How do you think the following should be formatted? 1. Like this: type TClass = class(TObject) private FSomeField: integer; private const SomeConstant = 5; end; 2. Like this: type TClass = class(TObject) private FSomeField: integer; private const SomeConstant = 5; end; Note: This is only about code where the 'private const SomeConstant = 5;' is in one line without a line feed in between. And what about the following: 1. Like this: type TClass = class(TObject) private FSomeField: integer; private const SomeConstant = 5; FSomeOtherField: string; end; 2. Like this: type TClass = class(TObject) private FSomeField: integer; private const SomeConstant = 5; FSomeOtherField: string; end; Note: This is only about code where the 'private const SomeConstant = 5;' is in one line without a line feed in between. Share this post Link to post
Uwe Raabe 2129 Posted Sunday at 02:18 PM Are you aware that your second example won't compile? It needs an additional var keyword between the constant declaration and the following field declaration. 1 1 Share this post Link to post
Anders Melander 1951 Posted Sunday at 03:03 PM type TClass = class(TObject) private FSomeField: integer; private const SomeConstant = 5; private type SomeType = integer; private class var SomeClassVar: integer; end; etc. etc. 2 Share this post Link to post
dummzeuch 1608 Posted Sunday at 03:26 PM 1 hour ago, Uwe Raabe said: Are you aware that your second example won't compile? It needs an additional var keyword between the constant declaration and the following field declaration. No, I missed that one. This is a contrived example not real code, personally I always put a line feed after the visibility modifier and rather than using var I start a new visibility section. Share this post Link to post
Darian Miller 381 Posted Sunday at 04:03 PM 57 minutes ago, Anders Melander said: type TClass = class(TObject) private FSomeField: integer; private const SomeConstant = 5; private type SomeType = integer; private class var SomeClassVar: integer; end; etc. etc. My preference would be similar, but I'd start with private const and end with private fields. 1 Share this post Link to post
dummzeuch 1608 Posted Sunday at 04:11 PM Just to be clear: I'm not asking whether you like the 'private const bla=blub;' in one line syntax, but how it should be indented: 1. like 'private' on its own line -> same indentation as the class/record 2. like other constants / fields / types -> one indentation more than the class/record I assume that most (including myself) would like to split that line (whether between 'private' and 'const' or between 'const' and the identifier would be yet another point for debate. 1 Share this post Link to post
Anders Melander 1951 Posted yesterday at 08:51 AM 16 hours ago, Darian Miller said: I'd start with private const and end with private fields. Me too - and I would most often also start with the class vars and types. Of course it depends on the size and structure of the class; For a large class I would probably try to keep associated stuff close together as an overriding principle. Share this post Link to post
EugeneK 23 Posted yesterday at 03:46 PM I think more consistent with Embarcadero style will be following, since there could be multiple consts/types/vars TClass = class(TObject) private FSomeField: integer; private const SomeConstant = 5; SomeOtherConstant = 6; private type SomeType = integer; SomeOtheType = string; private class var SomeClassVar: integer; SomeOtherClassVar: string; end; 1 Share this post Link to post
DelphiUdIT 218 Posted yesterday at 04:53 PM I will write in that way, I mean that I add identation for everything is inside the class definition. I find it very comprensive simple to view, with very long definition too. But surely it is 'cause I'm old ... type TClass = class(TObject) private const SomeConstant = 5; SomeOtherConstant = 6; private type SomeType = integer; SomeOtheType = string; private class var SomeClassVar: integer; class var SomeOtherClassVar: string; private FSomeField: integer; end; Share this post Link to post
Zane 3 Posted 20 hours ago 7 hours ago, EugeneK said: I think more consistent with Embarcadero style will be following, since there could be multiple consts/types/vars TClass = class(TObject) private FSomeField: integer; private const SomeConstant = 5; SomeOtherConstant = 6; private type SomeType = integer; SomeOtheType = string; private class var SomeClassVar: integer; SomeOtherClassVar: string; end; This is the style that pasfmt uses. It's most consistent to break after every visibility specifier because it does start a new section, and there may not be a visibility specifier before the next section: type TClass = class(TObject) private const SomeConstant = 5; type SomeType = integer; end; 1 Share this post Link to post