Hall of Famer Posted September 9, 2012 Share Posted September 9, 2012 As far as I know, two common indent styles exist in the programming world: K&R and Allman. Well not to be disrespectful for other indent styles, I am just talking about the two most widely used ones. For me, I've been coding with K&R styles throughout my life, and find it more comfortable personally. I do, however, realize that most PHP frameworks use Allman indenting style, good examples are Zend Framework, Symfony and Codeignitor. CakePHP is perhaps the only framework stick to K&R intent style. I was wondering though, how many of you here are advocates for K&R or Allman style. And why? I was told before that it was just a matter of preference, like the color we choose for our shirts. But is it really so? Are there any other important reasons behind this preference? Is it just a coincidence that CakePHP is the only popular PHP framework using K&R? Quote Link to comment https://forums.phpfreaks.com/topic/268181-indent-styles/ Share on other sites More sharing options...
ignace Posted September 9, 2012 Share Posted September 9, 2012 I use the PSR standard. Quote Link to comment https://forums.phpfreaks.com/topic/268181-indent-styles/#findComment-1376424 Share on other sites More sharing options...
Hall of Famer Posted September 9, 2012 Author Share Posted September 9, 2012 Oops, just found that Lithium uses K&R indent style, guess Cake is not the loner afterall. Quote Link to comment https://forums.phpfreaks.com/topic/268181-indent-styles/#findComment-1376426 Share on other sites More sharing options...
scootstah Posted September 9, 2012 Share Posted September 9, 2012 I use the PSR standard. I do as well for the most part. But, I use tabs for indenting. Quote Link to comment https://forums.phpfreaks.com/topic/268181-indent-styles/#findComment-1376433 Share on other sites More sharing options...
trq Posted September 9, 2012 Share Posted September 9, 2012 But, I use tabs for indenting. ewww. Quote Link to comment https://forums.phpfreaks.com/topic/268181-indent-styles/#findComment-1376435 Share on other sites More sharing options...
scootstah Posted September 9, 2012 Share Posted September 9, 2012 Old habits die hard I guess. Quote Link to comment https://forums.phpfreaks.com/topic/268181-indent-styles/#findComment-1376437 Share on other sites More sharing options...
The Little Guy Posted September 9, 2012 Share Posted September 9, 2012 I have just recently started using spaces for tabbing... I use K&R Variant: 1TBS Here is a small list: http://en.wikipedia.org/wiki/Indent_style Quote Link to comment https://forums.phpfreaks.com/topic/268181-indent-styles/#findComment-1376440 Share on other sites More sharing options...
premiso Posted September 9, 2012 Share Posted September 9, 2012 But, I use tabs for indenting. ewww. I use tabs as well, not really sure why, but I like that I can change the tab size to be 2 "spaces" vs having to do 4 spaces all the time without much room for manipulating. Just my preference though. Quote Link to comment https://forums.phpfreaks.com/topic/268181-indent-styles/#findComment-1376461 Share on other sites More sharing options...
kicken Posted September 9, 2012 Share Posted September 9, 2012 I kind of have my own style I guess. From reading through the wiki-list it probably resembles 1TBS the most. I put the opening brace after the expression (eg if ($blah){). Having it on it's own line annoys me to no end. I use tabs for an indent rather than spaces. I rarely have any issues with this, but I can understand why spaces would be preferred in a large multi-coder environment. If I end up needing to split something across multiple lines, I usually do something like this: $a = sprintf("Welcome %s, your color is %s and your symbol is %s\r\n", $name, $color, $symbole ); or if ( $a == $b || ($c == $b && $x==$y ){ blah(); } I generally don't care what style someone uses, so long as it is readable and not a big wild mess like some people post to the forums here. Quote Link to comment https://forums.phpfreaks.com/topic/268181-indent-styles/#findComment-1376463 Share on other sites More sharing options...
scootstah Posted September 9, 2012 Share Posted September 9, 2012 and not a big wild mess like some people post to the forums here. class HTMLPurifier { /** Version of HTML Purifier */ public $version = '4.3.0'; /** Constant with version of HTML Purifier */ const VERSION = '4.3.0'; /** Global configuration object */ public $config; /** Array of extra HTMLPurifier_Filter objects to run on HTML, for backwards compatibility */ private $filters = array(); /** Single instance of HTML Purifier */ private static $instance; protected $strategy, $generator; /** * Resultant HTMLPurifier_Context of last run purification. Is an array * of contexts if the last called method was purifyArray(). */ public $context; /** * Initializes the purifier. * @param $config Optional HTMLPurifier_Config object for all instances of * the purifier, if omitted, a default configuration is * supplied (which can be overridden on a per-use basis). * The parameter can also be any type that * HTMLPurifier_Config::create() supports. */ public function __construct($config = null) { $this->config = HTMLPurifier_Config::create($config); $this->strategy = new HTMLPurifier_Strategy_Core(); } /** * Adds a filter to process the output. First come first serve * @param $filter HTMLPurifier_Filter object */ public function addFilter($filter) { trigger_error('HTMLPurifier->addFilter() is deprecated, use configuration directives in the Filter namespace or Filter.Custom', E_USER_WARNING); $this->filters[] = $filter; } /** * Filters an HTML snippet/document to be XSS-free and standards-compliant. * * @param $html String of HTML to purify * @param $config HTMLPurifier_Config object for this operation, if omitted, * defaults to the config object specified during this * object's construction. The parameter can also be any type * that HTMLPurifier_Config::create() supports. * @return Purified HTML */ public function purify($html, $config = null) { // :TODO: make the config merge in, instead of replace $config = $config ? HTMLPurifier_Config::create($config) : $this->config; // implementation is partially environment dependant, partially // configuration dependant $lexer = HTMLPurifier_Lexer::create($config); $context = new HTMLPurifier_Context(); // setup HTML generator $this->generator = new HTMLPurifier_Generator($config, $context); $context->register('Generator', $this->generator); // set up global context variables if ($config->get('Core.CollectErrors')) { // may get moved out if other facilities use it $language_factory = HTMLPurifier_LanguageFactory::instance(); $language = $language_factory->create($config, $context); $context->register('Locale', $language); $error_collector = new HTMLPurifier_ErrorCollector($context); $context->register('ErrorCollector', $error_collector); } // setup id_accumulator context, necessary due to the fact that // AttrValidator can be called from many places $id_accumulator = HTMLPurifier_IDAccumulator::build($config, $context); $context->register('IDAccumulator', $id_accumulator); $html = HTMLPurifier_Encoder::convertToUTF8($html, $config, $context); // setup filters $filter_flags = $config->getBatch('Filter'); $custom_filters = $filter_flags['Custom']; unset($filter_flags['Custom']); $filters = array(); foreach ($filter_flags as $filter => $flag) { if (!$flag) continue; if (strpos($filter, '.') !== false) continue; $class = "HTMLPurifier_Filter_$filter"; $filters[] = new $class; } foreach ($custom_filters as $filter) { // maybe "HTMLPurifier_Filter_$filter", but be consistent with AutoFormat $filters[] = $filter; } $filters = array_merge($filters, $this->filters); // maybe prepare(), but later for ($i = 0, $filter_size = count($filters); $i < $filter_size; $i++) { $html = $filters[$i]->preFilter($html, $config, $context); } // purified HTML $html = $this->generator->generateFromTokens( // list of tokens $this->strategy->execute( // list of un-purified tokens $lexer->tokenizeHTML( // un-purified HTML $html, $config, $context ), $config, $context ) ); for ($i = $filter_size - 1; $i >= 0; $i--) { $html = $filters[$i]->postFilter($html, $config, $context); } $html = HTMLPurifier_Encoder::convertFromUTF8($html, $config, $context); $this->context =& $context; return $html; } /** * Filters an array of HTML snippets * @param $config Optional HTMLPurifier_Config object for this operation. * See HTMLPurifier::purify() for more details. * @return Array of purified HTML */ public function purifyArray($array_of_html, $config = null) { $context_array = array(); foreach ($array_of_html as $key => $html) { $array_of_html[$key] = $this->purify($html, $config); $context_array[$key] = $this->context; } $this->context = $context_array; return $array_of_html; } /** * Singleton for enforcing just one HTML Purifier in your system * @param $prototype Optional prototype HTMLPurifier instance to * overload singleton with, or HTMLPurifier_Config * instance to configure the generated version with. */ public static function instance($prototype = null) { if (!self::$instance || $prototype) { if ($prototype instanceof HTMLPurifier) { self::$instance = $prototype; } elseif ($prototype) { self::$instance = new HTMLPurifier($prototype); } else { self::$instance = new HTMLPurifier(); } } return self::$instance; } /** * @note Backwards compatibility, see instance() */ public static function getInstance($prototype = null) { return HTMLPurifier::instance($prototype); } } What's wrong with that? Quote Link to comment https://forums.phpfreaks.com/topic/268181-indent-styles/#findComment-1376498 Share on other sites More sharing options...
The Little Guy Posted September 9, 2012 Share Posted September 9, 2012 That is how you know someone still uses notepad to edit Quote Link to comment https://forums.phpfreaks.com/topic/268181-indent-styles/#findComment-1376519 Share on other sites More sharing options...
scootstah Posted September 9, 2012 Share Posted September 9, 2012 All the cool cats use Microsoft Word. Quote Link to comment https://forums.phpfreaks.com/topic/268181-indent-styles/#findComment-1376520 Share on other sites More sharing options...
Pikachu2000 Posted September 9, 2012 Share Posted September 9, 2012 WordStar 2.26 on my Osborne 1. (That's right bitches, I'm stylin') Quote Link to comment https://forums.phpfreaks.com/topic/268181-indent-styles/#findComment-1376542 Share on other sites More sharing options...
Christian F. Posted September 10, 2012 Share Posted September 10, 2012 Something very similar to K&R Variant: 1TBS, but with a few differences. For instance, having the opening bracket on the same line as the statement, for all statements. Even though it's function/class definitions, or whatever. Makes things more consistent, if you ask me. Tabs all the way, set to 4 characters wide. Quote Link to comment https://forums.phpfreaks.com/topic/268181-indent-styles/#findComment-1376552 Share on other sites More sharing options...
The Little Guy Posted September 10, 2012 Share Posted September 10, 2012 Chuck Norris uses MS Paint Quote Link to comment https://forums.phpfreaks.com/topic/268181-indent-styles/#findComment-1376559 Share on other sites More sharing options...
Jessica Posted September 10, 2012 Share Posted September 10, 2012 a big wild mess like some people post to the forums here. I swear to god this is what some of my coworkers do. They all have something else in common too. I should find out what editor they use. I spent 30 minutes once cleaning up some indenting (yes, I know a real IDE can do it for me, shut up.) Quote Link to comment https://forums.phpfreaks.com/topic/268181-indent-styles/#findComment-1376608 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.