Complete web apps in Ruby without using any framew

2019-03-02 18:14发布

I am a Ruby noob. Has any one in this community written a Ruby app without any frameworks? (edit:My goal is to write one on my own.)Tell us about your experience. How difficult is it? Whats the lowest abstractions you used? What are the pitfalls? Thanks.

2条回答
时光不老,我们不散
2楼-- · 2019-03-02 18:38

This ia a very, very broad question. Are you looking to write your own framework, or just a simple CGI-like application (you can do that with ERB quite easily).

The biggest pitfall I can see to not using a framework (including one that you've written) is that it will be much, much harder for other people to figure out what your code is doing, and why. Plus, you lose all the automated testing, data binding, packaging, document generation, and other goodies that frameworks tie together.

Of course, if you do all the tying-together yourself, you've just written a framework. :)

If not, you've written a horrible mess of spaghetti code.

What I'd do, since you're a beginning Rubyist, is read the Rails (or Sinatra) source, and try and figure out what it does. Not because it's necessarily a great example, but because your understanding of web frameworks will be a lot more complete by diving into a couple. And this is very, very valuable.

Edit:

I looked at a few of your other posts, and it looks like you're a student, so I'm going to caution you against writing your own framework, not because it's a bad idea per se, but because of what a software framework represents -- namely, the sum total of years of experience in working with language X.

Programmers are like beavers -- we want to build. We want to to build everything ourselves, always with the idea of fixing the shortcomings of the existing tools. While this is a very noble thing, it tends to lead people down the path of getting very little done, because they aren't willing to use tools that other people have written, often for what boil down to minor, cosmetic reasons. Younger coders are especially guilty of this, and I was no different -- I wasted literally years screwing around with writing webservers and database abstraction layers, instead of writing software that I could have made money with.

If I could go back and do things differently, I would have started contributing to the frameworks that already existed, rather than just trying to "do it right" from scratch.

Now, there is an exception to that rule of "use other peoples' work first", and that is when you've got the experience with the tools to know when it's time to build something new. DHH (the guy who started Rails) was a very long-time Ruby coder before he decided to write Rails.

As a Ruby newbie, you're probably better-served at reading what other people have cooked up, and patching/improving that, rather than just starting on your own. You'll learn more about the language, make a valuable contribution to the community, and give yourself some good resume fodder.

查看更多
别忘想泡老子
3楼-- · 2019-03-02 18:38

You ought to ask yourself why you want to do this. A simple framework like Sinatra really isn't going to get in your way. Is this just for learning purposes?

At the minimum, you should consider using the Rack middleware to make life easier for you - connect your app to Rack, and use Rack to host the site through Passenger, Thin, Mongrel, etc.

查看更多
登录 后发表回答