Is the separation of program logic and presentation layer going too far?

In a Drupal programming guide, I noticed this sentence:

The theme hook receives the total number of votes and the number of votes for just that item, but the template wants to display a percentage. That kind of work shouldn’t be done in a template; instead, the math is performed here.

The math necessary to calculate a percentage from a total and a number is (number/total)*100. Is this application of two basic arithmetic operators within a presentation layer already too much? Is the maintenance of the entire system severely compromised by this amount of mathematics?

The WPF (Windows Presentation Framework) and its UI mark-up language, XAML, seem to go to similar extremes. If you try to so much as add two numbers in the View (the presentation layer), you have committed a cardinal sin. Consequently, XAML has no operators for any arithmetic whatsoever.

Is this ultra-strict separation really the holy grail of programming? What are the significant gains to be had from taking the separation to such extremes?

I see nothing wrong with documentation being a tad pedantic, especially considering the typical target audience, even more so when it comes to things like templates, given that it’s not exactly rare for non developers (graphic artists, for example) to dabble with them. Prior to your quote, the wording suggests that, although a bit silly, the example is used to illustrate the concept, I don’t think the authors really meant to suggest that you should blindly follow their suggestion, but more to make a point.

Furthermore when it comes to documentation that targets PHP developers (and non developers), extreme pedantry is almost required, PHP has a notoriously low entry barrier and consequently the ecosystem is filled with crap code. I haven’t looked at Drupal’s codebase in years, but the last time I remember doing so, it was mostly super glue and duct tape, not WordPress bad mind you, but still I was amazed it even worked. I’ll venture a guess and say that the pedantry in the documentation is probably a direct consequence of the… not ideal state of the project’s codebase.

At the same time though, you make a fair point, and the quote you isolated feels a bit dogmatic. Separating logic from presentation is an abstract principle, and thus open to interpretation and affected by various constraints. Similarly, MVC, the main expression of the principle, at least in web development, is an architectural pattern, or perhaps more accurately a tiered architectural model with three main components and without a canonical, or “pure”, implementation. There are no “holy grails” in this, as there are no “holy grails” in anything in software development, our profession is one of trade-offs.

It’s nearly impossible to say how much the application of two basic arithmetic operators within a presentation layer will actually affect your application, unless we know exactly what you’re building and what exactly will depend on that math. Will the math need to change at a later time, for example? And if so, will you remember that this small, but perhaps crucial piece of code is not where it’s supposed to be, two years after you’ve written it? I’m assuming here that you practice separation of program logic and presentation in general, and because of that you’ve trained yourself, perhaps unwittingly, to expect things to be in a certain place.

If you are confident that you are just doing a simple operation, that will probably never change and nothing important depends on it, I’d say feel free to put it wherever you want. Sure, purists will bark, some of them will probably feint, but who cares? I’ve said it before and I’ll say it again, perfectionism is not a goal in itself, keep it simple, stupid!

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật