Hey all, I wanted to see if my opinion jives with what everyone else is thinking. I usually append ''?'' to a method name when it is returning a boolean answer. I append ''!'' to a method when it is some kind of "finalized" move. For instance, I have methods like ''create_article!'' where I use the ! as a reminder that the method takes care of calling .save on the created object instead of passing the new object back to the caller. These ''!'' methods return the result of the .save call. Is that a correct understanding/usage? Are there any other "naming conventions" for methods along these lines? Thanks, Jeff
Jeff Casimir <jeff-+RlNNtFrnNmT15sufhRIGw@public.gmane.org> writes:> Hey all, > > I wanted to see if my opinion jives with what everyone else is > thinking. I usually append ''?'' to a method name when it is returning > a boolean answer. I append ''!'' to a method when it is some kind of > "finalized" move. For instance, I have methods like > ''create_article!'' where I use the ! as a reminder that the method > takes care of calling .save on the created object instead of passing > the new object back to the caller. These ''!'' methods return the > result of the .save call.Generally, "!" corresponds to a "destructive" action. That is, Array.sort returns a copy of the Array sorted (leaving the original untouched), whereas Array.sort! actually (destructively) modifies the array being sorted. -- I tend to view "truly flexible" by another term: "Make everything equally hard". -- DHH
Using ? for booleans is correct. The ! is usually used in Ruby to indicate that the method changes the object it is being called on, rather than returning a modified copy. So using it as you describe could be a bit misleading for people experienced with Ruby, I''d create methods like create_and_save_article instead. Cheers, Colin On 03/08/05, Jeff Casimir <jeff-+RlNNtFrnNmT15sufhRIGw@public.gmane.org> wrote:> Hey all, > > I wanted to see if my opinion jives with what everyone else is > thinking. I usually append ''?'' to a method name when it is returning a > boolean answer. I append ''!'' to a method when it is some kind of > "finalized" move. For instance, I have methods like ''create_article!'' > where I use the ! as a reminder that the method takes care of calling > .save on the created object instead of passing the new object back to > the caller. These ''!'' methods return the result of the .save call. > > Is that a correct understanding/usage? Are there any other "naming > conventions" for methods along these lines? > > Thanks, > Jeff > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >