Stefan Says

Opinions on ASP.NET, ASP, databases etc
posts - 32, comments - 25, trackbacks - 23

Thursday, August 30, 2007

More about code structure

Long time, no blogging. Sorry about that, but I have had a LONG summer vacation. Really nice.

Lately I have actually been doing some Wordpress stuff. What started out with some simple customizations for
a client quickly turned into some deep WP hacking. I can say this, I am really impressed with the product. As a
pure publishing tool I doubt there is nothing beating it. If you can live with using Apache (well, technically IIS is possible, but when doing some url rewrites etc, which you most certainly want in Wordpress, it's a lot easier with Apache) . You also have to live with being tied to PHP and MySQL, of course. 

My first reflection after a few weeks of PHP hacking: I miss the ASP coding days in a way. If you don't know it,
coding in ASP and PHP are very much alike. You typically insert some PHP/ASP tags inside your HTML and just upload the page. Done... It simply allows for quick coding and quick results. While you *could* program the same way with ASP.NET there is almost like an unwritten law saying you should use code behind (what moron wrote that - oh, right, it was me...), you should create  multitiered (three layers are an absolute minimum, you know) applications etc.

And I agree, myself I *almost always* do use code behind, I almost always separate business layer/database layer/GUI in different dll:s etc and I really do believe in that model. But lets face it - we must question ourselves - WHY should
we separate our layers? And is it possible to achieve in some other way?

Take code reuse for one example. If you implement your FooBar business class inside a dll it means your ASP.NET app as well as your Windows app as well as your console batch routine etc can use it. Fine! But that could also be done with ASP and PHP, not involving any dll:s, but simply including a the FooBar.php/asp file.

Cause, back to Wordpress now, I am amazed over how well organized that code project is. Using a "simple" untyped language they have implemented a model which still allows for event handling etc, third party plugin registration etc.
Yes, it's all string based, meaning you register a hook for say "wp_footer" (in this example your function will be called each time the page footer is being rendered) - but it's still really easy because of the structure. The "correct" ASP.NET equivalent would be having the server app define an interface and the plugin implementing it.

To finish this ranting off - I will not leave my "structured way" of ASP.NET coding, it works really well for me,
but the Wordpress work I have done has kind of opened my eyes a little. I kind of have this idea "best practice is not what someone else says is best practice - best practice is what best for me" (maybe a luxury of being self employed being able to define my own models) so therefore I think it's important to think always try out new and different things.

 

 


   

posted @ Thursday, August 30, 2007 8:20 AM | Feedback (0)