ruby on rails - How do you name a function which turns other Boolean value to true? -


i have model , model has several attributes. want turn 1 of boolean attributes true based on other attributes.

let's have model called user , user has attributes like..

  • id (int)
  • name (text)
  • birthday (date)
  • legal_age (boolean)

i asked change legal age attribute, based on birthday. (if user 20 years old turn true, if not, keep false.) named function check_legal_age, because checks legal age column true.

however, 1 of colleagues advised me name vague , hard figure out function , kind of value function returns.

after conversation, decided name function make_legal_age_true, wordy straight-forward name. colleague suggested me name trufy_legal_age

is there conventional way name method makes intentions clear others reading code?

your colleague right check_legal_age not name, not because it's vague, per se, because it's misleading , therefore dangerous. seems imply object state being checked or validated, when in fact it's being altered.

convention method changes internal object state should "bang" ! method. naming method legal_age! gets point across setting boolean attribute true.

better if predicate method (the 1 returns true or false) ended ?. legal_age? , legal_age! seem crystal clear me.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -