TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Roll your own Ruby Web Framework in Half an Hour

63 点作者 svs超过 11 年前

5 条评论

jrochkind1超过 11 年前
It seems gauche to insult Rails for being bloated, while bragging that you can write your own framework in 43 lines of code -- while using ActionDispatch::Routing::RouteSet, a fairly complicated, very powerful, part of <i>Rails</i> which takes way more than 43 lines to express.<p>(735 lines, not counting any of it&#x27;s own dependencies inside Rails. <a href="https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/route_set.rb" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rails&#x2F;rails&#x2F;blob&#x2F;master&#x2F;actionpack&#x2F;lib&#x2F;ac...</a>)<p>Sure, you wrote your own framework in 30 minutes -- by using a part of Rails which many many developer-hours have gone into, over many calendar years. (<a href="https://github.com/rails/rails/commits/master/actionpack/lib/action_dispatch/routing/route_set.rb?page=7" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rails&#x2F;rails&#x2F;commits&#x2F;master&#x2F;actionpack&#x2F;lib...</a> history stops at rails3 four years ago, when they moved the router from one project to another... the actual history goes back further)<p>Rails may arguably be bloated, but as of Rails3 it&#x27;s also amazingly modular and decoupled, allowing you to use just the parts of it you want. And OP thought the Router was awesome enough to want to reuse it. At least give it the credit it deserves, for that, when you&#x27;re using Rails to write a framework you say shows how Rails is awful!
swanson超过 11 年前
The issue is that by the time you bring in an ORM&#x2F;database migrations, form builder, link builders, asset pipeline, admin panel, etc you have basically hobbled together your own ghetto version of Rails without the vast resources&#x2F;support that Rails has. One of the benefits of Rails is that it has all of those features mostly baked in - at the cost of some bloat.<p>But my project doesn&#x27;t need all that, you might say. Well, that&#x27;s fine, then use something like Sinatra. But I wouldn&#x27;t build a non-toy web application without the above things.
评论 #6297937 未加载
评论 #6296307 未加载
Jgrubb超过 11 年前
As a Drupal developer, I find it cute how you Ruby guys consider Rails to be massive and monolithic. You know nothing of massive and monolithic :)
评论 #6298228 未加载
评论 #6296894 未加载
评论 #6298302 未加载
SeoxyS超过 11 年前
For what it&#x27;s worth, I was dissatisfied with most Ruby frameworks (aka. Rails &amp; Sinatra), so when it came time to build up a massive project on a Ruby backend, I rolled my own minimal (&lt;1kloc) Ruby framework.<p><a href="https://github.com/kballenegger/kenji" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kballenegger&#x2F;kenji</a><p>I, too, find Rails to be a bloated mess. Here&#x27;s what I wanted out of my ideal framework:<p>- The &quot;framework&quot; has one single task: providing a DSL for routing requests, and dealing with the HTTP nitty-gritty.<p>- The default would be build for JSON APIs. The return value of routes gets serialized to JSON.<p>- Everything is explicit. No magic.<p>- You can organize you code in simple, maintainable units (files), grouped by functionality. (This is achieved through a tree routing structure, where controllers can pass &#x2F; forward certain routes to other controllers.<p>- Code can be namespaced, can be tested easily, can be scripted easily. Functionality does not depend on naming conventions.
评论 #6298858 未加载
ianb超过 11 年前
If you are curious about a roll-your-own article similar to this, but for Python: <a href="http://docs.webob.org/en/latest/do-it-yourself.html" rel="nofollow">http:&#x2F;&#x2F;docs.webob.org&#x2F;en&#x2F;latest&#x2F;do-it-yourself.html</a>