Hari ini ketika mengedit source file ASP yang saya kerjakan kemarin, baru saya dapati dari senior programmer saya Mas Cipta, yang meng-comment apa yang telah saya kerjakan sebelumnya dan dia juga meninggalkan catatan ” NOTES: Prefer using declarative binding, I’ll continue later”. Akhirnya ya aku tidak lanjutkan yang aku kerjakan. Aku sendiri tidak tahu alasannya kenapa dia prefer ke declarative binding, sedangkan saya sendiri lebih menyukai programmatic binding. Alasannya kurang lebih sama dengan penjelasan seperti yang sama temukan di Chris McKenzie’s Blog
Declarative vs. Programmatic binding with the ASP .NET DataGrid
A co-worker and I were having an argument this morning about the best way to databind to an ASP .NET datagrid control. The argument centered around whether to use the declarative server-tag syntax in the aspx file (e.g., <%# Container.DataItem(“Name”) %> ) or doing it programmatically in the code-behind using the ItemDataBound() event.I personally do not like the server-tag approach. Given that I use the code-behind to manage databinding in most other instances, and given that I often need a finer degree of presentation control than server tags give me, I prefer to write my binding code using the event model. I realize that this approach adds a bit of complexity on the initial design side, but I find that such code is easier to modify and extend in the long run than server tags. I also like knowing that all of my binding code is in one place, and that there is a consistent approach to databinding throughout the system, making maintenance easier. Extensibility is also a concern because if the needs of the binding exceed what is normally accessible via server-tags, the binding logic has to be redeveloped from scratch in the code-behind. Finally, the server-tags approach smells of classic ASP to me; and while it’s a purely emotional response, I want to stay as far away from intermingling presentation and programming logic as possible.
My co-worker recognizes that there are many instances where programmatic databinding is necessary, but argues that it’s often easier to just use declarative server-tags. His argument is that the speed-of-development on the front-end is worth the possible slower maintainability and extensibility in the future.
I realize that I’m not giving my co-worker equal space here, but in truth, that’s about all he said. I’m interested if anyone else has an opinion on this subject, and what other issues may be present that we’re not considering.
Published Wednesday, May 18, 2005 2:36 PM by taganov
Filed under: ASP .NET, Miscellaneous
Anda sendiri lebih prefer mana, declarative ataukah programmatic binding?Itu semua pilihan Anda ^__^