iT邦幫忙

0

WET code 特徵是什麼?

  • 分享至 

  • twitterImage

新手初發問,請幫幫忙,謝謝!
請問WET code 的特徵是什麼?可以舉例解釋一下嗎?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
海綿寶寶
iT邦大神 1 級 ‧ 2022-06-30 09:02:01
最佳解答

WET = Write Everything Twice
初學者應學習避免的一種程式寫法

In the software engineering world, there is a concept of WET code and DRY code.

DRY stands for “Don’t Repeat Yourself”, while WET stands for “We Enjoy Typing” or “Write Everything Twice” (or Thrice!)

Good code is generally pretty DRY. Never repeating itself.
Sloppy code is often pretty WET. The same lines (or variations of the same lines) are often repeated over and over in different places.

Why is repeating code bad? Imagine having the same block of code repeated in 3 different sections of your program. Then imagine changing the logic to that block of code because you wanted to fix a bug or improve performance. Well, now you have to find all the instances of that code block and update it in all 3 locations.

When you first write out new code, you’ll often have WET code. And that’s both common and fairly normal. What is bad is if you decide not to refactor and leave it WET.

資料來源

等到寫程式一段日子了
就可以自己判斷/選擇要寫WET/DRY code

我要發表回答

立即登入回答