Pseudo Code

pickledegg

Active member
Nov 9, 2008
1,191
20
38
chrisjallen.com
Can anyone improve on this?

Code:
function punchintheface($victim = $someoneIHate){
  if(!in_array($victim,$peopleIcanstomach){
  $punch = true;
  return $punch;
}

do {
punchintheface();
} while ($victim === CONSCIOUS);
 


function punchintheface($victim = $someoneIHate)
{
if(!in_array($victim,$peopleIcanstomach){
$punch = true;
return $punch;
}

do {
punchintheface();
} while ($victim != CONSCIOUS);
 
Code:
def punch(victim,friends=['dan','frank','simon']):
    return victim not in friends
    
concious = False
while not concious:
    punch(victim)
infinite as concious is never possibly modified.

why assign a return value to a variable?
 
inb4 uplinked tells me to use a tuple for slight efficiency gains
You might consider refactoring your example to use a tuple, for efficiency reasons; as the "Friends" array is never modified, using an immutable datastructure here would be more proper.

Also, instantiating the array in the method declaration as a default argument value will cause the object to get re-created on every function call, leading to unnecessary memory usage. A better solution would involve declaring the array in a higher scope and referencing it in the function (either implicitly by allowing the scope to pass down from parent, or explicitly by passing the array as a function parameter).

[/codesnob]
 
You might consider refactoring your example to use a tuple, for efficiency reasons; as the "Friends" array is never modified, using an immutable datastructure here would be more proper.

Also, instantiating the array in the method declaration as a default argument value will cause the object to get re-created on every function call, leading to unnecessary memory usage. A better solution would involve declaring the array in a higher scope and referencing it in the function (either implicitly by allowing the scope to pass down from parent, or explicitly by passing the array as a function parameter).

[/codesnob]

Well what do you know I don't even have the urge to punch anyone anymore. :updown:
 
pfft @ you python guys (it's python, right? right??)

oo php is teh way to go.

Code:
class prepare {
	function lunge($goal) {
		$out['arm'] = array('elbow'=>'pullBack','upper_arm'=>'raise');
		$out['hand'] = $this->doFist('outside');
		return ($out ? $out : 'run_away');
	}
	
	function doFist($thumbPosition='inside') {
		$fist['fingers'] = 'interlock';
		$fist['thumb'] = $thumbPosition;
		return ($fist ? $fist : $this->TakeYogaClass());
	}
}

class punch {
	__construct() {
		$this->prepare = new prepare();
	}

	private function nuts() {
		var_dump($dignity);
		$goal = $this->aim('center');
		$punch = $this->prepare->lunge($goal);
		return $punch;
	}
}

$punch = new punch();
echo $punch->nuts();
 
ha. it's on the list man, definitely soon! I have to take care of a few things first. I'll probably just jump on a plane spontaneously one of these days. That's how I usually end up doing trips... I gave up on planning them lol.