User Guide: Libraries vs Core Classes

#11
[eluser]oribani[/eluser]
[quote author="BrianDHall" date="1252647614"]Actually, I don't know that I understand the real difference between a plugin and a library.

I think the idea of a helper is just that its suppose to be some useful functions that are useful everywhere - the reason for the destinction is that they are not object oriented. Once loaded they behave like a native PHP function, that is to say you can just call sha1() or md5() or trim() anywhere.
[/quote]

Yeah, that's their justification for the difference between "library" and "helper", but why? I'm not sure there is a definitive definition of a "library", but to me procedural functions ring more true to the definition, or at least not less so than object oriented code. In the end, procedural versus object oriented has NOTHING to do with "library" as far as I know.

[quote author="BrianDHall" date="1252647614"]Libraries and plugins, to my understanding, are more object oriented and they are more tightly integrated and organized. For instance in file uploads $this->upload->data() is meaningless and useless unless you are using the other functions of the upload class, or the Session class - their functions only work if you use the whole library. Meanwhile the HTML helper function img() is just handy in all sorts of places.

Core classes mean they are available on all CI systems.

Plugins is what I flat don't know about - what's the difference in a plugin and a library?
[/quote]

No. See: http://ellislab.com/codeigniter/user-gui...ugins.html
"Plugins work almost identically to Helpers. The main difference is that a plugin usually provides a single function"

A plugin is basically synonymous with a helper except that it's supposed to contain just one function. Not sure why that is, since the loading mechanism for both seems to just be a simple include_once.

[quote author="BrianDHall" date="1252647614"]The manual does need cleaned in this respect, but we must first know and agree what is correct before we can attempt to explain it to others.

EDIT:

On extending core classes, you are not 'supposed' to ever change a core class, because you become locked into those changes and cannot easily upgrade to newer versions of CI, and if you run into a problem it may be hard to get help from others because they have different code than you do.

Hm, is this the difference with what a plugin is? Is a plugin what you put in the same directory as the core classes that automatically over-ride the underlying classes automagically?[/quote]

No. See above - plugins are not related to core classes. And extending or replacing core classes IS SUPPORTED. It's the same thing as extending or replacing libraries (there is no difference from what I can tell, which is the subject of this thread). You don't edit the core class code - you put your override/extension in the application/libraries/ directory.

[quote author="BrianDHall" date="1252647614"]Then extending a core class is different because it is not automatic. You can make a MY_Controller class, but if you don't explicitly make a controller that extends "MY_Controller" instead of "Controller", then your special controller class doesn't get used.

Am I on the right track?[/quote]

Yes, from what I can tell, you need to make sure you extend "MY_Controller" in your controller files, but you are not correct about how core classes are overridden and supported.

#12
[eluser]oribani[/eluser]
While I'm at it... I think there was a mis-use of "its" or "it's" somewhere earlier in the user guide, but I didn't bother to note where it was.

But I thought I'd add that the "Enabling Transactions" section of

http://ellislab.com/codeigniter/user-gui...tions.html

isn't written too well. The section title should probably be "Disabling Transactions" and it should be more detailed. At first I couldn't understand the difference between trans_off and trans_complete and what the example did (it doesn't say). Looks to me like trans_off makes any following trans_starts and other trans_* calls no-ops. The documentation should be more clear about that.

Oh, and I think "AN SQL QUERY" should be "A SQL QUERY" unless S is a vowel now.

#13
[eluser]oribani[/eluser]
[quote author="oribani" date="1252655027"]At first I couldn't understand the difference between trans_off and trans_complete and what the example did (it doesn't say). Looks to me like trans_off makes any following trans_starts and other trans_* calls no-ops. The documentation should be more clear about that.

Oh, and I think "AN SQL QUERY" should be "A SQL QUERY" unless S is a vowel now.[/quote]

Sorry, I should have mentioned that part of the confusion here is because it says "Transactions are enabled automatically the moment you use $this->db->trans_start()". So, when the example starts with trans_off and then trans_start, I thought it turns transactions off and then turns them back on again immediately. Reading the code, I think trans_start doesn't really "automatically enable" transactions at all, at least if you have called trans_off. Simple, but really confusing as documented.

#14
[eluser]oribani[/eluser]
[quote author="oribani" date="1252650589"]
[quote author="jedd" date="1252647934"]
I imagine your Open Source reference (I'm very much a free software vernacular kind of guy) was uttered in much the same tone that people usually reserve for complaining about how governments never do the right thing AND how they are asked, every four years, to allocate an hour or so of their time to do something vaguely democratic. Not really embracing the classic Greek tradition of being a good citizen, I've often thought.

But thanks for dropping in and spending a few moments to complain about the manual, in any case.[/quote]

No, that wasn't my meaning. I meant to acknowledge that it is indeed my responsibility as much as anyone else's to do something about it. My "sorry that I can't" was sincere.[/quote]

Actually, now that I think about it, I don't find CI to be quite as open as your normal FOSS project. The EllisLab people seem to develop it privately and I am not aware of there being a way for anyone not part of their company/business to join and contribute. I haven't seen a public SCM anywhere, either. Sure, they might accept contributions and patches at their discretion, but this isn't an entirely open or transparent model. I imagine that could come in for a bit of criticism from some people.

I am only just getting started with CI, so I may very well have missed something (or not seen it yet), so please correct me if I'm wrong.

#15
[eluser]wiredesignz[/eluser]
@oribani, There is a more appropriate place to post details of any spelling mistakes that you may have discovered in the User Guide.

As for helpers vs libraries, you are correct that any file containing one or more related functions or methods is termed a library. However for the sake of getting into the CodeIgniter frame of mind you are asked to consider the functionality of these libraries when describing them.

Controllers, Models and Views are pretty self explanatory.

CodeIgniter helpers are libraries of related procedural functions and they have global scope.

All CodeIgniter library files contain related object oriented methods and they are automatically instantiated by the core loader class and attached to the controller object for you.

Core libraries can be replaced by your own that bear the same file name but they must contain the "CI_" class prefix which makes them different to your user libraries.

Core libraries can be extended by your own that bear the subclass prefix of the core library file name and class name.

I don't believe you can replace and extend a core library at the same time. (untested)

Plugin's are also libraries which are loaded but are not instantiated by the framework, therefore they can be procedural or object oriented. (the single function in a plugin idea is not enforced.)

I'm not sure if this helps, but in any case understanding all of this is very much a CodeIgniter framework thing.

#16
[eluser]oribani[/eluser]
[quote author="wiredesignz" date="1252659407"]@oribani, There is a more appropriate place to post details of spelling mistakes that you may have discovered in the User Guide.[/quote]

So are you going to share that location, then?

[quote author="wiredesignz" date="1252659407"]As for helpers vs libraries, you are correct that any file containing one or more related functions or methods is termed a library. However for the sake of getting into the CodeIgniter frame of mind you are asked to consider the functionality of these libraries when describing them.[/quote]

I can see that you might try to establish some differences between certain libraries based on their functionality, but in this case, "helper" to me isn't indicative of any particular functionality, and in fact "helper" and "library" don't have substantive differences in the meanings of the words themselves. If you have a concrete difference in functionality, the names should indicate it.

I'm not sure I see the functional difference, either, but one thing seems certain, "native libraries" and "core classes" seem to be the same thing, and the user guide should really be changed to clear up that confusion.

[quote author="wiredesignz" date="1252659407"]Controllers, Models and Views are pretty self explanatory.

CodeIgniter helpers are libraries of related procedural functions and have global scope.

All CodeIgniter library files contain related object oriented methods and they are automatically instantiated by the core loader class and attached to the controller object.[/quote]

So here you seem to be pointing out that libraries are only usable within the scope of the controller where they were loaded. If that's the case, maybe "libraries" should be "controller libraries" and "helpers" should be "global libraries" or something like that.

[quote author="wiredesignz" date="1252659407"]Core libraries can be replaced by your own that bear the same filename but they must contain the "CI_" class prefix which makes them different to user libraries.[/quote]

But like I've said a couple times here, the issue I was looking at really didn't have anything to do with your own custom libraries.

But anyway, going with what I suggested above, then you might have "core controller libraries" (are core libraries scoped only to the controller?), "custom controller libraries" and "global libraries". I didn't put a lot of thought into those names, so there may be something better.

Or if you want to harp on the "functional" differences, maybe it makes more sense to be really clear: these "libraries" are really class objects when you use them, aren't they? (as you note, they are in fact instantiated for you) So why not "object libraries" or "controller object libraries" to indicate their scope as well. That would be clearly different than "helpers" and "plugins", which would be better understood as "global function libraries".

Oh, and core vs. your own "libraries" could be distinguished as "core controller object libraries" and "custom controller object libraries".

In the end, it's not a big deal if you understand how it all works. I'm just pointing out that the distinctions are arbitrary and in some cases are more confusing than they should be (and maybe the arbitrary nature of the distinctions should be explicitly pointed out).

[quote author="wiredesignz" date="1252659407"]Plugins are also libraries which are loaded but not instantiated by the framework.[/quote]

But here you contradict the nomenclature yourself. As I noted previously, helpers and plugins do appear identical, especially given that they both seem to be loaded with a simple include_once. So if you are trying to keep with the "functional" distinction you are trying to point out, plugins are HELPERS, not libraries. But really, they're all libraries, aren't they?

[quote author="wiredesignz" date="1252659407"]I'm not sure if this helps, but in any case understanding all of this is very much a CodeIgniter framework thing.[/quote]

I don't buy that. That's like saying you just have to accept it because that's the way it is. The nomenclature is arbitrary. And plugins seem pretty unnecessary too when they could just be put in the helpers directory anyway. I won't lose sleep over what are in the end minor points, but at this point it really does seem like the user guide is flawed at least where it confuses "core libraries" with "native libraries" on the two pages I pointed out.

#17
[eluser]wiredesignz[/eluser]
Paying you lip service beyond my original post is counter productive, so I'll leave this.

I will be interested to see if you actually contribute anything to the community more than this diatribe.

Good luck in your endeavours.

#18
[eluser]oribani[/eluser]
[quote author="wiredesignz" date="1252665529"]Paying you lip service beyond my original post is counter productive, so I'll leave this.

I will be interested to see if you actually contribute anything to the community more than this diatribe.

Good luck in your endeavours.[/quote]

C'mon. Just because I'm new to this particular tool doesn't mean that I can't point out inconsistencies with it. I don't have to prove myself - my points and whether or not they make sense is all that matters. If you can't reply with a constructive message, then don't bail out with snide remarks at me. THAT is what is not cool.

#19
[eluser]n0xie[/eluser]
[quote author="oribani" date="1252670770"]
C'mon. Just because I'm new to this particular tool doesn't mean that I can't point out inconsistencies with it. I don't have to prove myself - my points and whether or not they make sense is all that matters. If you can't reply with a constructive message, then don't bail out with snide remarks at me. THAT is what is not cool.[/quote]
The distinction between a core class and a library becomes quite clear once you use them (which would make this whole discussion a waste of time), which is probably why no one has thus far complained about it. I'm not saying your point isn't valid, it just seems to me like you never actually tried using the framework, but gladly offer your opinion about it.

I would suggest using the framework for a week, and if you still have problems grasping what a core class is and where it differs from a library or an helper, I'm pretty sure the community at large will gladly guide you on your way.

#20
[eluser]wiredesignz[/eluser]
@oribani, Nobody is bailing, but what is NOT cool is your compulsion to publicly berate CodeIgniter over things that don't bother anyone else.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.