954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Building Platform

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? =)

phorce
Posting Whiz
362 posts since Jul 2011
Reputation Points: 31
Solved Threads: 26
 

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?

broj1
Posting Whiz
359 posts since Jan 2011
Reputation Points: 29
Solved Threads: 43
 

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

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

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.. =)

phorce
Posting Whiz
362 posts since Jul 2011
Reputation Points: 31
Solved Threads: 26
 

What is the reason you choose if: else: endif; over curly brackets ?

pritaeas
Posting Expert
Moderator
5,483 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

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.

mschroeder
Work Harder
Team Colleague
666 posts since Jul 2008
Reputation Points: 279
Solved Threads: 131
 

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! :(

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

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 =)

phorce
Posting Whiz
362 posts since Jul 2011
Reputation Points: 31
Solved Threads: 26
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: