Function to Function Pointer refactoring

Last week I had some time to work on some C legacy code again and write some unit tests. I've been playing with a refactoring that I've used in the past and now use it all the time when working in C. The refactoring is called "function to function pointer" and is fairly trivial to do and save in legacy code. It gives a lot of flexibility.

The steps are:

  1. Change function prototype to function pointer in the header (just adding (*name)). Make sure it's extern
  2. Rename the function in the .c file to name_impl, or something non conflicting.
  3. At the end of the .c file. Initialize the function pointer with the _impl one.

That's it. Just takes a few seconds and it allows you to dynamically replace the function in your unit tests. It makes unit testing code in C a lot easier. (there are also some variants, but this is the easiest and most basic version)

Read more

คนไม่ใช่สิ่งทดแทนกันได้ (People are not Fungible)

คนไม่ใช่สิ่งทดแทนกันได้ (People are not Fungible)

ในปี 2546 นักศึกษาคณะวิทยาศาสตร์ที่เรียนอยู่ที่ศูนย์รังสิตมาตลอดแบบผม ได้มีโอกาสเข้าเมืองไปเรียนที่ธรรมศาสตร์ ท่าพระจันทร์ เป็นครั้งแรก นอกจากจะตื่นตาตื่นใจกับของอร่อยมากมายรอบมหาวิทยาลัยแล้ว บรรยากาศที่ศูนย์ท่าพระจันทร์มันมีมนต์ขลังแปลก ๆ ตัวผมได้

By Chokchai
ทำไม System Analyst ถึงไม่เชื่อ Design จากทีม

ทำไม System Analyst ถึงไม่เชื่อ Design จากทีม

บ่อยครั้งที่ผมได้ยินน้อง ๆ ออดส์ทีม (ODT) เล่าว่า งานที่ทำอยู่ไม่ท้าทายเลย เพราะเพียงได้รับ Specification มาจาก System Analyst (SA) หรือ Tech Lead ที่เป็นพนักงาน แล้วน้องก็มีหน้าที่เขียนโค้ดตามนั้นไปอย่างเดียว บ่

By Chokchai
เวลาอู้

เวลาอู้

ผมกำลังอ่านหนังสือ Slack: Getting Past Burnout, Busywork, and the Myth of Total Efficiency ของ Tom DeMarco ซึ่งได้ให้มุมมองใหม่เกี่ยวกับ Slack time หรือเวลาอู้งานกับผม แต่ก่อนจะเล่าว่าผมเห็นอะไร ผมของแบ่งปันมุมมองเวลาผมดูองค์กรก่อนนะ สายการผลิต คนในองค์กรมารวมตั

By Chokchai