我但願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. linux

一年前,我從新開始真正的編碼。我再也不浪費時間在愚蠢的遊戲或其餘事上。我喜歡建設網站,因此我又返回了個人老本行。我10歲時就編碼 HTMLCSS了,很快我就掌握了從表到DIV標籤和其餘全部東西了。我學會手工編碼,不依賴Dreamweaver. 這樣能獲得更好,更緊湊,更有效的HTML。我11歲就開始玩PHP了,因此我決定再用它建立點東西。 git

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框架。 我作到了。 github

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. web

玩了幾天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: ubuntu

  • Highest ratio of smug fanboys windows

  • End-statements ruby

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

我據說過一個邪惡的語言,稱爲紅寶石,還有個叫做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中,你永遠不要這樣作):


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代碼,在一個面嚮對象語言中。哇。原來這傢伙,真有用處,他告訴我他作了一個應用的骨架,讓我去填孔/方法。它是像這樣的東西:


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不是個壞系統,只是它不適合我。 我建議你去嘗試不一樣的語言,不一樣的系統,並最終找到一個最適合本身的。

相關文章
相關標籤/搜索