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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Making some Discourse code a little better

123 点作者 janerik超过 12 年前

4 条评论

EvilTrout超过 12 年前
A couple of weeks ago, I was talking to a friend about the impeding launch of Discourse. She asked me if I was worried that people would judge me for the code I'd written (although to be honest, you can't tell who wrote what since we reset our commit history when we launched).<p>The truth is releasing your code is a very scary thing to do. I knew some parts were good, some parts less so.<p>Posts like this (and their pull requests) have floored me. Grant did a fantastic job refactoring a large chunk of technical debt we'd acquired, and then took the time to write up why he did it in detail.<p>I really hope this trend of improving something and writing how you did it catches on. I want to see it in other people's code bases too!
评论 #5199177 未加载
octernion超过 12 年前
I really enjoyed reading this!<p>When Discourse was originally announced, I read this file (quite randomly), and was distressed at the complexity and length (even though I totally understand time constraints and the need to 'get it to work').<p>I had never heard of the Law of Demeter (<a href="http://en.wikipedia.org/wiki/Law_of_Demeter" rel="nofollow">http://en.wikipedia.org/wiki/Law_of_Demeter</a>), nor had I heard of Sandi Metz's rules for Rails development (<a href="http://gist.io/4567190" rel="nofollow">http://gist.io/4567190</a>), both of which put in concrete terms some of the lessons I've learned when maintaining Rails applications.<p>I'd love to see more of these!<p>Edit: After reading over the pull request, I admit I'm a little confused why the response code was refactored into 'perform_show_response' - this seems like the direct responsibility of this controller method (and isn't common or otherwise misplaced). Is there a reason why you moved it out?
评论 #5198795 未加载
评论 #5198767 未加载
tinco超过 12 年前
This post is great, I'd love to see more blog posts about refactorings of open source code on Hacker News.<p>It's good to be reminded of refactoring techniques, and to be reminded of what neatly refactored complex code looks like.<p>I think being able to refactor code, and make it look that good is a hallmark of a great programmer.
评论 #5199016 未加载
ericb超过 12 年前
Good overall, but is there justification for having consider_user_for_promotion called through a before_filter? It doesn't filter anything or redirect the request. It also doesn't retrieve instance variables for the request to process. You could theoretically put the whole method being refactored into a before_filter, but that's just a shell game.<p>I agree with making consider_user_for_promotion a standalone function. I like that because it is reusable, and self-comments the code.
评论 #5198808 未加载