News for hackers. Stuff that matters.
Re:Invalid Object Is an Anti-Pattern by rubiquity on Wednesday December 30, 2015 @09:31AM (#10812150)
I think I'd rather just use a language with a good type system than write Ruby in that sort of style. The value of types is greatly diminished if there isn't a compiler to make all sorts of wonderful optimizations and find bugs for you. At least until Ruby the language implements gradual/soft typing directly.

The library mentioned also raises exceptions for bad input. Unfortunately, exceptions cripple the runtime performance of Ruby so I wouldn't consider that a smart thing to do.

Re:Invalid Object Is an Anti-Pattern by solnic on Wednesday December 30, 2015 @10:05AM (#10812296)
You'd get these runtime exceptions anyway, but they would be obscure and often hard to debug. Once you define core objects in your system that you construct from external sources (like a database) you establish a contract that the source is trusted and it's expected to provide valid data. If that doesn't happen, for some reason (and it happens), you want to see it as early as possible and a meaningful error can be very helpful.

This obviously doesn't come even close to a statically typed language but I believe it's a huge improvement over the typical approach in Ruby where you...just don't care and hope for the best ;)

Re:Invalid Object Is an Anti-Pattern by rubiquity on Wednesday December 30, 2015 @10:41AM (#10812452)
> You'd get these runtime exceptions anyway, but they would be obscure and often hard to debug.

Only if you use the bang versions of save/update/create, which I don't.