Why I hate frameworks

作爲一個傳統的C程序員,java的框架快煩死我了,明明是一件事,非要拆成好幾件,最後再找個人把事情粘合起來。而且框架一搭好,實現方式也就定死了,寫的時候條條框框的,沒有靈活性可言。難怪以前學習的時候就聽說java設計的時候就是把程序員當笨蛋來看,什麼事情都幫你做了,你只要按照它的方式寫就好。

查資料的時候發現這篇文章,深有體會,雖然是快十年前的,放到現在依然如此。

轉載地址:http://www.cnblogs.com/kkjmyazi/archive/2006/11/29/576573.html


Author:Benji Smith
Translator:Evan Wang
Original Link:Why I Hate Frameworks

我正處於建造一個基於Java的Web應用的規劃階段(是的,必須基於Java,不過我現在還不想討論其中的原因)。在這個過程中,我評估了一系列CMS應用容器框架,它們大多擁有J2EE門戶、採用與JSR相兼容的MVC架構、基於角色等。
I'm currently in the planning stages of building a hosted Java web application (yes, it has to be Java, for a variety of reasons that I don't feel like going into right now). In the process, I'm evaluating a bunch of J2EE portlet-enabled JSR-compliant MVC role-based CMS web service application container frameworks.

然而在花了幾十個小時閱讀功能列表和文檔後,我幾乎想戳瞎我的雙眼。
And after spending dozens of hours reading through feature lists and documentation, I'm ready to gouge out my eyes.

首先假設我決定做一個調味品架子。
Let's pretend I've decided to build a spice rack.

我以前做過一些小的木工活,因此我知道自己需要以下東西:一些木頭和基本工具,包括捲尺、鋸子、水平儀和錘子。
I've done small woodworking projects before, and I think I have a pretty good idea of what I need: some wood and a few basic tools: a tape measure, a saw, a level, and a hammer.

如果我想造一棟房子,而不僅僅是一個調味品架,我還是需要捲尺、鋸齒、水平儀和錘子(以及其它東西)。
If I were going to build a whole house, rather than just a spice rack, I'd still need a tape measure, a saw, a level, and a hammer (among other things).

所以,我跑到一家五金店,問一個銷售員,哪裏能找到一把錘子。
So I go to the hardware store to buy the tools, and I ask the sales clerk where I can find a hammer.

“錘子?”他說:“現在幾乎沒人要買錘子了。這個已經過時了。”
"A hammer?" he asks. "Nobody really buys hammers anymore. They're kind of old fashioned."

我很驚訝這樣一種發展,於是問他爲什麼。
Surprised at this development, I ask him why.

“嗯,問題在於有太多種類的錘子。大錘啦,拔釘錘啦,球頭錘等等。你買了其中一種,後來發現你還需要另外一種怎麼辦呢?你下次還得單獨買一把。因此,大多數人實際上需要一把能夠處理他們一生中可能碰到的所有敲敲打打的活的錘子。”
"Well, the problem with hammers is that there are so many different kinds. Sledge hammers, claw hammers, ball-peen hammers. What if you bought one kind of hammer and then realized that you needed a different kind of hammer later? You'd have to buy a separate hammer for your next task. As it turns out, most people really want a single hammer that can handle all of the different kinds of hammering tasks you might encounter in your life."

“嗯,這個聽起來挺不錯。那麼我在哪裏能夠找到這樣一把通用錘子呢?”
"Hmmmmmm. Well, I suppose that sounds all right. Can you show me where to find a Universal Hammer."

“不,我們不再銷售了。他們已經廢棄了。”
"No, we don't sell those anymore. They're pretty obsolete."

“真的嗎?我想你剛纔不是說通用錘子是將來的趨勢嘛。”
"Really? I thought you just said that the Universal Hammer was the wave of the future."

“事實上,如果生產出一種能夠處理所有事情的錘子,反倒不能很有效率地處理其中的任何一件。用一把大錘去拔個釘子很費勁吧。並且,你要殺死你前任女友的話,沒有什麼會比一把球頭錘更適合的了。”
"As it turns out, if you make only one kind of hammer, capable of performing all the same tasks as all those different kinds of hammers, then it isn't very good at any of them. Driving a nail with a sledgehammer isn't very effective. And, if you want to kill your ex-girlfriend, there's really no substitute for a ball-peen hammer."

“這倒是真的。如果沒有人會買這種通用錘子,而你們又不再銷售老式的各種錘子,那麼你們賣什麼樣的錘子呢?”
"That's true. So, if nobody buys Universal Hammers anymore, and if you're no longer selling all those old-fashioned kinds of hammers, what kinds of hammers do you sell?"

“事實上,我們不賣錘子。”
"Actually, we don't sell hammers at all."

“那麼…”
"So..."

“根據我們的研究,人們需要的根本不是通用錘子。最好還是用不同的錘子做不同的工作。所以,我們現在銷售錘子工廠,它能夠生成任何你需要的錘子。你所需要的只是爲錘子工廠招聘員工,開動機器,購買原材料,付公用事業費,諸如此類的…這樣你就可以隨時得到你需要的錘子。”
"According to our research, what people really needed wasn't a Universal Hammer after all. It's always better to have the right kind of hammer for the job. So, we started selling hammer factories, capable of producing whatever kind of hammers you might be interested in using. All you need to do is staff the hammer factory with workers, activate the machinery, buy the raw materials, pay the utility bills, and PRESTO...you'll have *exactly* the kind of hammer you need in no time flat."

“但我真的不想買一個錘子工廠…”
"But I don't really want to buy a hammer factory..."

“對頭。我們其實也不再銷售錘子工廠了。”
"That's good. Because we don't sell them anymore."

“但你剛剛還說…”
"But I thought you just said..."

“我們發現大多數人實際上不需要一整個錘子工廠。比如說,一些人,就不可能用到球頭錘。(也許他們就沒有前女友。或者他們用冰錐來解決她們。)所以對一些人來說一個能生產各種錘子的工廠是沒有什麼意義的。”
"We discovered that most people don't actually need an entire hammer factory. Some people, for example, will never need a ball-peen hammer. (Maybe they've never had ex-girlfriends. Or maybe they killed them with icepicks instead.) So there's no point in someone buying a hammer factory that can produce every kind of hammer under the sun."

“耶,這個實際得多。”
"Yeah, that makes a lot of sense."

“所以,我們開始銷售錘子工廠的示意圖,以便我們的客戶能夠建造他們自己的錘子工廠,自行設計只生成他們實際需要的那些錘子。”
"So, instead, we started selling schematic diagrams for hammer factories, enabling our clients to build their own hammer factories, custom engineered to manufacture only the kinds of hammers that they would actually need."

“讓我猜猜看。你們現在也不再銷售這些了。”
"Let me guess. You don't sell those anymore."

“對,真的是這樣。實際上,人們不會爲了幾把錘子去建一個工廠。就像我經常說的,讓建造工廠的專家去建造工廠吧。”
"Nope. Sure don't. As it turns out, people don't want to build an entire factory just to manufacture a couple of hammers. Leave the factory-building up to the factory-building experts, that's what I always say!!"

“這一點我贊成。”
"And I would agree with you there."

“對的。所以我們停止銷售這些示意圖,轉而銷售建造錘子工廠的工廠。每個建造錘子工廠的工廠都由這方面的頂尖專家建造,所以,你根本不需要操心建造工廠的任何細節。你依然擁有自定義錘子工廠的好處,根據你自己特定的錘子設計做出你自己的錘子。”
"Yup. So we stopped selling those schematics and started selling hammer-factory-building factories. Each hammer factory factory is built for you by the top experts in the hammer factory factory business, so you don't need to worry about all the details that go into building a factory. Yet you still get all the benefits of having your own customized hammer factory, churning out your own customized hammers, according to your own specific hammer designs."

“嗯,這個實際上並不…”
"Well, that doesn't really..."

“我知道你想說什麼!…我們也不再銷售這些東西了。因爲某些原因,也沒有多少人買建造錘子工廠的工廠,所以我們又有了新的解決方法。”
"I know what you're going to say!! ...and we don't sell those anymore either. For some reason, not many people were buying the hammer factory factories, so we came up with a new solution to address the problem."

“哇哈。”
"Uh huh."

“當 我們回過頭來審查這個統一工具的基礎時,發現人們被必須管理和運作一個製造錘子的工廠以及它所生成的錘子工廠給困住了。當你需要處理類似的建造捲尺工廠的 工廠,水平儀工廠的工廠,鋸子工廠的工廠的時候,這很快就會變得相當棘手。更別提木材生產集團公司了。當我們審查這種狀況的時候,我們意識到這對於僅僅想 做個調味品架子的人來說過於複雜了。”
"When we stepped back and looked at the global tool infrastructure, we determined that people were frustrated with having to manage and operate a hammer factory factory, as well as the hammer factory that it produced. That kind of overhead can get pretty cumbersome when you deal with the likely scenario of also operating a tape measure factory factory, a saw factory factory, and a level factory factory, not to mention a lumber manufacturing conglomerate holding company. When we really looked at the situation, we determined that that's just too complex for someone who really just wants to build a spice rack."

“是啊,這可不是開玩笑。”
"Yeah, no kidding."

“所以,這個星期,我們正在推廣一種通用的建造工廠, 用來建造生產工具工廠的工廠,這樣你所有的用來建造不同種類工具的工廠的工廠就可以由一個單一的、統一的工廠來建造了。這種工廠將僅僅生產你所需要的工具 工廠的建造工廠,而這些建造工廠將生成一個僅生產你自定義的工具的工廠來。你將得到你要的那種錘子,你要的捲尺,所有這一切僅僅需要按一下按鈕(當然,也 許你要發佈一些配置文件以便它能根據你的期望來工作)。”
"So this week, we're introducing a general-purpose tool-building factory factory factory, so that all of your different tool factory factories can be produced by a single, unified factory. The factory factory factory will produce only the tool factory factories that you actually need, and each of those factory factories will produce a single factory based on your custom tool specifications. The final set of tools that emerge from this process will be the ideal tools for your particular project. You'll have *exactly* the hammer you need, and exactly the right tape measure for your task, all at the press of a button (though you may also have to deploy a few *configuration files* to make it all work according to your expectations)."

“所以,你們根本就沒有什麼錘子?不是嗎?”
"So you don't have any hammers? None at all?"

“是的。如果你需要一個高質量的,工業標準的調味料架子,你絕對需要這些高級玩意,而不是從那些破破爛爛的五金店裏就買得到的錘子。”
"No. If you really want a high-quality, industrially engineered spice rack, you desperately need something more advanced than a simple hammer from a rinky-dink hardware store."

“現在所有的人都在這麼做嗎?當他們需要一把錘子的時候,所有的人都在使用一個通用的能夠生產工具工廠的建造工廠的工廠嗎?”
"And this is the way everyone is doing it now? Everyone is using a general-purpose tool-building factory factory factory now, whenever they need a hammer?"

“是的。”
"Yes."

“那…好吧。我想這就是我必須要做的。如果這是處理事情的既定方法,我想我最好還是學學怎麼來用吧。”
"Well…All right. I guess that's what I'll have to do. If this is the way things are done now, I guess I'd better learn how to do it."

“祝你好運!”
"Good for you!!"

“這些都有文檔的,對吧?”
"This thing comes with documentation, right?"

現在我已經自豪地擁有了自己的通用的工具工廠的建造工廠的建造工廠,我很高興地知道它與GPTBFF 0.97 RC2標準草案兼容,這是“通用的工具工廠的建造工廠的建造工廠”的標準。 
Now that I'm the proud owner of my own general-purpose tool-building factory factory factory, I'm satisfied to know that it complies with the GPTBFFF 0.97 RC2 draft specification for tool-building factory factory factories.

很幸運地,面向工具的元工廠聯盟裏的工人都通過了這個版本的標準的驗證。
Luckily, 70% of the workers in the Tool-Oriented Metafactory Union are certified against this version of the spec.

然而標準之爭即將開始:一種名爲UXCTBFFF(Universal Trans-Continental Tool Building FFF)很有競爭力的原工廠技術承諾將統一建造工廠的工廠的建造行業,以使之符合那些同時使用公制和當地度量單位的國家的標準。
On the horizon is a competing standard, though: a very compelling metafactory technolgy called the UXCTBFFF (Universal Trans-Continental Tool Building FFF), which promises to unify the factory factory factory industry to comply with guidelines of countries that use both metric and standard tools.

我的理解是只需要創建一個貫穿用戶界面的抽象層的補丁包,就可以使GPTBFF 0.97 RC2與UXCTBFF標準達到95%左右的兼容。
My understanding is that there will be a service pack to my GPTBFFF 0.97 RC2 to bring it into nearly 95% compliance with the UXCTBFFF standard, just by creating an abstraction layer through its user interface.

真是太好了!
Sweet!!

想必這種新的發展能夠提升我的調料架的質量(一旦我搭建好我的工具工廠的建造工廠的建造工廠並使之運行,培訓好工人,從柬埔寨進口來原木,在最近的某天,我就要開始做那個調料架了)。
Surely this new development will improve the quality of my spicerack (which I'll get around to building one of these days, as soon as I've got my factory factory factory all up and running, my labor force trained, my raw materials imported from Cambodia, etc).

發佈了6 篇原創文章 · 獲贊 3 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章