dummzeuch 1628 Posted March 30 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 2133 Posted March 30 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 1973 Posted March 30 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 1628 Posted March 30 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 March 30 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 1628 Posted March 30 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 1973 Posted March 31 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 March 31 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 225 Posted March 31 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 March 31 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