Jump to content

Module vs function


webhoes
 Share

Recommended Posts

Hello,

A general questions.

A recently made a tag cloud for my website. I looked at an old module for that and based on that logic created a function in my _func.php. It contains a fourth of the code and does the same.

I am curious in wether there a great differences in doing something via a function or making a module for it. Specially the pro's and cons for each like speed, maintainability or what is best practice.

Sanne

Link to comment
Share on other sites

I've been doing functions from the start, but more recently I've had a couple of instances where I go for a custom module.

I can't really speak in terms of performance, haven't made any tests, but the module approach feels better when there's more than one or two functions, to organise everything more neatly.

Example: I'm working on an online store built from scratch. In that project the server shoots emails all the time. On register, on purchase, on order status changes, etc. Each email has a template that can be edited in the CMS. It becomes complex having to handle multiple templates and usage scenarios, replacing variables, different results based on context, so turning it into a module made it much more organised.

I guess for me it's about volume and reusability. If it's small stuff I don't bother.

  • Like 2
Link to comment
Share on other sites

i don't think there is any noticable performance difference (just guessing). the main difference imho is reusability. for small things functions are totally fine. there is a reason why the _func.php file exists in the profile ;) but if you use your function across several pw installations it's for sure better to pack them in a module, host them on some version control system and push updates to all of your sites easily whenever you want. that could get tedious when you have your code spread all over your sites and _func files...

  • Like 2
Link to comment
Share on other sites

Those are very clear answers. Thanks :D

Currently all functions are specific to a site as they also contain small parts of the template.

I do see stuff coming in the future that could be used in more sites. By then I should make it a module.

Making a module would be the next challange to learn.

Link to comment
Share on other sites

1 hour ago, webhoes said:

Making a module would be the next challange to learn.

i encourage you to take this challenge as soon as possible. it's really not hard and it will make your head think differently in some situations and make your code cleaner and easier to maintain. and in the end that will save you time ;)

have fun :)

  • Like 2
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...