Best practice to maintain your code readability, etc. |
Just wondering how other people maintain their codes without sacrificing its readability?
Since I am a home-based (and newbie) web developer, I don't have experience working with other developers (especially on a big projects). Love to hear your experiences Kaitenz
@kaitenz,
Using the CI Style/coding guide is definitely a good starting place ( https://codeigniter.com/userguide3/gener...guide.html ). This way there are no questions of your expectations from other developers who may work with you. Are you #TeamTabs or #TeamSpaces?
Skinny controllers, fat models - try to keep your functionality and business logic in models, that way it's easily re-usable.
Another thing I sometimes do when I have more time to pre-plan, I start writing mock model-methods in controllers to see how it lays out, then filling in functionality for methods afterwards.
Ironical the Docs state always use the following example and never use it in their own examples
>>> if (strpos($str, 'foo') === FALSE)
Take the time to learn Php heredoc because lengthy lines can be drastically simplified and understood at a single glance.
Always use Php 7 and learn how to use declare(strict_types=1); Declare a function's return type and always only have a single return in every function/method.
...and not forgetting...
Never ever use Css styles in Libraries, Controllers or Models which I have learnt from bitter experience in trying to debug Views. (07-10-2018, 08:16 AM)php_rocs Wrote: @kaitenz,I'm on #TeamTabs (07-10-2018, 01:48 PM)Pertti Wrote: Skinny controllers, fat models - try to keep your functionality and business logic in models, that way it's easily re-usable.Wow. We are on the same page. I have a controller named "Test" where I test some codes/models/libraries/helpers in this controller. (07-10-2018, 05:31 PM)John_Betong Wrote: Take the time to learn Php heredoc because lengthy lines can be drastically simplified and understood at a single glance.Heard them before. Haven't tried to use it. Maybe this is the time.. Hahaha. (07-10-2018, 06:23 PM)John_Betong Wrote: ...and not forgetting...Same. I always separate them. Just like in JavaScript, I don't like using the in-line JS thing because it is messy and hard to maintain. But that is just my taste and maybe it is useful to others but not to me.
Just want to add this so if someone saw this thread (maybe because we are on the same page):
(03-27-2018, 09:08 AM)jreklund Wrote: You should not use xss_clean on input Darn! I always use xss_clean() on input. That's why when I tried to hack my own creation, I always outputting something like this: Code: [removed]script[removed]
Another neat way to simplify code is to drop nested if-else statements and exit method as early as possible.
PHP Code: public function test($input) Could be simplified to: PHP Code: public function test($input)
(07-10-2018, 11:24 PM)Pertti Wrote: >>> Another neat way to simplify code is to drop nested if-else statements and exit method as early as possible. As mentioned I prefer declaring a default $result and only returning a single $result. Each to their own PHP Code: //=================================== |
Welcome Guest, Not a member yet? Register Sign In |