most programmers are unable to separate their fragile egos from the code they write iBanjo
ส่วนหนึ่งที่ชอบมากใน django คือส่วน template engine ของมัน แม้จะไม่ค่อยชอบที่มันคล้ายๆ python แต่ดันต่างกันนิดหน่อยให้งงเล่นๆ แต่โดยทั่วไปแล้วต้องยอมรับว่า template ของ django มันใช้งานได้จริง
ปัญหาในช่วงหลังมานี้พอดีว่ามีเรื่องต้องทำ code generation เยอะ ด้วยความที่ต้องเขียนสคริปต์ TCL (ภาษารุ่นพ่อ) เพื่อมาใช้งาน NS2 ในการจำลองเครือข่ายคอมพิวเตอร์ แม้ns2 จะใช้ภาษาสคริปต์อย่าง TCL เพื่อความสะดวกในการแก้ไขสคริปต์โดยไม่ต้อง build ใหม่ทั้งระบบแล้วก็ตาม แต่การแก้สคริปเป็นร้อยๆ แบบก็ไม่สนุกนัก แถมภาษา TCL นั้นเขียนลำบาก เขียนผิดทีเล่นเอาหาไม่เจอบ่อยๆ อาจจะเป็นเพราะผมไม่ชำนาญเองก็ได้
วิธีที่ง่ายกว่าคือการสร้างสคริปต์ขึ้นมาใหม่ โดยใช้สคริปต์หลักเป็นโครง แล้วใช้พวก template engine นี่แหละมาสร้างเอา
เมื่อคิดได้อย่างนั้นสิ่งแรกที่ผมทำคือการ พยายามใช้ template engine ของ django มาสร้างสคริปต์ทันที แต่แล้วก็ต้องพบกับความลำบากเมื่อ template engine ของ django นั้นผูกกับตัว web framework จนแกะไม่ออก
สุดท้ายเลยมาเห็นเอา jinja ที่ระบุตัวเองชัดเลยว่าเป็น django-like แต่เอามาใช้งานแยกได้ง่ายๆ ตอนนี้ที่ใช้งานแบบง่ายๆ ก็มีแค่สามสี่บรรทัด
import jinja as jj
env = jj.Environment(loader=jj.FileSystemLoader('./'))
tmpl = env.get_template('template.tcl')
print tmpl.render(number_of_node=3,width=100,height=20,packet_size=20,bandwidth=0.064)
น่าสนใจว่าถ้าเอาไปรวมเข้ากับ web framework อื่นๆ อย่าง web.py ก็น่าจะสวยดีเหมือนกัน
CRUD เป็นคำย่อมาจาก Create Read Update Delete ซึ่งเป็นการรวมการทำงานพื้นฐานบนฐานข้อมูลใดๆ คำนี้จะเจอบ่อยกับบรรดา Web Framework ทุกยี่ห้อ
วันนี้นั่งอ่านๆ ไปแล้วก็เพิ่งรูว่ามันมีคำอื่นด้วย
- ABCD: add, browse, change, delete
- ACID: add, change, inquire, delete
- BREAD: browse, read, edit, add, delete
- VADE(R): view, add, delete, edit (restore)
ที่มา - Wikipedia
Today, i try to write more sample application in django. While django is a great framework with simplicity. Many parts of its’ quite unstable. With many modules waiting for rewrite before version 1.0. I hit a quite simple bug in ORM mapper. (Bug #2918)
But the problem was not all bad. I has tried to find some GUI application to work with sqlite3 for awhile. (For I’m too lazy to read SQL which I hardly used.) Most application were written for win32. But at last I found sqlitebrowser, it’s simple and clean GUI administration for sqlite3.
The problem always come with solution and knowledge, doesn’t it?