From: Silas Davis Date: 2010-09-17T20:48:43+09:00 Subject: Re: Use of ? in variable names Michael Brooks wrote: > I'm not intending the "?" to control the parser or anything. It's just > "decoration" to remind me that the variable or method is intended to be > treated like a boolean when I'm looking at my code. The "?" suffix is > simpler than a "is_", "has_" prefix or "_flag" suffix for labeling > booleans. I believe one or two Ruby book even recommend that methods > which act like booleans should end with names that have a "?". I would also support this, and I have another case. I often use the idiom exemplified by: EXTERNAL_COMMAND = lambda {|data| "command_name -abc #{data} -def"} or INCLUDE_RECORD = lambda {|record| (record[0] == "this") && (/.txt$/ === record[1])} Where I could make the two constants full-blown methods, but I really like the way ruby closures allow me to separate what are essentially methods into a form that is both lightweight and suggestive that they are not first-class citizens of my business logic. In the latter example I would really like to be able to write INCLUDE_RECORD? = ... In this case the naming convention would be exactly like that that is permitted and recommended for methods. I see no strong reason why this couldn't be allowed for all variable names. I assume currently the syntax: bool ? : Can be written: bool? : So I suppose it depends how sacred the latter case is considered. Personally I wouldn't mind if a space between the boolean and question mark was required. -- Posted via http://www.ruby-forum.com/.