I don't like it, maybe...
Massimo Morin
mmorin at schedsys.com
Fri Jan 21 22:26:22 GMT 2000
Hi,
as said I do not have the code working yet but:
> 1. The Get/Set pair gets constructed as an option. Some member variables
> are truly private and for our eyes only.
>From the doc :
/**
This is the holder of the rules and the one that apply the rule to
the member or method passed.
Basically it prepend or postpend to the "string" inserted some
information that will help to document and autogenerate the code.
This rules are going to be applied when the Kdevelop dialog will
popup a "Add Member".
The options available are, in that case:
[1] Apply style rule
[2] Create accessors
[3] Create boolean Is accessor
[4] Pass to constructor as parameter
[5] Use default value on inizialization
[6] Initialize in constructor
We can have rule for creation of a method too, but in this case we
will
have only the check box for
[7] Apply style rule
Example:
we want to add a member "member" of type "int" to the class MyClass,
but in our coding
standard (at least in mine), it has to have a prepending m_ .
We use prepending Get for retreiving the value, and prepending Set
for setting the value with capitalize first latter of the string
used.
What we check are all the 6 rules.
What the set of rule will generate:
// .h file
MyClass(...., int member = 0);
const int GetMember() const { return m_member; }
void SetMember(const int member) { m_member = member; }
// This is generated by kdevelop!
int m_member;
// in .cpp
MyClass::MyClass(...., int member /* = 0 *\) {
....
m_member = member;
}
oops by now I have to get on hold the IsMethod. It is too messy to
work on...
but it should do
// .h file
MyClass(...., bool isMember = false);
const bool IsMember() const { return m_isMember; }
void SetMember(const bool isMember = true) { m_isMember = member; }
// This is generated by kdevelop!
bool m_isMember;
*/
...........
/*
*--------------------------------------------------------------
*
* RuleActivator::GenerateConstructorDeclaration --
*
* Declare the constructor form
* we can have 4 cases
*
class Foo { class Foo { class Foo { class Foo {
public: public: public: public:
Foo(int foo = 0); Foo(int foo); Foo(); Foo();
private: private: private: private:
int m_foo; int m_foo; int m_foo; int m_foo;
} } } }
Foo::Foo(int foo /* = 0 *\) { Foo::Foo(int foo) { Foo::Foo() {
Foo::Foo() {
m_foo = foo; m_foo = foo; m_foo = 0; // Initialization
missing: m_foo = ??
} } } }
The variable used are:
[1] Pass to constructor
[2] Initialize with default
case 1 we have [1]=true [2]=true
case 2 we have [1]=true [2]=false
case 3 we have [1]=false [2]=true
case 4 we have [1]=false [2]=false
*/
> 2. This looks sticky for situations where the user has multiple constructors
> for the class.
oops, didn't considered this BUT, why not use the initialization only on
the FIRST constructor defined.
Usually I do:
1) basic constructor (as empty as I can)
MyClassThatCreateAPair(int a, int b=0);
2) special constructor
MyClassThatCreateAPair(Pair<int> a);
3) the copy constructor
MyClassThatCreateAPair(const MyClassThatCreateAPair &myClass);
.. well any other suggestion/modification when I will have some code
working (by monday I hope).
> Also some questions:
> 1. Any idea how you would handle situations where the new member variable
> gets initialized by a constructor arugment? ex.
> class foo{
> public:
> foo( int arg1 ) : m_myInt( arg1 ){}
> private:
> int m_myInt;
> };
Prefer to move in the .cpp file as a regular statement. Do not like much
empty constructor, and if you have a pointer to allocate...
BUT to investigate also.
> 2. How do you intend to handle naming of the values? I myself hate the
> words Get/Set for values. A lot of times I prefer the following
>
> class foo{
> public:
> foo(){}
> int myInt() { return m_myInt; }
> void myInt( const int value ) { m_myInt = value; }
> private:
> int m_myInt;
> };
>
> Not to get into a semantics war, but how do you propose to handle this
> situation when dealing with the likes of me?
Ok the rule is defined as following:
class Rule {
....
private:
AttachPosition m_attachPosition; // where to attach before name, or
after
AttachData m_attachData; // what to attach, a string, nothing or
the type
QString m_attachValue; // the value to attach when usign a string
type
AttachTo m_attachTo; // to which element to attach: meber,
getAccessor, setAccessor, slot signal etc..
AttachModifier m_attachModifier; // it is private, public, protected,
or any type is valid
bool m_isStatic;
bool m_isConst;
bool m_isVirtual;
bool m_isPure;
AttachCapitalization m_attachCapitalization; // capitalize first, last
letter, all the attached one..
...
}
so in my case the Set/Get accesor rule for the member "myInt" that want
to be m_bar
prepending string m_ member any NO NO NO NO NONE
prepending string Get GetAccessor any NO NO NO NO firstLetter
prepending string Set SetAccessor any NO NO NO NO firstLetter
Will have
void SetMyInt(const int myInt) { m_myInt = myInt; }
const int GetMyInt() const { return m_myInt; }
int m_myInt;
In your case:
prepending string m_ member any NO NO NO NO NONE
prepending NONE EMPTY GetAccessor any NO NO NO NO NONE
prepending NONE EMPTY SetAccessor any NO NO NO NO NONE
We will have:
void myInt(const int myInt) { m_myInt = myInt; }
const int myInt() const { return m_myInt; }
int m_myInt;
Ok, now I don't know if m_myInt=myInt is accepted by the compiler or
barfed out with
"() missing in line ..."
Solution can be postpending Value to myInt when it is used as a
parameter: we will see.
>
> Again, good idea. I'm just curious to see what direction you see this
> feature going in.
I'm curious too
We will see.
Cheers
Max
> -----Original Message-----
> From: Mailing list agent [mailto:mdom at barney.cs.uni-potsdam.de]On Behalf
> Of Massimo Morin
> Sent: Friday, January 21, 2000 9:59 AM
> To: kdevelop
> Subject: I don't like it, maybe...
>
> Hi,
> time ago we were talking about coding standards and accessors of
> member-variable, and how it could be a good idea to customize the code
> generated by kdevelop.
>
> Sincerelly, I do not like the code it generates because it doesn't fit
> my conventions, so I have to reedit all the code and adjust it.
> Most of the time when I add a member to a class I write the Get/Set
> function and I initialize it into the constructor too.... and this is a
> very boring and automatic operation :(
>
> Well, I was thinking: why don't we set some user defined rule to apply
> everytime we create a member variable or a member method for a class?
>
> Is there anyone working on something like that??? (Jonas are you
> there??)
>
> I played a little with this idea and I like it so I wrote a couple of
> classes.... during the week-end I hope to debug them and excercice it a
> little.
>
> If there is some interest and no one has alredy implemented it, I'll try
> to integrate it into kdevelop.... otherwise ... it was a good exercice
> for myself.... :)
>
> Let me know.
>
> Max
> --
> _...__..-'
> Massimo Morin .'
> mmorin at schedsys.com .'
> +1 (617) 484 2999 .'
> .'
> .------._ ;
> .-"""`-.<') `-._ .'
> (.--. _ `._ `'---.__.-'
> ` `;'-.-' '- ._ Scheduling Systems Inc.
> .--'`` '._ - ' . Three University Office Park
> `""'-. `---' , 95 Sawyer Road
> ''--..__ `\ Waltham, 02453 Massachusetts USA
> ``''---'`\ .' +1 (781) 893-0390 x 126
> `'. ' http://www.schedsys.com
> `'.
--
Massimo Morin _...__..-'
mmorin at schedsys.com .'
(617) 484 2999 h .'
(617) 512 0203 c .' Airline
.' Solutions
.------._ ; Today
.-"""`-.<') `-._ .'
(.--. _ `._ `'---.__.-'
` `;'-.-' '- ._ Scheduling Systems Inc.
.--'`` '._ - ' . Three University Office Park
`""'-. `---' , 95 Sawyer Road
''--..__ `\ Waltham, 02453 Massachusetts USA
``''---'`\ .' +1 (781) 893-0390 x 126
Senior `'. ' http://www.schedsys.com
Software Engineer `'.
More information about the KDevelop
mailing list