Sticking to CodeIgniter practices vs. making things easier for new developers to pick up - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Sticking to CodeIgniter practices vs. making things easier for new developers to pick up (/showthread.php?tid=2844) |
Sticking to CodeIgniter practices vs. making things easier for new developers to pick up - El Forum - 08-27-2007 [eluser]charlieD[/eluser] Some of CodeIgniter's functionality is very useful; however sometimes I think the framework-specific ways of doing things would just make it harder for new developers (who perhaps aren't familiar with CodeIgniter) to pick up. For example, there are a few 'helper' functions which just appear to be one line wrappers for a simple native PHP function, possibly with a tiny benefit. In other situations, it's less clear whether using the framework would be beneficial or not. For example, when adding a general function to deal with an array task, CodeIgniter's rules would say this would be added as a 'helper'. However, I personally would find it easier to follow if the function is wrapped in a 'Utils' class, e.g. $this->utils->doSomething(); rather than doSomething() makes it easier to follow and find the doSomething() method. What is the best practice in situations like this? Is this a matter of personal preference or is it strongly recommended that you stick to the Framework at all times? Sticking to CodeIgniter practices vs. making things easier for new developers to pick up - El Forum - 08-27-2007 [eluser]Michael Wales[/eluser] I say whatever will help you develop your application and maintain it the best. Like Jolly said in this post: Quote:My take: Sticking to CodeIgniter practices vs. making things easier for new developers to pick up - El Forum - 08-28-2007 [eluser]Rick Jolly[/eluser] [quote author="charlieD" date="1188295538"] For example, when adding a general function to deal with an array task, CodeIgniter's rules would say this would be added as a 'helper'. However, I personally would find it easier to follow if the function is wrapped in a 'Utils' class, e.g. $this->utils->doSomething(); rather than doSomething() makes it easier to follow and find the doSomething() method. [/quote] Since you probably don't need an instance of the Utils class you could call methods staticly: Utils::doSomething();. CI doesn't have any obvious way to create static classes. If you made a library CI would instantiate it. You could create a helper though, and instead of defining functions you could make it a class. That way CI wouldn't instantiate it and you could call methods statically: HelperClassName:omeStaticMethod();. Sticking to CodeIgniter practices vs. making things easier for new developers to pick up - El Forum - 08-28-2007 [eluser]charlieD[/eluser] Static classes was something I thought was oddly missed out by CodeIgniter; this is a nice solution. |