什么是“太聪明"的 Ruby 代码示例? [英] What's an example of Ruby code that's "too clever"?

查看:38
本文介绍了什么是“太聪明"的 Ruby 代码示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和一些程序员朋友讨论过,他们说他们看到 Ruby 程序员(特别是)编写了很多太聪明"的代码.所以我想知道那会是什么样子?我指的是在一个简单的东西会同样有效或更好的上下文中不必要地使用晦涩的语言功能.知道这方面的任何好的 Ruby 示例吗?

解决方案

在直接回答你的问题后,我也想对前提提出异议;每当一群程序员以这种方式描述另一种语言的用户时,很有可能他们告诉你的更多是关于他们自己而不是他们所描述的社区.

例如,您可以指责 c 程序员过于沉迷于底层细节,或者指责 Haskell 程序员被他们对功能纯度的渴望所蒙蔽;为简洁起见,perl mongers 等等.但是恕我直言,当你这样做时,你会倒推因果关系.

当我想编写一个最好用某种风格表达的程序时,我会尝试选择一种支持这种风格的语言.有时您需要一个工具来让您做不寻常的事情,而对于这样的任务,拥有诸如 ruby​​ 之类的语言与在工具包中拥有用于数学的 mathematica 或用于浏览器操作的 javascript 一样有价值.如果我想玩排版,我会跳到 postscript 因为这是它最擅长的.

这就像在说你有没有注意到使用电钻的人总是在东西上戳洞?"这是真的,但它有点没有抓住重点.

I was having a discussion with some programmer friends who said that they see Ruby programmers (in particular) producing a lot of code that's "too clever". So I'm wondering what would that look like? I'm referring to the unnecessary use of an obscure language feature in a context in which something straightforward would have worked just as well or better. Know any good Ruby examples of this?

解决方案

After giving a straight answer to your question, I'd like to also dispute the premise; whenever a group of programmers characterizes the users of another language in this way, the odds are that they are telling you more about themselves than about the community they are describing.

You could, for example, accuse c programmers of being too obsessed with low level details, or haskell programmers with being blinded by their desire for functional purity; perl mongers for brevity, etc. But you would, IMHO, by getting the causality backwards when you do so.

When I want to write a program that is best expressed in a certain style, I try to choose a language that supports that style. Sometimes you want a tool that lets you do unusual things, and for such a task having a language such as ruby is as valuable as having mathematica for math or javascript for browser manipulation in your toolkit. If I want to play with typography I hop into postscript because that's what it's best at.

It's like saying "Have you ever noticed that people who use power drills are always poking holes in things?" It's true, but it kind of misses the point.

这篇关于什么是“太聪明"的 Ruby 代码示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆