正在加载视频...

视频加载失败

Linus Torvalds explains "taste" in code by showing how to remove an entry from a singly linked list in C without adding extra complexity. Source: TED

8,910,656 次观看 • 1 年前 •via X (Twitter)

10 条评论

tetsuo.ai 的头像
tetsuo.ai1 年前

Source:

🇵🇹Ninja Dynamics☀️🌴🍹 的头像
🇵🇹Ninja Dynamics☀️🌴🍹1 年前

Oh man, seeing how elegantly a simple linked list can be optimized really blew my mind! Beautiful! Linus really is the goat!

dinn 的头像
dinn1 年前

"Better taste" would not work if entry is a value, not a list element that needs to be deleted. Last string needs indirect->next

Kevin Dai 的头像
Kevin Dai1 年前

I'd argue the first one is better *because* it's more intuitive and understandable (biased as a compiler developer). In reality, the compiler has no trouble optimizing this trivial logic: and actually yields better code in the "untasteful" one (1/3)

Ghasem Ramezani 的头像
Ghasem Ramezani1 年前

Looking at the problem from a different perspective is extremely hard when you are in the problem. 😫

Araf 的头像
Araf1 年前

had to do some soul searching

wundram 的头像
wundram1 年前

That while loop tastes pretty sour.

Teobastus 的头像
Teobastus1 年前

But it doesn't really handle the case where you reach the end of the list without finding the element you're looking for. If you reach the end it will crash and probably segfault.

Method 的头像
Method1 年前

“code taste”

Noga Navon🏳️‍⚧️ الزهرة الحكيمة נוגה נבון 的头像
Noga Navon🏳️‍⚧️ الزهرة الحكيمة נוגה נבון1 年前

This is the kind of thing that make having pointers in your language worth it.

相关视频