195 points · by anthony_franco · 14y ago · 96 comments
Why are they even bothering? Really, who cares about PATCH vs. PUT? If PATCH even has a remote chance of breaking 0.01% of sites, then WHY do it? PUT works fine. I don't care. I don't care either way, actually, since I don't use Rails anymore, just put PATCH in.
But my main concern is: Why is this major blog post worthy for Rails? I want to see something like "Rails 4: Damn Simple Websockets" or something to show that Rails is modernizing. I spent some time playing (read: nothing serious) with Lift and Scala, and while I wouldn't use that full time, it is clear to see that Lift has a handful of features that are just amazing for a modern website that Rails completely lacks (ridiculously simple AJAX/websocket stuff, triggering UI elements based on data model changes in the backend, etc.).
Anyways, its so early that Rails 4 is still a big unknown, but this is not the PR start I would've liked to see.
Any web framework has the duty to use and promote proper HTTP usage. Pushing PATCH over PUT we are doing that.
This change is not the entire Rails 4.0, it is only one change in Rails 4.0. Rails 4.0 has still a long way to go.
And of course, there are going to be practical improvements as there have been in all major (and indeed minor) versions. We will do practical improvements as well as being better HTTP citizens.
PATCH has the same idempotent requirement. It isn't simply some more generic version of PUT intended for generic CRUD updates. As I understand, it is a specific way to submit a "diff" of a resource to "patch" it so to speak.
PUT/PATCH verbs as far as HTTP/REST is concerned seem to have been designed with literal management of resource data/state in mind. The primary scenarios I can think of that require their use are things like blob storage APIs and perhaps other types of direct content management scenarios. It just doesn't seem appropriate as the general "update" mechanism that Rails is trying to make it out to be.
I'm not saying the Rails way of doing CRUD is bad. It's a handy abstraction and pattern that works fine for many, even most, cases, but as far s REST goes, Rails is really just RESTful theatre. From what I can tell the most RESTful thing Rails could do is just use POST by default everywhere and provide a convenient way for the developers to use PUT/PATCH where and when it truly makes sense.
The PATCH method thing only becomes relevant in conjunction with APIs where I would hope that you have enough control over your environment to not having to deal with broken proxies.
On the upside, using PATCH instead of PUT, in the context as PUT is used most often these days (partial updates) is more compliant with HTTP which says that the body of a PUT request should contain the whole resource, not just parts that change.
In a good majority of API cases the correct method is POST, even for so-called updates. Because, generally speaking, it is the controller that decides what happens to state when processing the request in Rails and if and when there will be side effects. Unless you can be certain the client will decide 100% of the result of the state PUT and even PATCH are just not technically correct.
PATCH is arguably better suited than PUT here but again why the strict adherence to one or the other for updates, when quite possibly neither is correct. Why PATCH by default? Why not just POST by default, PATCH/PUT where they make sense? In the end there is nothing specifically RESTful about Rails, it has no real resources or hypermedia to speak of so I can understand why people would question the real value of this move.
Lots of people care. It's about following existing standards to allow for more predictable behavior. What if people didn't care about status code 200 vs 404?
And if you don't care... what's with the rant?
Assume I'm stupid.
Explain to me, but don't stop at "because it's more compliant to the HTTP Standard" / "because thus it has been written in the scriptures" mustn't be the fundamental reason to do something.
Similarly, "it is Good to be compliant with the HTTP Standards in this case, because in other cases it was Good also"--certainly I can understand that being compliant with the 200 and 404 status code is a Good Thing.
But is there any other, tangible reason why a Rails project would benefit from now using PATCH instead of PUT? Some interoperability with another existing framework maybe? Or interoperability with a hypothetical future framework? What other kinds of software would need to be changed and used before it'll provide a tangible benefit to a Rails project that uses PATCH vs a Rails project using PUT?
BTW I'm not arguing against standards (I know, I said you may assume I'm stupid, but no need to go all out ok?), I'm just genuinely curious if there is any other benefit, real, future, hypothetical or imaginary, other than "it's more compliant, and being compliant is good".
Actually even if that is the only reason, that's nice, it makes things neater and that's also good. But it would be kind of thin.
PUT is A) idempotent (meaning that repeated operations have the same result), and B) always replaces the entire resource (and by implication should contain the entire new resource).
PATCH is A) not idempotent (meaning that repeated invocations could have different results), and B) affects part or all of the resource.
So, an immediately obvious benefit[1] is that PATCH requests are potentially much lighter-weight.
[1] Aside from conceptual clarity which I frankly cannot fathom reasons for arguing against, yet many do…
It seems like the post is intended to highlight a high quality commit which somebody worked hard on, as well as prepare the community for a semantic change. It may not be worth touting as much as a competitive feature, but it certainly deserves it's place in the feed.
But really, the only thing that bothers me with this post is the under-developed blog it's been running on for years (ie.: no simple way to get to archives, next or previous post, etc).
Advocating against PATCH is near to advocating against the introduction of RESTful routes and controllers, which was a crucial gain for Rails (even though they probably got the hint from Django?).
P.s.: Socket.io isn't part of Node.js core either. There are implementations in Ruby, but why not just use Node and Socket where appropriate?
Well, this "if it even remotely breaks 0.01%" and "I don't care" attitude is the main reason things get bloated and stop progressing.
There's still serious performance regressions.
The asset pipeline is still sort of a trainwreck.
There's still no automation for schema migrations (perhaps hobo fields will finally bring some relief for those who adopt it).
They still don't seem to have realized that code generators are a no-go.
I see zero efforts towards modernizing the bloated routing and MVC cruft to accomodate modern fat-clients (and imho the "resources"-magic was a terrible idea from the start even for regular apps).
The whole thing is still riddled with ungodly amounts of magic that likes to break in unpredictable ways (my pet bug: the monkey-patch to really suppress browser stack-traces in production changes about every 3 months and it's worrying such a bug was deliberately created in first place).
I could go on for a while... </rant>
It's beyond me why rails thinks it should dictate how to write/manage/package javascript.
As a newbie-ish javascript developer I am continually learning from great projects like requirejs, enderjs, nodejs, commonjs (AMD in general), backbonejs, etc.
How arrogant do rails programmers have to be to dip their hand into javascript best practices? Honest question, because the better I get at programming the more I feel like rails is less necessary.
An insistence on handling all things with Ruby is why things get bloated and stop progressing.
Sprockets solves a pain, I admit, but at the cost of adding ruby bloat to all thick client code.
Instead of being able to use javascript libraries with one another natively, everything goes through Ruby.
Anyways, I'll probably get downvoted for this comment by Railers because this is somewhat OT and trollish (I admit), but it's a legitimately complaint about the direction of Rails.
I think Rails has lost sight of what it does really well, server-side logic. Rails, in v4.0, needs to adopt a symbiotic relationship with thick-client javascript instead of trying to consume it and insert ruby in-between all the javascript parts.
For example, right now, the recommended place for a backbone.js app in a rails project is /app/assets/javascripts/. That "folder" is only going to grow as the client-side javascript becomes more important. Keeping the javascript logic "subordinate" to the Ruby elements in a Rails project causes more bloat than anything else. Look at any thick-client Rails project and count the number of gems managing javascript. If there are more than two or three, you've probably got a separation of concerns issue at the language level. That's bloat.
If you want to down vote me, go ahead. I just ask that you have the courtesy to defend your down vote with a comment. If you think I'm wrong tell me why. Maybe, I'm doing something wrong.
I have no idea what this means. how is it subordinate? The location on the filesystem?
"Look at any thick-client Rails project and count the number of gems managing javascript"
I've made a few that have no gems managing javascript. They talk to rails via REST. Rails doesn't need to care about them, and they don't need to care about rails.
You can still do that, you can turn the asset pipeline off and just throw everything in /public like normal if you want.
Re: "through Ruby." If you meant that the body of the CSS file is generated for a request by running through the ruby interpreter, that's not true.
I code with Rails. With Rails 3.2, I'm more productive than I've ever been. What others call "bloat", I call "features". It is surprisingly good having an out of the box asset pipeline for optimization of JS/CSS. The simplicity with which you can construct and adjust scoped queries with ActiveRecord is astounding. The ease of adding pre-baked authentication and authorization gems is great.
Seriously - screw writing a large data-driven web app in a tiny framework. You get so much for free in Rails.
Yes, Rails has some issues. It has a long initial load time. Ruby is not the fastest language. My main complaint about Rails at the moment would be that it moves too quickly - not that it moves too slow. If you're writing an app to service millions of users simultaneously (and not charging for it), the speed might be an issue. I haven't found it to be a problem in my company, where we charge money for what we write.
And on this change - I'm not fussed either way, but it's certainly good that Rails core mention this on the Rails blog so that Rails developers are aware of it well before 4.0 comes out. And standards compliance is a good enough reason for me.
If you want to make a drum machine that runs in your browser, like Giles Bowkett, then perhaps Ruby on Rails is really not good for you. On the other hand, if you want to earn a living, then the tremendous ease with which you can produce a reliable, secure, and full-featured application with Rails is really quite astounding.
I do think that some of the criticism around the thick-client support in Rails is justified, however. Rails was ahead of the pack when it came to AJAX support in the early days, but it is not leading the way when it comes to thick-client architecture. At the same time, however, when the core developers announced that Rails would default to Coffeescript, half of the developer community freaked out, including many people here on HN. At this point, there are so many people with a stake in Rails it is impossible to please them all.
I'm very happy with where rails is at right now. I feel incredibly productive with it. I get to play with new fancy stuff because I know it's still there to bail me out and get it done fast when I need to.
I find neither a suit nor skinny jeans comfortable. Instead rails fits like a well worn in pair of jeans and a plain old t-shirt. Sell the hipster crap somewhere else.
Also, it's standardizing the language that developers are using to interact with each other, and reducing the amount of work needed to build interoperable software. As more and more websites turn into web services (even if those services are only consumed by e.g. client-side Javascript), this should result in cost savings and faster time-to-market as more businesses move in that direction.
Finally, a lot of web apps are basically just CRUD (create/read/update/delete) apps. The more we standardize the on-the-wire protocols for these routine operations, the more we can push those protocols into application frameworks. This means that, as developers, we can work on things that are actually valuable, rather than coming up with new, site-specific ways of shuffling this data around the network.
Edit: I just noticed that RFC 2616 mandates write-through behavior: http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13...
https://github.com/rails/rails/issues/348
https://github.com/rails/rails/pull/431
Ideally you wouldn't need to do partial updates and just send the entire resource; your resources shouldn't be so big that that's an issue. It's much simpler than making the front-end decide when to do full versus partial updates and which method to use.
Rails can't really do that though, too much legacy code out there, too many people set in their ways. Resorting to PATCH is their only option if they want to use HTTP correctly.
I had actually thought to try to use a Rails-based REST service in the future, because I thought it would be quicker than rolling my own again (I had no choice, honest!) but without partial updates, I couldn't use it.
> "Rails to use PATCH instead of PUT" Http nerds annoy me
> "it's actually doing is un-breaking HTTP caching
> and proxying semantics" ... roll eyes
- ryah
https://twitter.com/ryah/status/173683063371464704In fact, I would argue that things like put/patch/_method are what make Rails so great. Rails makes a lot of strong opinions (put, whoops no, patch!), but then at then end of the day always gives you a way (_method) to deal with any issues where their opinions may not work in your current architecture. This pattern appears throughout the framework and is one of the reasons I really enjoy Rails.
Imagine if this was "we are using a new non-HTTP network protocol, and the answer to "how will you get it through proxies" is not "we tested it: it works" but instead "we have a way to tunnel it over HTTP"... that is a non-answer that undermines the entire purpose of having a new protocol, and restating it with pointlessly denegrating statements about people who don't know about the tunneling system doesn't help: it just makes the feature that much more questionable. :(
I think what you're saying though is that the downsides are. You may be right on that, but I'm going to withhold judgement until I really figure out what this means.
The way I've understand it is that GET is for reads (which are always idempotent), PUT is an idempotent write and POST is a non-idempotent write. I don't see what PATCH adds over POST.
(commented this on the article as well)
Playing with rails for more than 3 years, and then suddenly something new comes and hits you is obviously going to hurt. Let me start with the Assets Pipeline, and in particular - style & script.
Did you feel that it is important to control the no. of bits and bytes going into your css now? Until Sprockets came by, people would drop a load of crap in the public/stylesheets (bloated with properties !importants and all).
Continuing this way, is going to affect your app's responsiveness on new landscapes - aka tablets, hand-helds especially if you're thinking about "app-development with non-native approach" in your mind.
I mean it's not about syntactic sugar alone. It's about the ability to see what can be removed completely from the code and dried up to give desired result with maximum re-usability.
Now I'd credit this to the "direction of rails" which served SASS/SCSS or coffeescript as default. It forced me to think and add programming logic into style. Personally, I like it.
Also what fails me, is the classic nodejs vs Rails war. Let me re-word this: It is a classic unfounded flame-war, as described in HN guidelines. Both technologies have a place and are useful for even more mutually-exclusive scenarios. Why compare?, just do you own thing!
To sum it up - there is a need to take a step back and consider the idea "you wouldn't bump on something new thing or useful with status quo." I would definitely like to consider PATCH over PUT.