Welcome Guest, Not a member yet? Register   Sign In
How do you compile your personal library functions
#1

[eluser]eboxhead[/eluser]
I've gotten to the point in my coding where I rely upon many functions that I've written myself. I originally compiled them into one large library script and usually auto loading that library.

I was wondering if this is the most efficient method for doing this or should I create smaller libraries and place them all in a subfolder, obviously only calling what I need?

Seeing as how I'm a self taught (and still always learning) coder, what is your chosen method of handeling this, and is there a best practice?
#2

[eluser]smilie[/eluser]
Well, try profiling your code, to see how much time / memory does loading that library takes. See Profiling CI.

What I usually do is group similiar functions into separate libraries, i.e. user functions (login / logout / check user / change pass etc) I would place in 1 lib and load that lib only where I need it. This way I can always trace back lib that I need by just looking at the name of it...

I think it is a resources overkill to load whole library with functions if you only use 3% of them for example.

But again, do some testing and then decide if the performance gain would be significant enough to split functions into multiple libs.

Cheers,
Smilie
#3

[eluser]eboxhead[/eluser]
Thanks, I hadn't thought of profiling. I will definitely try that.

My question wasn't for speed purposed though, I know that loading an entire library only to use a fraction of it will bog down the app, I'm looking as more of an ease of use when developing new apps to just add a folder of a compilation of your libraries or one large library.

I have started to dismantel the large library in favor of the smaller packages, but I just wanted to see what the world does Smile
#4

[eluser]Abdul Malik Ikhsan[/eluser]
i think, you can set include path in bootstrap or autoload Smile
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . './yourfolder/');
//add autoload func Smile
function __autoload($class_name) {
require_once $class_name . '.php';
}
?>
#5

[eluser]pbreit[/eluser]
Are we talking about 10 classes? 100? 1,000? You're probably fine leaving them in one class for now. Spend your energy elsewhere.
#6

[eluser]smilie[/eluser]
Pure for the coding purposes I love to have my code separated into logical groups. Some time I do manage to simply copy & paste files and re-use it in other project, but most of the time minor tweaks are needed...

On that note I would definately recommend to 'split' your code into more logical and usable files.

Cheers,
Smilie
#7

[eluser]Narkboy[/eluser]
I always divide things into their logical compartments. It helps me remember where things are but more importantly allows for compact, reusable, easy-to-upgrade components that are basically plugn-play within any CI site I've created.

My Auth lib is now at version 3.x - and I have sites running on at least 4 different versions, depending on when I set them up. As everything auth related is in one file (a model in this case) and the functions / vars are named the same, it dosen't matter which I use. Only the internals change, along with performace.

For most utility functions I keep them with the lib / model that needs them. There are a few site-wide functions that I use - I try to keep these in a utility class or helper, and load as required - never auto-load.

TBH - I've profiled several different ways and found no *huge* difference, but that's down to the specific functions and coding style, etc. Now I keep them the easiest way for me to develop without getting confused!

Go with what you feel works for you. The benefit of small sites is that you can do it all your way and you do't have to compromise with co-developers!!

/B




Theme © iAndrew 2016 - Forum software by © MyBB