• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Code sharing between parts of your website

Joined
Sep 26, 2015
Likes
2
#1
As programmers, the less code you have to write, the more stable it is. One way to achieve less code is to avoid redundant code as much as possible, because you won't probably remember everything at each time you redo the same functionality. For example, in a counter, if you do it once for all, you will likely bring all features, but if you do redundantly two counter codes, it is likely you will forget to save appropriately the count in one of the redundant code. So the best thing to do is to share the code across the two parts of your website needing it.

But I would like to know how you could realize this? How would you make it possible?
 
Joined
Sep 26, 2015
Likes
2
#3
-su-;n1497 wrote: I would use PHP and build a functions file and include it in your PHP files that need it.
For sharing the simplest part, I would agree, but I would also focus on classes if we speak about PHP. A class allow to remember a full state about something in your app (for example, the state of the parsing system for your BBcode) that functions can't bring that easily, so I would have expected more classes sharing. But PHP and oriented-object usage is pretty low compared to other languages since people under-use the PHP features. JavaScript has the same problem, after all.

As well, includes, okay, but how to separate files? What functions/classes should contain each includes, or each file you include? Separating correctly is as important.
 
Top Bottom