Procedural programming คืออะไร?

แนวคิดกระบวนทัศน์การเขียนโปรแกรม

Eleanor Thomas

Senior Data Analytics Engineer

Procedural programming คืออะไร?

  • Procedural programming: รูปแบบการเขียนโปรแกรมเชิงคำสั่งที่สร้างโปรแกรมด้วย procedures
  • Procedure (subroutine): ชุดขั้นตอนที่อ้างอิงและเรียกใช้ซ้ำได้หลายครั้ง
  • หมายเหตุ: Procedural programming เป็นประเภทหนึ่งของ imperative programming แต่ไม่ใช่ทุก imperative programming ที่เป็น procedural

Imperative และ procedural programming

แนวคิดกระบวนทัศน์การเขียนโปรแกรม

Procedures ใน procedural programming

  • Procedures: วิธีที่ procedural programming แบ่งแยกความรับผิดชอบ
  • Procedures ช่วยให้โค้ดมีโมดูลาริตี
  • ช่วยให้เรียกใช้โค้ดส่วนเดิมซ้ำในหลายที่ได้อย่างมีประสิทธิภาพ
  • ช่วยด้านการจัดระเบียบและความอ่านง่าย

รายการตรวจสอบ

แนวคิดกระบวนทัศน์การเขียนโปรแกรม

ตัวอย่าง procedures

  • ใน Python procedures จะถูกนำไปใช้งานในรูปแบบฟังก์ชัน
    ducks = ['Huey', 'Dewey', 'Louie']
    sorted_ducks = sort_ducks(ducks)
    

เป็ดเรียงแถว

แนวคิดกระบวนทัศน์การเขียนโปรแกรม

ตัวอย่างโปรแกรมแบบ procedural

def print_initial(name):
    initial = name[0]
    print(initial)

print_initial("Marwa")
print_initial("Celia")
print_initial("Raqael")

Output:

"M"
"C"
"R"
แนวคิดกระบวนทัศน์การเขียนโปรแกรม

มาฝึกกันเถอะ!

แนวคิดกระบวนทัศน์การเขียนโปรแกรม

Preparing Video For Download...