From: Lyndon Samson Date: 2005-11-07T12:22:28+09:00 Subject: Re: programming best practices On 11/7/05, swille wrote: > I have a couple of standard programming questions. The first is that > I often like to return true or false in a method when no other return > value is really needed. Is that bad form? I was talking to someone > the other day who said said something that made me think that maybe it > was. For example: > > def login() > rc = false > begin > perform action > rescue > rc = false > some error > end > > return rc > end > > I like that because it reads well when you use it > > if login > do_stuff > else > complain > end > Ruby doesnt have procedures, so every method call returns a value. Its just nil by default. Also, error conditions are usually best signalled with exceptions, which sort of make checking return values redundant. > My second question is this. I occasionally see stuff like > if -1 == result > Poor programmers do this to avoid accidental assignment :-) > rather than > if result == -1 > > What, if any, is the benefit of one over the other? > > Thanks > > -- Into RFID? www.rfidnewsupdate.com Simple, fast, news.