Tags:
Node Thumbnail

สงครามศาสนาที่คงอยู่มายาวนานของวงการโปรแกรมเมอร์คือ การย่อหน้าด้วย space vs tab ซึ่งก็คงยังไม่มีข้อยุติในเร็ววัน

เรื่องนี้เป็นประเด็นขึ้นมาอีกครั้ง เมื่อเว็บไซต์ The Register ไปค้นพบว่า Linus Torvalds ไปแก้โค้ดในเคอร์เนลลินุกซ์ ซึ่งในแพตช์นี้มีการแก้ไขเพียงอย่างเดียวคือเปลี่ยนอักขระ space มาเป็น tab

อย่างไรก็ตาม Linus ไม่ได้เลือกข้างในสงครามศาสนานี้แต่อย่างใด เพราะเหตุผลของเขาคือไฟล์ที่เขาแก้ไขคือ Kconfig ซึ่งเป็นไฟล์คอนฟิกค่าต่างๆ ของเคอร์เนล (ลักษณะเดียวกับ YAML ในปัจจุบัน) และมี parser รุ่นเก่าๆ บางตัวที่ยังเขียนมาได้ไม่ดีพอ ทำให้อ่านค่า space/tab ผิดพลาด

จุดที่น่าสนใจคือ สิ่งที่ Linus ทำไม่ได้แก้ให้ไฟล์ Kconfig อ่านค่าได้ง่ายขึ้น แต่เขา "จงใจ" ทำให้ไฟล์ซับซ้อนขึ้นแทน โดยเปลี่ยน space ธรรมดาให้เป็น tab ความกว้าง 8 ตัวอักษร เพื่อบีบให้ parser บางตัวทำงานพลาด คนเขียน parser จะได้กลับมาแก้ไขโค้ด parser ของตัวเอง

Linus ให้คำอธิบายการแก้ไขไว้ดังนี้

Let's make sure it gets fixed. Because if you can't parse tabs as whitespace, you should not be parsing the kernel Kconfig files.

ที่มา - The Register , ภาพจาก Reddit r/programming

No Description

Get latest news from Blognone

Comments

By: obtheair on 17 April 2024 - 15:14 #1309881

ผมสาย tab
ผมไม่ได้มีปัญหากับ spaceและผมเห็นด้วยกับภาพท้ายข่าว
ตุบตับตุบตับ

By: EngineerRiddick
iPhone Windows Phone Android Ubuntu
on 17 April 2024 - 15:22 #1309882
EngineerRiddick's picture

CivilWar2024
dev: เฮ~พวก ไม่เอาน๊า พวกเราเป็นprogrammerเหมือนกัน
reviewer: แล้วคุณเป็น programmer ที่เคาะspace หรือเคาะtabละ?

:)

By: pote2639
Contributor iPhone Windows Phone Windows
on 17 April 2024 - 16:41 #1309886

คนที่ไม่เขียน program คงปวดหัวสิ่งนี้ จะเว้นวรรคใน word processor ใช้ tab..

By: hisoft
Contributor Windows Phone Windows
on 17 April 2024 - 16:58 #1309888 Reply to:1309886
hisoft's picture

word processor นี่น่าจะใช้ tab/space กันหนักหน่วงกว่าเขียนโปรแกรมอีกนะ

By: iamfalan
iPhone Android Windows
on 17 April 2024 - 17:26 #1309890

ฮาตรงไม่ได้แก้ให้ compatible แต่แก้ให้แอพที่เขียนไม่ดีพัง

By: Configuleto
Android Windows
on 17 April 2024 - 18:22 #1309894
Configuleto's picture

The Register ก็ไปตัดมานิดเดียว อ่าน คอมเม้นเต็มๆ ของไลนัสเองจะรู้สึก amusement กว่า

Commit d96c36004e31 ("tracing: Fix FTRACE_RECORD_RECURSION_SIZE Kconfig entry")
removed a hidden tab because it apparently showed breakage in
some third-party kernel config parsing tool.

It wasn't clear what tool it was, but let's make sure it gets fixed.
Because if you can't parse tabs as whitespace, you should not be parsing
the kernel Kconfig files.

In fact, let's make such breakage more obvious than some esoteric ftracerecord size option. If you can't parse tabs, you can't have page sizes.

Yes, tab-vs-space confusion is sadly a traditional Unix thing, and
'make' is famous for being broken in this regard. But no, that does not
mean that it's ok.

I'd add more random tabs to our Kconfig files, but I don't want to make
things uglier than necessary. But it might bbe necessary if it turns
out we see more of this kind of silly tooling.

By: mr_tawan
Contributor iPhone Android Windows
on 18 April 2024 - 05:51 #1309908
mr_tawan's picture

เป็นสายใช้อะไรก็ได้ แล้วจบด้วย clang-format


  • 9tawan.net บล็อกส่วนตัวฮับ
By: btoy
Contributor Android Windows
on 18 April 2024 - 10:57 #1309922
btoy's picture

ผมว่าขอแค่แต่ละภาษาหรือ script มี formatter ของตัวเองก็พอ จะเป็นอะไรก็ได้


..: เรื่อยไป

By: Be1con
Contributor Windows Phone WindowsIn Love
on 19 April 2024 - 20:17 #1310065
Be1con's picture

ทีมใส่ Tab...


Coder | Designer | Thinker | Blogger