不要只学习语言,要了解它的文化 27

Don’t Just Learn the Language, Understand its Culture
In high school, I had to learn a foreign language. At the time I thought that I’d get by nicely being good at English so I chose to sleep through three years of French class. A few years later I went to Tunisia on vacation. Arabic is the official language there and, being a former French colony, French is also commonly used. English is only spoken in the touristy areas. Because of my linguistic ignorance, I found myself confined at the poolside reading Finnegans Wake, James Joyce’s tour de force in form and language. Joyce’s playful blend of more than forty languages was a surprising albeit exhausting experience. Realizing how interwoven foreign words and phrases gave the author new ways of expressing himself is something I’ve kept with me in my programming career.

In their seminal book, The Pragmatic Programmer, Andy Hunt and Dave Thomas encourage us to learn a new programming language every year. I’ve tried to live by their advice and throughout the years I’ve had the experience of programming in many languages. My most important lesson from my polyglot adventures is that it takes more than just learning the syntax to learn a language: You need to understand its culture. You can write Fortran in any language, but to truly learn a language you have to embrace the language. Don’t make excuses if your C# code is a long Main method with mostly static helper methods, but learn why classes make sense. Don’t shy away if you have a hard time understanding the lambda expressions used in functional languages, force yourself to use them.

Once you’ve learned the ropes of a new language, you’ll be surprised how you’ll start using languages you already know in new ways. I learned how to use delegates effectively in C# from programming Ruby, releasing the full potential of .NETs generics gave me ideas on how I could make Java generics more useful, and LINQ made it a breeze to teach myself Scala.

You’ll also get a better understanding of design patterns by moving between different languages. C programmers find that C# and Java have commoditized the iterator pattern. In Ruby and other dynamic languages you might still use a visitor, but your implementation won’t look like the example from the Gang of Four book.

Some might argue that Finnegans Wake is unreadable, while others applaud it for its stylistic beauty. To make the book a less daunting read, single language translations are available. Ironically, the first of these was in French. Code is in many ways similar. If you write Wakese code with a little Python, some Java, and a hint of Erlang, your projects will be a mess. If you instead explore new languages to expand your mind and get fresh ideas on how you can solve things in different ways, you will find that the code you write in your trusty old language gets more beautiful for every new language you’ve learned.

By Anders Norås

不要只学习语言,要了解它的文化
在高中时,我不得不学习一门外语。当时我认为我会很好地学习英语,所以我选择在三年的法语课上睡觉。几年后,我去突尼斯度假。阿拉伯语是那里的官方语言,作为法国的前殖民地,法语也很常用。英语只在旅游区说。由于我对语言的无知,我发现自己被限制在泳池边阅读詹姆斯·乔伊斯的《芬尼根守灵》,这是詹姆斯·乔伊斯的形式和语言之旅。乔伊斯有趣地融合了40多种语言,这是一次令人惊讶但又令人筋疲力尽的经历。在我的编程生涯中,我一直意识到交织在一起的外国单词和短语给了作者新的表达方式。
Andy Hunt和Dave Thomas在他们的开创性著作《实用程序员》中鼓励我们每年学习一种新的编程语言。我试着听从他们的建议,这些年来我有过用多种语言编程的经验。我从多语种冒险中得到的最重要的教训是,学习一门语言不仅仅需要学习语法:你需要了解它的文化。你可以用任何语言编写Fortran,但要真正学习一种语言,你必须接受这种语言。如果你的C#代码是一个长Main方法,其中大部分是静态辅助方法,不要找借口,但要了解类为什么有意义。如果你很难理解函数语言中使用的lambda表达式,不要回避,强迫自己使用它们。
一旦你学会了一门新语言的诀窍,你会惊讶于你会如何开始以新的方式使用你已经知道的语言。我从Ruby编程中学到了如何在C#中有效地使用委托,释放了.NET的全部潜力。NET泛型让我想到了如何让Java泛型更有用,LINQ让自学Scala变得轻而易举。
通过在不同语言之间切换,您还可以更好地理解设计模式。C程序员发现C#和Java已经将迭代器模式商品化了。在Ruby和其他动态语言中,您可能仍然使用访问者,但您的实现看起来不像“四人帮”一书中的示例。
有些人可能会认为《芬尼根守灵》不可读,而另一些人则称赞它的风格之美。为了让这本书不那么令人望而生畏,我们提供了单语言翻译。具有讽刺意味的是,第一个是法语。代码在很多方面都是相似的。如果你用一点Python、一些Java和一点Erlang编写Wakese代码,你的项目就会一团糟。如果你转而探索新的语言来扩展你的思维,并对如何以不同的方式解决问题有新的想法,你会发现你用可靠的旧语言编写的代码对你所学的每一种新语言都会变得更漂亮。
Anders Norås著

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值