我希望Ruby程序员一年前就告诉我

What I wish a Ruby programmer had told me one year ago

One year ago, I started coding for real again. I dumped wasting times on stupid games and so on. I like building websites, so I started by going back to the roots. HTML & CSS which I had coded when I was about 10, and it didn't take me long before I had moved from tables to div tags and all. I learned myself to hand-code it, and not rely on software like Dreamweaver. Resulting in better, more compact and valid HTML. I had played around with PHP when I was about 11, so I decided to build some stuff in it again.

一年前,我重新开始真正的编码。我不再浪费时间在愚蠢的游戏或其他事上。我喜欢建设网站,所以我又返回了我的老本行。我10岁时就编码 HTMLCSS了,很快我就掌握了从表到DIV标签和其他所有东西了。我学会手工编码,不依赖Dreamweaver. 这样能得到更好,更紧凑,更有效的HTML。我11岁就开始玩PHP了,所以我决定再用它创建点东西。

I should never have done that, I have realized. I used about 4 months in PHP, picking up bad habits. At some point, I found myself reaching points where I saw PHP solutions plain stupid. I didn't have experience with any other languages, but I knew there had to be better ways. So I decided to dive into Python, and later look at the Django web framework. So I did.

我已经意识到我不该那么做。我用了约4个月的PHP,染上了坏习惯。有时,我发现自己接触到了很多愚蠢的PHP解决方案。我还没有使用其他语言的经验,但我知道一定有更好的办法。所以我决定专研Python,然后看Django Web框架。 我做到了。

After a few days playing around with Python, I felt okay with it. I didn't love Python, but it was fairly simple, and from the simple Django examples I felt confident I was ready to proceed and expand my literacy in Python via Django. After following the basic tutorials, I felt Django was already superior to PHP.

玩了几天Python后,感觉不错。我不喜爱Python,但它相当简单,而且通过简单的Django示例,我很自信,我想我已经准备好继续扩充我的Python知识了,通过Django. 跟随基本教程学习,我感觉Django早已优于PHP

I had heard about this evil language called Ruby and some framework called Rails, I had not considered it though because of three (stupid) reasons:

  • Highest ratio of smug fanboys

  • End-statements

  • Ruby had become popular due to Rails, not the other way around as it is with Django

我听说过一个邪恶的语言,称为红宝石,还有个叫作Rails的框架,我以前从未考虑过它,因为3个(愚蠢的)原因:

* 有很多自以为是的家伙

* End来结束语句

* RubyRails变得流行,而不是其他的东西,就像Django

So a Saturday night, I turned off the light, locked the door and sealed the windows. It was time to check out this Japanese creation. The fanboys all over the web seemed to recommend this fabulous book called Why's (poignant) guide to Ruby. I installed Ruby, and dove into the book.

于是,一个星期六的晚上,我关掉灯,锁上门,密封窗户。开始检查这个 日本创造 的东西。所有网上的粉丝似乎都推荐这个神话般的书叫 为什么(辛酸的)转向Ruby.我安装了Ruby,一头扎进书里。

A few hours later, I had forgotten everything about Python. Stupid language. Ruby was where it was at, and I instantly started recommending it to all my code-buddies. It's such an awesome language, why not spread the joy? They said I was a fanboy, and told me to gtfo. And I quickly realized what had happened.

几个小时后,我已经忘了一切关于Python的东西,那个愚蠢的语言。 Ruby才是我要的,我立刻开始推荐给我所有的代码哥们。它是个如此棒的语言,为什么不传播喜悦呢?他们说我是变形金钢,叫我滚开(GTFO: Get The Fuck Out). 我很快意识到发生什么事了。

Ruby is evil

Ruby is indeed evil. So evil. Extremely evil. But why so evil? Because it's so beautiful. The syntax is so elegant, everything are objects. Everything makes sense. The Ruby-way of doing things is so sexy.

Ruby很邪恶。

Ruby真的很邪恶。如此邪恶,邪恶之极。但为什么如此邪恶? 因为它是如此美丽。语法是如此优雅,一切都是对象。一切都很在理。Ruby的做事方式是如此的性感。

 I quickly headed over to #ruby and asked them what I should do to practise my all-so-awesome Ruby skills, and some guy recommended me coding a todo-app. It seemed it was the new semi-advanced-but-no-so-advanced hello world. So I did, and here's the extremely awesome output (be prepared, it's extremely bad code and you should NEVER do something like this in Ruby):

我赶紧冲到#ruby问他们,我应该做什么来练习我的极棒的Ruby技能,一些人建议我编个待办事项的应用,这看上去是个稍微先进又不很先进的HelloWorld. 我做了,这里是非常可怕的输出(有心理准备,这是极其恶劣的代码,在Ruby中,你永远不要这样做):

我希望Ruby程序员一年前就告诉我

我希望Ruby程序员一年前就告诉我

我希望Ruby程序员一年前就告诉我

我希望Ruby程序员一年前就告诉我

我希望Ruby程序员一年前就告诉我


Proudly I showed it to the guy who recommended me to create a Todo-app. "Look at this! Ruby is so narwhal!" It took him a while to reply. It would've taken me a while to reply too if somebody showed me such code. It looks like some Bash code, in an object oriented language. Woah. So this guy, he was very helpful and told me he'd make a skeleton for the app. and make me fill in the holes/methods, it was something like this:

我自豪地展示给 推荐我做todo-app的家伙。“看这个!Ruby是个独角兽!". 他花了段时间回复我。如果有人向我展示这种代码我也会花一段时间。它看起来像一些Bash代码,在一个面向对象语言中。哇。原来这家伙,真有用处,他告诉我他做了一个应用的骨架,让我去填孔/方法。它是像这样的东西:

我希望Ruby程序员一年前就告诉我

我希望Ruby程序员一年前就告诉我

So I did. It took a while to adapt from the bad PHP-style, to the Ruby-style. I ended up with this. And then I added an interface. And then meta-programming. And then I was in love.

我做了。从坏的PHP风格适配到 Ruby风格花了一会儿工夫。我就这样结束了这个填空。

然后,我增加了一个接口,然后再元编程,然后我坠入爱河。

So the title of this post is "What I wish a Ruby programmer had told me one year ago..", and that's quite an intro. Since what I wish a Ruby programmer had told me is not much, but could've saved me 4 months in company with PHP.

因些 这篇文章的标题是 “我多希望Ruby程序员一年前就告诉我”,那是多好的前导。即使我希望的Ruby程序员没告诉我那么多,但至少能节省我4个月的在公司使用PHP的时间。

Here's what I'll tell anyone asking me how they should get into programming:

 "First, learn Ruby (buy a book). Play around, create a Todo-app. Create simple programs to handle system tasks for you. But always remember to use classes, and separate the interface from the functionality. In the end this will be pain, you'll always think about making it appear Rubyish, but at some point - it becomes natural. And when it has become natural, you go create a Gem. If you create a big Gem, with much functionality - split it into more Gems, and make it require those. Or use other peoples Gems. If you want to move on with developing web applications, start out simple. Check out a lightweight framework like Sinatra, it's cool and very fun to work with. Move on to Rails if you want, it takes longer to learn, but it is much faster to develop in."

这里就是我告诉 任何问我如何踏入编程行业 的人的话:

“首先,学习Ruby(买一本书)。玩弄,做个待办事项应用。为自己创建一个简单来处理系统任务的程序。但永远记住要使用类,而且要从功能分离出接口。最后这可能会痛,你总是思考如何让化更Ruby化,但有时,它会变得更自然,而且这种做法已成为自然时,你去创建一个Gem(宝石,译者注:类似库),如果你创建一个大Gem,有许多功能,把它分割成多个Gem。然后require它们。(译者注:类似include/import)或者使用别人的Gems。如果你想转而开发Web应用,从简单的开始,下载轻量级框架,如Sinatra.它很酷也很有趣。如果有需要,你可以转到Rails,它需要更长的时间学习,但它开发得更快。

And perhaps point them towards Linux, if they are up for it:

"I do not believe Windows is the best development platform in the world for Ruby. I recommend you to try out Linux (or OS X, if you've got the money for it). Start with a simple distribution, like Ubuntu. And then I recommend something like Arch Linux whenever you feel like you are ready for something more advanced, assuming you want to learn more about how Linux works!"

也许会让他们转到Linux,如果他们认可的话:

”我不相信Windows是世界上最好的Ruby发展平台,我建议你尝试Linux(或OS X,如果你已付钱),从一个简单的发行版开始,像Ubuntu. 当你感觉可以准备学习更高级知识时,我建议你改用类似Arch Linux的系统,假如你想学习更多关于Linux如何运行的知识。

Note: I'm biased. And I know it. Ruby is not a language for everyone, and PHP is not a bad language - it's just not for me. Neither is Python a bad language - it's just not for me. Windows is not a bad operating system - It's just not for me. I advise you to try different languages/operating systems, and eventually find the one you feel at home in.

注:我知道我有些偏见。Ruby不是对每个人来说都是好语言,PHP不是坏语言,只是它不适合我。Python也不是个坏语言,只是它不适合我。Windows不是个坏系统,只是它不适合我。 我建议你去尝试不同的语言,不同的系统,并最终找到一个最适合自己的。

你可能感兴趣的:(PHP,Web,python,脚本,Ruby)