• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Helpers and Other Conventions

#1
It's better to implement InterCaps/BaseCaps for classes and camelCasing for methods. I'm not exactly sure if https://github.com/bcit-ci/CodeIgniter4/...helper.php is the official GitHub repository however, it would be nice to have something like:

Code:
use Helpers\UrlHelper;

UrlHelper::site(string $path = '', string $scheme = null)
UrlHelper::base(string $path = '', string $scheme = null)
UrlHelper::current(bool $returnObject = false)
UrlHelper::uri()
UrlHelper::index()

The methods are mostly static in order to imply implicit method calls. I also noticed the parent folder HTTP which, looks a bit odd. If all caps is applied, the filename would look like URLHelper.php instead of UrlHelper.php. Root folders are lower-cased as well. Is it for BC?
Long live CodeIgniter!
Reply

#2
Here's the styleguide: https://bcit-ci.github.io/CodeIgniter4/c...guide.html

However, we don't have any plans at the moment to convert helpers to static classes. I've always been told that simply shoving a bunch of procedural functions into a class is "doing OOP wrong", so that's where my bias comes from. I will admit the syntax is, in some ways, nicer, and in other ways not to much. I can also see it being problematic with things like the form validation, if it stays anywhere close to how it is, and maybe some other things we have cooking.
Support Development  • Practical CodeIgniter 3  •
Myth:AuthVulcan - CLI Tools for CI4
Reply

#3
Cool. Perhaps camelCased functions would be enough. It's in the Procedural Code section in the styleguide however, underscores don't seem to be consistently used anymore on modern PHP functions or methods. Keep up the good work guys! Excited for CI4...
Long live CodeIgniter!
Reply

#4
(06-28-2016, 09:06 PM)kilishan Wrote: Here's the styleguide: https://bcit-ci.github.io/CodeIgniter4/c...guide.html

However, we don't have any plans at the moment to convert helpers to static classes. I've always been told that simply shoving a bunch of procedural functions into a class is "doing OOP wrong", so that's where my bias comes from. I will admit the syntax is, in some ways, nicer, and in other ways not to much. I can also see it being problematic with things like the form validation, if it stays anywhere close to how it is, and maybe some other things we have cooking.

It's not OOP at all, you're not using objects.
The only reason for that usage is lack of function autoloading.
Reply

#5
I believe Validation is fine instead of FormValidation. I recall CI3 had Rules http://icecream.me/3b712753751a989683ac6f3995f37f0b. Having them as constants would be nice: Validation::REQUIRED, Validation::MATCHES, Validation::IS_UNIQUE, and so forth.

I noticed second thoughts about keeping the Helper Doc http://icecream.me/26b32b0970667b87a1a3242b05208320. Shouldn't it be like this http://icecream.me/358033b5c59bada3ae6696b2900bcc4e?
Long live CodeIgniter!
Reply

#6
The helpers that will be in CI4 will be implemented as part of Phase 2, per the roadmap. The user guide will be updated then too.
Reply

#7
(06-29-2016, 01:17 AM)Narf Wrote: It's not OOP at all, you're not using objects.
The only reason for that usage is lack of function autoloading.

Sure it is. Classes are objects, and it's got methods. That makes it a (really poorly designed) object, right? Smile But, yes, I know what you mean.

The other valid reason I've heard for doing that is it limits the global function pollution. Neither one of those are good enough reasons for me to consider the change, though.
Support Development  • Practical CodeIgniter 3  •
Myth:AuthVulcan - CLI Tools for CI4
Reply

#8
Interesting read about this:

Are PHP developers functophobic?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#9
(06-29-2016, 06:26 AM)InsiteFX Wrote: Interesting read about this:

Are PHP developers functophobic?

I would say that, yes, yes they are. Smile

Reminds me of a cartoon I saw once but cannot find right now that went through a progression as a developer got more experienced from a really simple solution as a new coder to more and more OOP abstractions as they got better, until the veteran was doing the same thing as a new dev.

To be fair, though, it's a hard balance to keep sometimes, and there are lots of very loud voices out there telling us all how it should be done. It's hard to hear reason through the noise at times. Especially when we're all just trying to do it "the right way"
Support Development  • Practical CodeIgniter 3  •
Myth:AuthVulcan - CLI Tools for CI4
Reply

#10
functophobic is funny.
@kilishan I'm seeing your way about helpers. You're right. It is weird creating classes with only static methods in them. But 3 things would be nice for procedural helpers:
1. Please use camelCase function names
2. Use namespace. I hope this will remove the constant usage of function_exists() as well Smile
3. Use InterCaps (instead of snake_case as stated in the styleguide) for filenames

Code:
formOpen();
formClose();
urlBase(); //Helper name first.
urlSite(); //Helper name first.
csrfKey();
csrfValue();
Long live CodeIgniter!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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