News for hackers. Stuff that matters.
Re:The M in MVC: Why Models are Misunderstood and Unappreciated by Volpe on Tuesday July 26, 2011 @07:18AM (#2806830)
Really? Throwing exceptions on known states of your model... hardly exceptional.
Re:The M in MVC: Why Models are Misunderstood and Unappreciated by glenjamin on Tuesday July 26, 2011 @08:04AM (#2806948)
How else would you achieve it - throwing exceptions for program flow is quite common in Python for example; Iterator.next() throws StopIteration when it reaches the end of the iterable.
Re:The M in MVC: Why Models are Misunderstood and Unappreciated by Volpe on Tuesday July 26, 2011 @08:30AM (#2807003)
That's an exceptional circumstance, the iterator is not responsible for knowing whether you have reached the end of the collection.

You could achieve it by catering for these cases in your logic if user.authorize(email, pass): ... success ... else: ... fail ...

rather than try: user.authorize(email, pass) ... success ... except WrongPasswordException: ... fail ...

Re:The M in MVC: Why Models are Misunderstood and Unappreciated by glenjamin on Tuesday July 26, 2011 @08:54AM (#2807057)
I see your point, I didn't notice that the parent mentioned WrongPasswordException, when I implemented something similar previously it looked like this:

User.authorize(username, password) -> Returns true if valid username/password -> Returns false if username/password do not match -> Raises AccountDisabled if username/password valid but account disabled

The normal login failure case is not exceptional - but the others are.

Re:The M in MVC: Why Models are Misunderstood and Unappreciated by bergie on Tuesday July 26, 2011 @09:53AM (#2807309)
Agreed, that is a better scenario.

Then again, stuff like authentication and authorization (two separate concepts!) are often better handled on some middleware or service layer than in models and controllers.