• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Use of boolean flags  RSS feed

 
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the app I'm working on, we have a table class that displays data. The user can load and reload data at various times, calling the table's load() method. I need to do one bit of logic ONLY on the first time load() is called. I'm considering using a boolean flag so I can check whether or not it's the first. But I seem to recall a fellow programmer or two turning their nose up at using flags in general....

Any opinions out there?
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you don't have something that shows you the state itself,I think you don't have any way else
but don't let the flag to be global if you can.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A "flag" is just a boolean field, right? So what's to cock a snoot at?
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as mentioned above: if you can not check the state then you have to add a "flag".
perhaps you can "abuse" a different field ?
e.g.

if they keep their noses up.... just call it "state" instead of flag, make it an int and assign it another value after each "phase" (e.g. init, load, reload, delete, flush or wahtever you have) :-)

pascal
 
Gail Schlentz
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok - Thanks for your support, guys. I'm gonna go ahead & use the flag. I tried "abusing" an existing field, but it didn't work out. I think these people "learned" something about a particular situation where maybe using the flag was bad, & are trying to over-apply it.



Thank you for all the input - you guys rock!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!