0

Hey, I'm building my own platform mainly for a project, but, for my own personal use as well.. I'm also changing the style of programming that I do it in, and, setting up some rules..

I just wondered if there are any disadvantages to the way that I am setting things out:

Everything in functions, no "stray" code and a different formatting to if statements:

<?php

   $app = new StdClass;
	
	function compare($number1, $number2)
	{ 
	   if($number1 > $number2):
	      return true;
	   else:
	      return false;
	    endif;
	}
	function main()
	{
		// Main is automatically outputted. 
		// And, for the application to work must be initalised.
		
		$app->Number1 = 19;
		$app->Number2 = 3;
		
		if(compare($app->Number1, $app->Number2)):
		  echo 'Yes';
		else:
		  echo 'No';
		endif;
            return 1;
	}
 ?>

Can anyone see any problems with using this style? =)

Edited by phorce: n/a

5
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by phorce
2

It might be hard to mix PHP code with HTML with this style of programming. You will be more or less limited to generate all HTML code with PHP I guess. Is that what you really want? And what is the role of the line 3 above (initialization of StdClass)? Are the functions methods of the class?

0

would the compare function be better used as a method inside the class itself?

do the numbers need to be set as class properties?

$app->compare($number1,$number2);

Could set your numbers as properties AND give you the desired compare output.

public function compare($n1,$n2){
  $this->number1 = $n1; //youd need to validate these nos.
  $this->number2 = $n2; //these 2 lines perhaps not needed
  if($n1 > $n2){
    return true;
  }else{
    return false;
  }
}

just a thought

Edited by diafol: n/a

0

Heyy.. I know what you mean, but, I'm not going to mix the HTML and PHP together. The idea is that the HTML aspect is separate and the PHP handles the HTML.. =)

2

Why reinvent the wheel and try to create a code style guide from scratch when there are plenty of sensical, logical and well documented style guides out there already that are accepted and in use in lots of projects?

All you'll do with such a non-standard design is create a barrier that if you ever need someone to work on your code they'll spend more time trying to figure out the style than what it is they're tasked to do.

Votes + Comments
good comment - especially about collaborative coding
2

I try to stick to these standards where possible:

http://pear.php.net/manual/en/standards.php

However, I do stray sometimes when writing PURELY personal projects. Problem is, if I ever need to release the code to somebody else, for whatever reason, I find that I have to go and 'de-personalise' it. What a waste of time, if only I'd stayed on the standard track! :(

0

I try to stick to these standards where possible:

http://pear.php.net/manual/en/standards.php

However, I do stray sometimes when writing PURELY personal projects. Problem is, if I ever need to release the code to somebody else, for whatever reason, I find that I have to go and 'de-personalise' it. What a waste of time, if only I'd stayed on the standard track! :(

Yeah, I know what you mean.. I've learnt loads of "bad practices" when coding now to what I learnt a few years ago. :(

Thanks for everyones help btw =)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.