5,207 karma · joined May 21, 2010 (16y ago) · 1,593 submissions
1201.
Show HN: The Obvious Architecture(obvious.retromocha.com ↗)
19 points · by programminggeek · 13y ago · 13 comments
comment 13y ago · link · parent
Take the money and run. Now it might be too late.
comment 13y ago · link · parent
Once you understand the concepts, you can whip up a simple crud app in a couple hours. Example app here: https://github.com/RetroMocha/obvious_status
comment 13y ago · link · parent
The best use of schema-less data storage I've heard of is Craigslist of MongoDB for their archives. Apparently migrations on their MySQL servers was taking way too long, and switching that system to Mongo made a lot of sense and apparently has worked out pretty well.
In the end it's about understanding the use of the right tool for the right job.
comment 13y ago · link · parent
The biggest reason to avoid schemas is to avoid schema migrations. On big enough datasets, they take a long time. That is not every app's problem, so it depends on your app. Also, not having a schema doesn't mean you completely avoid data migrations as a result of changing your schema in all cases.
comment 13y ago · link · parent
The biggest "problem" is that it will be harder to build as many giant media companies around general news distribution. On the other hand, a bunch of smaller players will have a chance to flourish. A lot like modern digital music.
comment 13y ago · link · parent
In the case of my example you could swap out the /delivery/web/app.rb or delivery/api/app.rb out for rails no problem. You wouldn't need to change any of the code in /app or /external to do so whatsoever.
Just because DHH thinks you should write your code one way and you don't agree doesn't mean you have to throw rails away entirely to have a different or better structure. Rails might be opinionated, but that's just like their opinion man.
comment 13y ago · link · parent
My side projects are where I have the most freedom and I just recently built and open sourced Obvious - http://obvious.retromocha.com. It makes it easy to build apps with good structure, good testing, and with pluggable front and back ends. So, if I want to switch out Mongo for MySQL or Postgres, it's basically painless.
comment 13y ago · link · parent
Nowadays, I have begun to defer my database choice until I absolutely have to put an app into production if possible. That way I can write an app and have it working without worrying too much about queries, caching, and so on until I need to actually put it out on a real server.
MySQL, Mongo, HBase, Cassandra, Postgres, Riak, Redis, Memcache, Couchbase, Filesystem? It doesn't matter.
They're all going to break at different times for different reasons depending on how you use them and what scale you are at. Everything breaks at scale eventually.
Build something awesome enough that it breaks under the user load. That's a good problem to have.
comment 13y ago · link · parent
I've been geeking out about software architecture and engineering lately to make TDD not suck, so I built Obvious to scratch my own itch. It's the most fun I've had building software in years. I don't know if anyone else is going to care, but I've enjoyed it immensely. http://obvious.retromocha.com/ if you're curious.
comment 13y ago · link · parent
comment 13y ago · link · parent
comment 13y ago · link · parent
You can go in the app/ directory of a project and read the file names of your actions and entities and know right away what the system does. Testing is fast because it never hits a database. Test doubles and mocking are easy to build and don't require a 3rd party lib. Data traveling between the app and the external systems is validated via contracts. It ends up being the most enjoyable TDD experience I've ever had.
For example, last night I put together an example "twitter" status update app in obvious. I got all the entities, actions, and contracts written TDD in about 3 hours. Today I'll be adding a delivery mechanism and probably filesystem and mysql plugs. Would be easy to write an api or console app and plugs for mongo, postgres, or whatever. Code is here: http://github.com/RetroMocha/obvious_status
comment 13y ago · link · parent
This is done via simple dependency injection, which is pretty standard in many other languages outside of ruby.
comment 13y ago · link · parent
If your models were just plain ruby objects that validate your data for you, your code is able to do more interesting things - like multiple persistence mechanisms, multiple delivery mechanisms. Oh and they can be incredibly fast to test from day one.
If you use a tool like Obvious (which I wrote), you can TDD from day one and still build things fast, while maintaining a good structure.
comment 13y ago · link · parent
I've got an example Obvious twitter close/status update app in progress at https://github.com/RetroMocha/obvious_status
Obvious is still super new and I'm working on documentation and examples. You can read more about Obvious at http://obvious.retromocha.com
comment 13y ago · link · parent
comment 13y ago · link · parent
1) Hiding persistance from the programmer by tying it to your models is a bad idea. It's where a lot of problems start. First, how do you test without hitting the database? How long do your tests take? Minutes? Hours? Or do you skip them?
I don't think your models should do persistance at all. They should model your data for you. Do validation against your business rules. That sort of thing.
Would you tie your models to the filesystem? If not, then why would you tie them to the database?
Pulling your persistance mechanism out of your models is the first step to writing fast, maintainable, highly testable code, even if you are still using rails.
2) Rails conventions want you to tie your DB to your objects, which is a bad idea. Rails does a lot of things well, like it gives you a nice structure for controllers, views, routing, asset management, so use it for those things. Rails is a delivery mechanism. Use it as one and leave data modeling and persistance to something else.
3) I think the name issue could be solved by treating it as "action" object. Think of actions as more like actors. They do things. They integrate models/entities and persistance mechanisms along with minor amounts of logic that don't fit inside of entities.
As an action object, you could all it CreateContact and it would be called create_contact.rb in the app/actions folder. Then, when you look in the app/actions folder, the file name communicates what it does - it creates a contact.
4) Actually, it helps a lot with testing. Creating a new class makes dependency injection super easy, making testing super easy and fast. Also, it can help with clarity and glance factor. Imagine you have an app/actions folder with files like create_contact.rb, remove_contact.rb, send_email.rb, get_contact.rb, compose_email.rb and so on. You look at that folder and you can see that it is probably an contact management and email app. Maybe an contact or newsletter management app?
That kind of glance factor you can't get with a bunch of higher level controller or service containers. It also avoids the problem of "what controller/module/service does this method belong to?"
5) I actually agree that the code that the OP did was not the best in that the persistence and email sending mechanisms aren't passed in to the action, so that you don't know what it is going to try and save and where. If the code explicitly passed in the persistence and email mechanisms it would be more apparent that an email is going to be sent as part of the CreateContact action. That being said, I would probably make those two separate actions for clarity's sake.
I've written some apps using the Obvious Architecture and it really does help solve a lot of the problems that default Rails MVC creates.
comment 13y ago · link · parent
In short, use your head. There is nothing wrong with breaking out this functionality into two actions.
comment 13y ago · link · parent
class CreateContact
def initialize contact_jack, email_jack
@contact_jack = contact_jack
@email_jack = email_jack
end
def do input
# validate input
contact = Contact.new
contact.populate input
contact_jack.save contact.to_hash
email = ContactEmail.new
email.populate contact.to_hash
email_jack.send email.to_hash
contact.to_hash
end
end
With that structure you can call CreateContact with: action = CreateContact.new
result = action.do ContactJack.new, EmailJack.new
In that structure you can totally test the action and logic without hitting the db or the mail system at all. Your ContactJack and EmailJack can be easily swapped out for various pluggable data stores. Fileystem, MySQL, Mongo, Postgres, Cassandra, could be swapped out for the ContactJack. EmailJack could send through standard mail servers, SendGrid, Amazon AWS, Mandrill, etc.Obvious is on github, you can read more at http://obvious.retromocha.com
comment 13y ago · link · parent
What the OP writes about is a good first step and frankly, is very close to right, but why stop there? Why not ditch ActiveRecord models all together and totally decouple persistance from the "app"? Honestly, the coupling of your models and logic to a database is really where most of this trouble starts.
In the Obvious architecture the app is separate from the delivery mechanism (rails/sinatra/whatever) and also from the external persistance mechanisms like databases, queues, caching, and so on. You can mix and match both delivery mechanism and persistance methods. So, you could write a CLI app against the filesystem and then make a rails web app with a mysql persistance mechanism without changing your "app" at all.
The whole thing is built from day one to be TDD and in a recent app I wrote, it has some 78 rspec tests that run in 0.03 seconds.
I'm in the process of documenting and open sourcing the whole thing. There is a project generator gem available now called 'obvious' and you can read more at http://obvious.retromocha.com/
When I have better documentation and examples available, I plan on posting to HN, but all questions are welcome.
comment 13y ago · link · parent
comment 13y ago · link · parent
Second, ARM chips are too cheap. Intel's biz is built on $100+ chips. ARM chips are like $10. If intel's chip prices drop to say $25, they don't have nearly the money for R&D.
X86 won't die, but it can't grow and over time that's going to hamstring Intel.
Call it peak x86.
comment 13y ago · link · parent
I'm all for pluggable protocols and standards, but Hypermedia links in your API don't magically get you there. They might help, but no more than a standard spec with standard URL patterns would.