Discussion:
order of definitions in class
(too old to reply)
mp
2016-12-12 22:21:02 UTC
Permalink
is there a standard practice re order of elements in writing a class?
eg
class definition
constructor(s)
Properties
Methods


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Marcel Mueller
2016-12-12 23:07:44 UTC
Permalink
Post by mp
is there a standard practice re order of elements in writing a class?
eg
class definition
constructor(s)
Properties
Methods
The language itself enforces no such restriction. And so probably every
programmer has its own slightly different standard.

Whatever order you use it will always have disadvantages in certain
cases. At the end the code should be readable and maintainable, no more
no less. Enforcing an order based on the object type will not improve
this in general. E.g. splitting fields and related properties (if auto
properties are not suitable) is counterproductive. The same applies to
other closely related class members.


Marcel
Arne Vajhøj
2016-12-13 01:09:38 UTC
Permalink
Post by mp
is there a standard practice re order of elements in writing a class?
eg
class definition
constructor(s)
Properties
Methods
The compiler does not care.

But I think most use one of these:

fields & properties
constructors
methods

and:

fields
constructors
properties
methods

Arne
mp
2016-12-13 11:36:04 UTC
Permalink
Post by Arne Vajhøj
Post by mp
is there a standard practice re order of elements in writing a class?
eg
class definition
constructor(s)
Properties
Methods
The compiler does not care.
fields & properties
constructors
methods
fields
constructors
properties
methods
Arne
thank you Arne and Marcel,
hope you guys don't mind all these beginner questions

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Arne Vajhøj
2016-12-13 23:47:21 UTC
Permalink
Post by mp
hope you guys don't mind all these beginner questions
The group exist to provide help.

Try to do some research before posting and include
sufficient information when posting questions. That
usually goes well with potential answerers.

Arne

Continue reading on narkive:
Loading...