Naming conventions for bool methods?

M

Markus Dehmann

BTW, how do you handle naming conventions for getters/setters of bools? I
use is/set, but it sounds stupid sometimes:

boolean dataInited;
boolean isDataInited();
void setDataInited(boolean inited);

Or worse:
boolean useMagicAlgorithm;
boolean isUseMagicAlgorithm();
void setUseMagicAlgorithm();

I could say
boolean usingMagicAlgorithm;
boolean isUsingMagicAlgorithm();
which would sound better.

Any help appreciated!
Markus
 
R

Ryan Stewart

Markus Dehmann said:
BTW, how do you handle naming conventions for getters/setters of bools? I
use is/set, but it sounds stupid sometimes:
[...]
is/set is the standard way of doing it. If your variable names don't work with
it, they probably need changing.
 
A

Andrew McDonagh

Markus said:
BTW, how do you handle naming conventions for getters/setters of bools? I
use is/set, but it sounds stupid sometimes:

boolean dataInited;
boolean isDataInited();

or..

boolean hasDataBeenInitialised()
void setDataInited(boolean inited);
DataInitialisationIs(boolean initialised)
Or worse:
boolean useMagicAlgorithm;
boolean isUseMagicAlgorithm();

boolean shouldUseMagicAlgorithm();
 
R

Ryan Stewart

[...]
boolean hasDataBeenInitialised()
[...]
DataInitialisationIs(boolean initialised)
[...]
boolean shouldUseMagicAlgorithm();

[...]
You can certainly name your methods anything you like, but a tool/library such
as JSTL that looks for getters and setters wouldn't find these.
 
A

Andrew McDonagh

Ryan said:
[...]
boolean hasDataBeenInitialised()

[...]

DataInitialisationIs(boolean initialised)

[...]

boolean shouldUseMagicAlgorithm();


[...]
You can certainly name your methods anything you like, but a tool/library such
as JSTL that looks for getters and setters wouldn't find these.

Correct, but the OP wasn't asking about that - was they?

I just thought they wanted some examples of what others here had used
before.
 
R

Ryan Stewart

Andrew McDonagh said:
Correct, but the OP wasn't asking about that - was they?

I just thought they wanted some examples of what others here had used before.
He didn't ask for anything more specific than "naming conventions". I was simply
pointing out that there may be other considerations than what you or I think
looks "nice".
 
J

Joona I Palaste

Ryan Stewart said:
You can certainly name your methods anything you like, but a tool/library such
as JSTL that looks for getters and setters wouldn't find these.

That's just stupid practice, I think. Even in Log4J the parameters for
logger and appender implementations are handled by creating methods
named "get..." or "set..." followed by the parameter name. I haven't
looked at the Log4J source, but I am fairly sure it uses Reflection to
handle the method invocations. If I had designed the API, I would have
made only two methods:
void setParameter(String name, Object value);
Object getParameter(String name);
 
A

Alan Krueger

Markus said:
BTW, how do you handle naming conventions for getters/setters of bools? I
use is/set, but it sounds stupid sometimes:

boolean dataInited;
boolean isDataInited();
void setDataInited(boolean inited);

How about simply "isInitialized"?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top