Basic switch statement

Basic switch statement

am 13.04.2010 18:04:22 von steve_r

--0050450176cc38ba480484206a4c
Content-Type: text/plain; charset=ISO-8859-1

I'm new to programming, drive a truck in the day, now taking night courses
to get a better job for my family. Please bear with me if this is a dumb
question, I don't have much experience.

I'm taking a night class in HTML and PHP and can't figure out a problem and
can't find the answer in the book for the course ("Beginning PHP5" by Wrox
Press), on the switch manual page on php.net, or in any postings to this
mailing list.

I'm trying to pass a value to a simple integer to a function, and then use
that value in a switch statement. The problem I'm having is that regardless
of the value of 'val', the first case statement always executes. Even if I
put '$val = 0' right before the case statement, the first case statement
executes. The syntax looks correct based on the php.net man page for switch
and from the user examples. It also matches the example in the book.

function check_it2($val) {
echo gettype($val);
switch($val) {
case($val > 0 ):
echo "Switch greater than 0";
$diff_obj = 1;
break;
case($val < 0 ):
echo "Less than 0";
$diff_obj = -1;
break;
default:
echo "Equal to 0";
$diff_obj = 0;
}
print("Here's \$diff_obj2 in the function: " . $diff_obj);
return $diff_obj;
}

I even put the following code before the switch statement just to make sure
I'm not crazy:

$val = 0;
if($val > 0) {
echo "If greater than 0";
}
else {
echo "If not greater than 0";
}

and it falls through to the else as it should.

I've tried putting single and double quotes around the case variables but it
always prints out the first value. I've recoded to use a series of if
statements but why isn't the switch working? I've read through the 'loose
comparison' section, but nothing appears to apply there.

Sorry for the basic question.

Steve Reilly

--0050450176cc38ba480484206a4c--

Re: Basic switch statement

am 13.04.2010 18:06:06 von Ashley Sheridan

--=-z6h1NMxWvV67aIC8M+l9
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Tue, 2010-04-13 at 12:04 -0400, steve_r wrote:

> I'm new to programming, drive a truck in the day, now taking night courses
> to get a better job for my family. Please bear with me if this is a dumb
> question, I don't have much experience.
>
> I'm taking a night class in HTML and PHP and can't figure out a problem and
> can't find the answer in the book for the course ("Beginning PHP5" by Wrox
> Press), on the switch manual page on php.net, or in any postings to this
> mailing list.
>
> I'm trying to pass a value to a simple integer to a function, and then use
> that value in a switch statement. The problem I'm having is that regardless
> of the value of 'val', the first case statement always executes. Even if I
> put '$val = 0' right before the case statement, the first case statement
> executes. The syntax looks correct based on the php.net man page for switch
> and from the user examples. It also matches the example in the book.
>
> function check_it2($val) {
> echo gettype($val);
> switch($val) {
> case($val > 0 ):
> echo "Switch greater than 0";
> $diff_obj = 1;
> break;
> case($val < 0 ):
> echo "Less than 0";
> $diff_obj = -1;
> break;
> default:
> echo "Equal to 0";
> $diff_obj = 0;
> }
> print("Here's \$diff_obj2 in the function: " . $diff_obj);
> return $diff_obj;
> }
>
> I even put the following code before the switch statement just to make sure
> I'm not crazy:
>
> $val = 0;
> if($val > 0) {
> echo "If greater than 0";
> }
> else {
> echo "If not greater than 0";
> }
>
> and it falls through to the else as it should.
>
> I've tried putting single and double quotes around the case variables but it
> always prints out the first value. I've recoded to use a series of if
> statements but why isn't the switch working? I've read through the 'loose
> comparison' section, but nothing appears to apply there.
>
> Sorry for the basic question.
>
> Steve Reilly


Change the first line of the switch to

switch(true)

and it will be functioning as you want. Normally, a switch has this
form:

switch($val)
{
case 1:
{
// statements
break;
}
case 10:
{
// statements
break;
}
default:
{
// statements
}
}

But PHP does allow you to use variable cases (as you have in your
example) if the value in the switch is a boolean (true or false). It can
be a little confusing if you're new to PHP (or programming in general)
but you'll get used to it after using it a few times.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-z6h1NMxWvV67aIC8M+l9--

Re: Basic switch statement

am 13.04.2010 18:12:24 von Robert Cummings

steve_r wrote:
> I'm new to programming, drive a truck in the day, now taking night courses
> to get a better job for my family. Please bear with me if this is a dumb
> question, I don't have much experience.
>
> I'm taking a night class in HTML and PHP and can't figure out a problem and
> can't find the answer in the book for the course ("Beginning PHP5" by Wrox
> Press), on the switch manual page on php.net, or in any postings to this
> mailing list.
>
> I'm trying to pass a value to a simple integer to a function, and then use
> that value in a switch statement. The problem I'm having is that regardless
> of the value of 'val', the first case statement always executes. Even if I
> put '$val = 0' right before the case statement, the first case statement
> executes. The syntax looks correct based on the php.net man page for switch
> and from the user examples. It also matches the example in the book.
>
> function check_it2($val) {
> echo gettype($val);
> switch($val) {
> case($val > 0 ):
> echo "Switch greater than 0";
> $diff_obj = 1;
> break;
> case($val < 0 ):
> echo "Less than 0";
> $diff_obj = -1;
> break;
> default:
> echo "Equal to 0";
> $diff_obj = 0;
> }
> print("Here's \$diff_obj2 in the function: " . $diff_obj);
> return $diff_obj;
> }

You're a tad confused :)

Q: What is the result of $val > 0?
A: false.

Q: What is the value of $val?
A: 0

Q: Is 0 equivalent to false?
A: Yes!

Use an if statement for this kind of logic.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 13.04.2010 18:15:20 von steve_r

--001636ed6d436f00620484209111
Content-Type: text/plain; charset=ISO-8859-1

Okay, I understand now, true/false is better, now it makes sense why it's
always hitting the case it hits. Thank you Ashley.

--001636ed6d436f00620484209111--

Re: Basic switch statement

am 13.04.2010 19:19:12 von TedD

At 12:04 PM -0400 4/13/10, steve_r wrote:
>I'm new to programming, drive a truck in the day, now taking night courses
>to get a better job for my family. Please bear with me if this is a dumb
>question, I don't have much experience.
>
>-snip-
>
>Sorry for the basic question.
>
>Steve Reilly


Steve:

Please review:

http://php1.net/c/switch/

Note:

1. The value of the switch statement in this case is "true" (it could
also be '1'). This is different than what's found in most other
case/switch control structures in other languages.

2. Generally you should use functions to process and return values
and then decide as to what to do with the results, such as print().
Putting print in functions is fine if the function is supposed to
print something.

3. Try to make your variables and function names simple and
syntactical -- it will help you later when your code becomes more
complex.

Good luck with trying to make a better living programming than driving a truck.

If you want to say thanks for my effort, please answer me this --
with regard to the class you are talking: What is the name of the
class? How many credits is it? What's the name of the textbook you
are using? And, if there is a syllabus, can I have a copy?

Thanks,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 13.04.2010 22:57:19 von Nathan Rixham

Robert Cummings wrote:
> steve_r wrote:
>> I'm new to programming, drive a truck in the day, now taking night
>> courses
>> to get a better job for my family. Please bear with me if this is a dumb
>> question, I don't have much experience.
>>
>> I'm taking a night class in HTML and PHP and can't figure out a
>> problem and
>> can't find the answer in the book for the course ("Beginning PHP5" by
>> Wrox
>> Press), on the switch manual page on php.net, or in any postings to this
>> mailing list.
>>
>> I'm trying to pass a value to a simple integer to a function, and then
>> use
>> that value in a switch statement. The problem I'm having is that
>> regardless
>> of the value of 'val', the first case statement always executes. Even
>> if I
>> put '$val = 0' right before the case statement, the first case statement
>> executes. The syntax looks correct based on the php.net man page for
>> switch
>> and from the user examples. It also matches the example in the book.
>>
>> function check_it2($val) {
>> echo gettype($val);
>> switch($val) {
>> case($val > 0 ):
>> echo "Switch greater than 0";
>> $diff_obj = 1;
>> break;
>> case($val < 0 ):
>> echo "Less than 0";
>> $diff_obj = -1;
>> break;
>> default:
>> echo "Equal to 0";
>> $diff_obj = 0;
>> }
>> print("Here's \$diff_obj2 in the function: " . $diff_obj);
>> return $diff_obj;
>> }
>
> You're a tad confused :)
>
> Q: What is the result of $val > 0?
> A: false.
>
> Q: What is the value of $val?
> A: 0
>
> Q: Is 0 equivalent to false?
> A: Yes!
>
> Use an if statement for this kind of logic.

This is a fantastic example of false logic and an easy pitfall.

in fact this would make a great interview question!

to expand a little on the various scenarios (just for clarity, Rob is right)

$val = 1;
1 > 0 equates to TRUE
is 1 equivalent to TRUE : YES

$val = 0;
0 > 0 equates to FALSE
is 0 equivalent to FALSE : YES

$val = -1;
-1 > 0 equates to FALSE
is -1 equivalent to FALSE: YES

so no matter what value you set $val to; it's always true.

lovely

Regards!


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 13.04.2010 23:02:03 von Robert Cummings

Nathan Rixham wrote:
> Robert Cummings wrote:
>> steve_r wrote:
>>> I'm new to programming, drive a truck in the day, now taking night
>>> courses
>>> to get a better job for my family. Please bear with me if this is a dumb
>>> question, I don't have much experience.
>>>
>>> I'm taking a night class in HTML and PHP and can't figure out a
>>> problem and
>>> can't find the answer in the book for the course ("Beginning PHP5" by
>>> Wrox
>>> Press), on the switch manual page on php.net, or in any postings to this
>>> mailing list.
>>>
>>> I'm trying to pass a value to a simple integer to a function, and then
>>> use
>>> that value in a switch statement. The problem I'm having is that
>>> regardless
>>> of the value of 'val', the first case statement always executes. Even
>>> if I
>>> put '$val = 0' right before the case statement, the first case statement
>>> executes. The syntax looks correct based on the php.net man page for
>>> switch
>>> and from the user examples. It also matches the example in the book.
>>>
>>> function check_it2($val) {
>>> echo gettype($val);
>>> switch($val) {
>>> case($val > 0 ):
>>> echo "Switch greater than 0";
>>> $diff_obj = 1;
>>> break;
>>> case($val < 0 ):
>>> echo "Less than 0";
>>> $diff_obj = -1;
>>> break;
>>> default:
>>> echo "Equal to 0";
>>> $diff_obj = 0;
>>> }
>>> print("Here's \$diff_obj2 in the function: " . $diff_obj);
>>> return $diff_obj;
>>> }
>> You're a tad confused :)
>>
>> Q: What is the result of $val > 0?
>> A: false.
>>
>> Q: What is the value of $val?
>> A: 0
>>
>> Q: Is 0 equivalent to false?
>> A: Yes!
>>
>> Use an if statement for this kind of logic.
>
> This is a fantastic example of false logic and an easy pitfall.
>
> in fact this would make a great interview question!
>
> to expand a little on the various scenarios (just for clarity, Rob is right)
>
> $val = 1;
> 1 > 0 equates to TRUE
> is 1 equivalent to TRUE : YES
>
> $val = 0;
> 0 > 0 equates to FALSE
> is 0 equivalent to FALSE : YES
>
> $val = -1;
> -1 > 0 equates to FALSE
> is -1 equivalent to FALSE: YES
>
> so no matter what value you set $val to; it's always true.

Fail on that last one. -1 is not equivalent to FALSE :B

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 13.04.2010 23:04:20 von Nathan Rixham

Robert Cummings wrote:
> Nathan Rixham wrote:
>> Robert Cummings wrote:
>>> steve_r wrote:
>>>> I'm new to programming, drive a truck in the day, now taking night
>>>> courses
>>>> to get a better job for my family. Please bear with me if this is a
>>>> dumb
>>>> question, I don't have much experience.
>>>>
>>>> I'm taking a night class in HTML and PHP and can't figure out a
>>>> problem and
>>>> can't find the answer in the book for the course ("Beginning PHP5" by
>>>> Wrox
>>>> Press), on the switch manual page on php.net, or in any postings to
>>>> this
>>>> mailing list.
>>>>
>>>> I'm trying to pass a value to a simple integer to a function, and then
>>>> use
>>>> that value in a switch statement. The problem I'm having is that
>>>> regardless
>>>> of the value of 'val', the first case statement always executes. Even
>>>> if I
>>>> put '$val = 0' right before the case statement, the first case
>>>> statement
>>>> executes. The syntax looks correct based on the php.net man page for
>>>> switch
>>>> and from the user examples. It also matches the example in the book.
>>>>
>>>> function check_it2($val) {
>>>> echo gettype($val);
>>>> switch($val) {
>>>> case($val > 0 ):
>>>> echo "Switch greater than 0";
>>>> $diff_obj = 1;
>>>> break;
>>>> case($val < 0 ):
>>>> echo "Less than 0";
>>>> $diff_obj = -1;
>>>> break;
>>>> default:
>>>> echo "Equal to 0";
>>>> $diff_obj = 0;
>>>> }
>>>> print("Here's \$diff_obj2 in the function: " . $diff_obj);
>>>> return $diff_obj;
>>>> }
>>> You're a tad confused :)
>>>
>>> Q: What is the result of $val > 0?
>>> A: false.
>>>
>>> Q: What is the value of $val?
>>> A: 0
>>>
>>> Q: Is 0 equivalent to false?
>>> A: Yes!
>>>
>>> Use an if statement for this kind of logic.
>>
>> This is a fantastic example of false logic and an easy pitfall.
>>
>> in fact this would make a great interview question!
>>
>> to expand a little on the various scenarios (just for clarity, Rob is
>> right)
>>
>> $val = 1;
>> 1 > 0 equates to TRUE
>> is 1 equivalent to TRUE : YES
>>
>> $val = 0;
>> 0 > 0 equates to FALSE
>> is 0 equivalent to FALSE : YES
>>
>> $val = -1;
>> -1 > 0 equates to FALSE
>> is -1 equivalent to FALSE: YES
>>
>> so no matter what value you set $val to; it's always true.
>
> Fail on that last one. -1 is not equivalent to FALSE :B
>

well that's one job I'm not getting :p

cheers for the picking that one up Rob

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 13.04.2010 23:06:30 von Robert Cummings

Nathan Rixham wrote:
> Robert Cummings wrote:
>> Nathan Rixham wrote:
>>> Robert Cummings wrote:
>>>> steve_r wrote:
>>>>> I'm new to programming, drive a truck in the day, now taking night
>>>>> courses
>>>>> to get a better job for my family. Please bear with me if this is a
>>>>> dumb
>>>>> question, I don't have much experience.
>>>>>
>>>>> I'm taking a night class in HTML and PHP and can't figure out a
>>>>> problem and
>>>>> can't find the answer in the book for the course ("Beginning PHP5" by
>>>>> Wrox
>>>>> Press), on the switch manual page on php.net, or in any postings to
>>>>> this
>>>>> mailing list.
>>>>>
>>>>> I'm trying to pass a value to a simple integer to a function, and then
>>>>> use
>>>>> that value in a switch statement. The problem I'm having is that
>>>>> regardless
>>>>> of the value of 'val', the first case statement always executes. Even
>>>>> if I
>>>>> put '$val = 0' right before the case statement, the first case
>>>>> statement
>>>>> executes. The syntax looks correct based on the php.net man page for
>>>>> switch
>>>>> and from the user examples. It also matches the example in the book.
>>>>>
>>>>> function check_it2($val) {
>>>>> echo gettype($val);
>>>>> switch($val) {
>>>>> case($val > 0 ):
>>>>> echo "Switch greater than 0";
>>>>> $diff_obj = 1;
>>>>> break;
>>>>> case($val < 0 ):
>>>>> echo "Less than 0";
>>>>> $diff_obj = -1;
>>>>> break;
>>>>> default:
>>>>> echo "Equal to 0";
>>>>> $diff_obj = 0;
>>>>> }
>>>>> print("Here's \$diff_obj2 in the function: " . $diff_obj);
>>>>> return $diff_obj;
>>>>> }
>>>> You're a tad confused :)
>>>>
>>>> Q: What is the result of $val > 0?
>>>> A: false.
>>>>
>>>> Q: What is the value of $val?
>>>> A: 0
>>>>
>>>> Q: Is 0 equivalent to false?
>>>> A: Yes!
>>>>
>>>> Use an if statement for this kind of logic.
>>> This is a fantastic example of false logic and an easy pitfall.
>>>
>>> in fact this would make a great interview question!
>>>
>>> to expand a little on the various scenarios (just for clarity, Rob is
>>> right)
>>>
>>> $val = 1;
>>> 1 > 0 equates to TRUE
>>> is 1 equivalent to TRUE : YES
>>>
>>> $val = 0;
>>> 0 > 0 equates to FALSE
>>> is 0 equivalent to FALSE : YES
>>>
>>> $val = -1;
>>> -1 > 0 equates to FALSE
>>> is -1 equivalent to FALSE: YES
>>>
>>> so no matter what value you set $val to; it's always true.
>> Fail on that last one. -1 is not equivalent to FALSE :B
>>
>
> well that's one job I'm not getting :p

Well you DID get 66.7%. I've met "coders" that would stare at the answer
and still not understand :D

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 13.04.2010 23:13:09 von Nathan Rixham

Robert Cummings wrote:
> Nathan Rixham wrote:
>> Robert Cummings wrote:
>>> Nathan Rixham wrote:
>>>> Robert Cummings wrote:
>>>>> steve_r wrote:
>>>>>> I'm new to programming
>>>>>>
>>>>>> function check_it2($val) {
>>>>>> echo gettype($val);
>>>>>> switch($val) {
>>>>>> case($val > 0 ):
>>>>>> echo "Switch greater than 0";
>>>>>>
>>>>> You're a tad confused :)
>>>>>
>>>>> Q: What is the result of $val > 0?
>>>>> A: false.
>>>>>
>>>>> Q: What is the value of $val?
>>>>> A: 0
>>>>>
>>>>> Q: Is 0 equivalent to false?
>>>>> A: Yes!
>>>>>
>>>>> Use an if statement for this kind of logic.
>>>> This is a fantastic example of false logic and an easy pitfall.
>>>>
>>>> in fact this would make a great interview question!
>>>>
>>>> to expand a little on the various scenarios (just for clarity, Rob is
>>>> right)
>>>>
>>>> $val = 1;
>>>> 1 > 0 equates to TRUE
>>>> is 1 equivalent to TRUE : YES
>>>>
>>>> $val = 0;
>>>> 0 > 0 equates to FALSE
>>>> is 0 equivalent to FALSE : YES
>>>>
>>>> $val = -1;
>>>> -1 > 0 equates to FALSE
>>>> is -1 equivalent to FALSE: YES
>>>>
>>>> so no matter what value you set $val to; it's always true.
>>> Fail on that last one. -1 is not equivalent to FALSE :B
>>>
>>
>> well that's one job I'm not getting :p
>
> Well you DID get 66.7%. I've met "coders" that would stare at the answer
> and still not understand :D

the travesty is that I spent most of yesterday on trains brushing up on
/ studying formal logic!



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 13.04.2010 23:17:29 von Robert Cummings

Nathan Rixham wrote:
> Robert Cummings wrote:
>> Nathan Rixham wrote:
>>> Robert Cummings wrote:
>>>> Nathan Rixham wrote:
>>>>> Robert Cummings wrote:
>>>>>> steve_r wrote:
>>>>>>> I'm new to programming
>>>>>>>
>>>>>>> function check_it2($val) {
>>>>>>> echo gettype($val);
>>>>>>> switch($val) {
>>>>>>> case($val > 0 ):
>>>>>>> echo "Switch greater than 0";
>>>>>>>
>>>>>> You're a tad confused :)
>>>>>>
>>>>>> Q: What is the result of $val > 0?
>>>>>> A: false.
>>>>>>
>>>>>> Q: What is the value of $val?
>>>>>> A: 0
>>>>>>
>>>>>> Q: Is 0 equivalent to false?
>>>>>> A: Yes!
>>>>>>
>>>>>> Use an if statement for this kind of logic.
>>>>> This is a fantastic example of false logic and an easy pitfall.
>>>>>
>>>>> in fact this would make a great interview question!
>>>>>
>>>>> to expand a little on the various scenarios (just for clarity, Rob is
>>>>> right)
>>>>>
>>>>> $val = 1;
>>>>> 1 > 0 equates to TRUE
>>>>> is 1 equivalent to TRUE : YES
>>>>>
>>>>> $val = 0;
>>>>> 0 > 0 equates to FALSE
>>>>> is 0 equivalent to FALSE : YES
>>>>>
>>>>> $val = -1;
>>>>> -1 > 0 equates to FALSE
>>>>> is -1 equivalent to FALSE: YES
>>>>>
>>>>> so no matter what value you set $val to; it's always true.
>>>> Fail on that last one. -1 is not equivalent to FALSE :B
>>>>
>>> well that's one job I'm not getting :p
>> Well you DID get 66.7%. I've met "coders" that would stare at the answer
>> and still not understand :D
>
> the travesty is that I spent most of yesterday on trains brushing up on
> / studying formal logic!

Muphry's Law!!!

http://en.wikipedia.org/wiki/Muphry's_law

*heheh*

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 13.04.2010 23:28:59 von Nathan Rixham

Robert Cummings wrote:
> Nathan Rixham wrote:
>> Robert Cummings wrote:
>>> Nathan Rixham wrote:
>>>> Robert Cummings wrote:
>>>>> Nathan Rixham wrote:
>>>>>> Robert Cummings wrote:
>>>>>>> steve_r wrote:
>>>>>>>> I'm new to programming
>>>>>>>>
>>>>>>>> function check_it2($val) {
>>>>>>>> echo gettype($val);
>>>>>>>> switch($val) {
>>>>>>>> case($val > 0 ):
>>>>>>>> echo "Switch greater than 0";
>>>>>>>>
>>>>>>> You're a tad confused :)
>>>>>>>
>>>>>>> Q: What is the result of $val > 0?
>>>>>>> A: false.
>>>>>>>
>>>>>>> Q: What is the value of $val?
>>>>>>> A: -1
>>>>>>>
>>>>>>> Q: Is -1 equivalent to false?
>>>>>>> A: Yes!
>>>>>>>
>>>>>>> Use an if statement for this kind of logic.
>>>>>> This is a fantastic example of false logic and an easy pitfall.
>>>>>>
>>>>>> in fact this would make a great interview question!
>>>>>>
>>>>>> to expand a little on the various scenarios (just for clarity, Rob is
>>>>>> wrong)
>>>>>>
>>>>>> $val = 1;
>>>>>> 1 > 0 equates to TRUE
>>>>>> is 1 equivalent to TRUE : YES
>>>>>>
>>>>>> $val = 0;
>>>>>> 0 > 0 equates to FALSE
>>>>>> is 0 equivalent to FALSE : YES
>>>>>>
>>>>>> $val = -1;
>>>>>> -1 > 0 equates to FALSE
>>>>>> is -1 equivalent to FALSE: NO
>>>>>>
>>>>> Fail on that last one. -1 is equivalent to FALSE :B
>>>>>
>>>> well that's one job you're not getting :p
>>> Well I DID get 66.7%. I've met "coders" that would stare at the answer
>>> and still not understand :D
>>
>> the travesty is that you didn't spend most of yesterday on trains brushing
>> up on / studying formal logic!
>
> Muphry's Law!!!
>
> http://en.wikipedia.org/wiki/Muphry's_law
>
> *heheh*

in situations like this one might consider changing the conversation
previous!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 14.04.2010 18:08:06 von TedD

At 10:04 PM +0100 4/13/10, Nathan Rixham wrote:
>Robert Cummings wrote:
> > Nathan Rixham wrote:
>
> > Fail on that last one. -1 is not equivalent to FALSE :B
>
>well that's one job I'm not getting :p
>
>cheers for the picking that one up Rob

And that's the reason why I hate test like that!

The short tricky logic questions that interviewer's use to be clever
are just nonsense.

I'll take someone who can solve a problem over one who can argue
true/false logic tables every time. Not meaning that people who come
natural to that sort of logic solving ability do not make good
programmers (because they can -- like Rob), but rather people who
fail those types of logic questions do NOT also fail to be good
programmers (like me). It's similar to the Tortoise and Hare thing --
it really doesn't make any difference who gets there first for both
can run the distance.

I don't think those types of logic puzzles do much to measure
anything other than people's ability to solve logic puzzles. IMO,
it's interviewers "leap of faith" to think logic puzzles are a good
indicator of programming prowess. To many of us, programming is just
doing over until it works.

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 14.04.2010 18:28:13 von TedD

At 5:06 PM -0400 4/13/10, Robert Cummings wrote:
>Nathan Rixham wrote:
>>
>>well that's one job I'm not getting :p
>
>Well you DID get 66.7%. I've met "coders" that would stare at the
>answer and still not understand :D
>
>Cheers,
>Rob.

Well.. count me among those staring. I just don't get those type of
things until I see them actually work.

My "logic" works the other way -- when presented with a logic
problem, I come up with a solution that works the way I think and I
always to solve the problem presented. Perhaps my solution isn't as
clever nor as cryptic as others, but it's always easier to read and
understand.

Cheers,

tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 14.04.2010 18:32:22 von Robert Cummings

tedd wrote:
> At 5:06 PM -0400 4/13/10, Robert Cummings wrote:
>> Nathan Rixham wrote:
>>> well that's one job I'm not getting :p
>> Well you DID get 66.7%. I've met "coders" that would stare at the
>> answer and still not understand :D
>>
>> Cheers,
>> Rob.
>
> Well.. count me among those staring. I just don't get those type of
> things until I see them actually work.
>
> My "logic" works the other way -- when presented with a logic
> problem, I come up with a solution that works the way I think and I
> always to solve the problem presented. Perhaps my solution isn't as
> clever nor as cryptic as others, but it's always easier to read and
> understand.

Maybe you haven't debugged enough "other people" code in your time as a
developer... there's a certain knack to weeding out logic failures :)

It also helps to use proper indentation and bracing format as
illustrated by all my code examples so that you can more easily see
where problems lie >:D

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 14.04.2010 18:45:28 von TedD

At 12:32 PM -0400 4/14/10, Robert Cummings wrote:
>tedd wrote:
>>My "logic" works the other way -- when presented with a logic
>>problem, I come up with a solution that works the way I think and I
>>always to solve the problem presented. Perhaps my solution isn't as
>>clever nor as cryptic as others, but it's always easier to read and
>>understand.
>
>Maybe you haven't debugged enough "other people" code in your time
>as a developer... there's a certain knack to weeding out logic
>failures :)

That could very well be. I don't usually debug other people's code
and seldom have clients want me to do so. I usually have clients who
present a problem and then I solve it -- thus, all original code.

Several yeas ago, I had one client who had considerable prior work
done and I found myself rewriting everything at a cost of many weeks
of my non-billable time. I won't be doing that again.

>It also helps to use proper indentation and bracing format as
>illustrated by all my code examples so that you can more easily see
>where problems lie >:D
>
>Cheers,
>Rob.

Ain't that the truth!

We are almost identical in our formatting.

I've found that when I run into someone who has similar ideas as I
have, they are usually very intelligent. :-)

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 14.04.2010 22:13:24 von Al

On 4/14/2010 12:28 PM, tedd wrote:
> At 5:06 PM -0400 4/13/10, Robert Cummings wrote:
>> Nathan Rixham wrote:
>>>
>>> well that's one job I'm not getting :p
>>
>> Well you DID get 66.7%. I've met "coders" that would stare at the
>> answer and still not understand :D
>>
>> Cheers,
>> Rob.
>
> Well.. count me among those staring. I just don't get those type of
> things until I see them actually work.
>
> My "logic" works the other way -- when presented with a logic problem, I
> come up with a solution that works the way I think and I always to solve
> the problem presented. Perhaps my solution isn't as clever nor as
> cryptic as others, but it's always easier to read and understand.
>
> Cheers,
>
> tedd

I'm with you Tedd. I'm forever cussing myself when I use a super clever trick to
solve a logic problem and then later can't figure out how the damn thing worked
even though I documented it.

Incidentally, about formatting scripts, one of the reasons I like phpEdit is
that it has a terrific code beautifier. You can set it for phpDoc or Pear
rendering. And, it auto indents, etc. as you enter stuff.

Al...........

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 14.04.2010 22:52:24 von Paul M Foster

On Wed, Apr 14, 2010 at 12:28:13PM -0400, tedd wrote:

> At 5:06 PM -0400 4/13/10, Robert Cummings wrote:
>> Nathan Rixham wrote:
>>>
>>> well that's one job I'm not getting :p
>>
>> Well you DID get 66.7%. I've met "coders" that would stare at the
>> answer and still not understand :D
>>
>> Cheers,
>> Rob.
>
> Well.. count me among those staring. I just don't get those type of
> things until I see them actually work.
>
> My "logic" works the other way -- when presented with a logic
> problem, I come up with a solution that works the way I think and I
> always to solve the problem presented. Perhaps my solution isn't as
> clever nor as cryptic as others, but it's always easier to read and
> understand.

+1

I've never had other coders looking over my shoulder, and I agonized for
years over whether my logical solutions were the "best" approach. Now I
just code and take pride in the fact that I can understand what I did
later (mostly).

Paul

--
Paul M. Foster

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 14.04.2010 23:06:39 von Ashley Sheridan

--=-cJxk3mmcNFFVy5+yt5Zt
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Wed, 2010-04-14 at 16:52 -0400, Paul M Foster wrote:

> On Wed, Apr 14, 2010 at 12:28:13PM -0400, tedd wrote:
>
> > At 5:06 PM -0400 4/13/10, Robert Cummings wrote:
> >> Nathan Rixham wrote:
> >>>
> >>> well that's one job I'm not getting :p
> >>
> >> Well you DID get 66.7%. I've met "coders" that would stare at the
> >> answer and still not understand :D
> >>
> >> Cheers,
> >> Rob.
> >
> > Well.. count me among those staring. I just don't get those type of
> > things until I see them actually work.
> >
> > My "logic" works the other way -- when presented with a logic
> > problem, I come up with a solution that works the way I think and I
> > always to solve the problem presented. Perhaps my solution isn't as
> > clever nor as cryptic as others, but it's always easier to read and
> > understand.
>
> +1
>
> I've never had other coders looking over my shoulder, and I agonized for
> years over whether my logical solutions were the "best" approach. Now I
> just code and take pride in the fact that I can understand what I did
> later (mostly).
>
> Paul
>
> --
> Paul M. Foster
>


I think as long as the code is readable, and doesn't have any glaringly
obvious issues (I've seen people re-writing built in PHP functionality
because they didn't know the built-in function existed) then it should
be OK. Add comments to aid any areas where you think you might forget or
other people might not easily understand what is happening.

Don't get me wrong, clever ideas are nice, and sometimes with the right
comment they just work beautifully. Just occassionally though something
is done in such a neat clever way, that in the future when it comes time
to extend the system, this neat clever idea is actually a hindrance and
causes extra work because it has to be re-written a 'less-clever' but
more flexible way!

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-cJxk3mmcNFFVy5+yt5Zt--

Re: Basic switch statement

am 15.04.2010 04:33:20 von Paul M Foster

On Wed, Apr 14, 2010 at 10:06:39PM +0100, Ashley Sheridan wrote:

> On Wed, 2010-04-14 at 16:52 -0400, Paul M Foster wrote:



>
>
> I've never had other coders looking over my shoulder, and I agonized for
> years over whether my logical solutions were the "best"
> approach. Now I
> just code and take pride in the fact that I can understand what I did
> later (mostly).
>
> Paul
>
> --
> Paul M. Foster
>
>
>
> I think as long as the code is readable, and doesn't have any glaringly obvious
> issues (I've seen people re-writing built in PHP functionality because they
> didn't know the built-in function existed) then it should be OK. Add comments
> to aid any areas where you think you might forget or other people might not
> easily understand what is happening.
>
> Don't get me wrong, clever ideas are nice, and sometimes with the right comment
> they just work beautifully. Just occassionally though something is done in such
> a neat clever way, that in the future when it comes time to extend the system,
> this neat clever idea is actually a hindrance and causes extra work because it
> has to be re-written a 'less-clever' but more flexible way!

That reminds me of a story. I once wrote what was almost an RPG (RPG--
the language, not the game) interpeter under FoxPro to handle incoming
EDI traffic and update invoicing, etc. The big problem with EDI is that
no one follows the standards properly, so every vendor tendering an
invoice did it differently. So you needed a database driven system which
would selectively make decisions based on each line of incoming EDI
content. Worked great, and when a new vendor came along, you just
analyzed their transactions and populated some more records in the
database to handle that vendor's transactions. I know, it sounds
obscure, but it made perfect sense at the time.

Shortly after that, I left that company. I documented the system, and it
worked fine, but it was hard to wrap your wits around how it worked. And
I just know the next coder on that account was cursing me day and night
for writing that system.

Anyway...

Paul

--
Paul M. Foster

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 15.04.2010 14:55:14 von TedD

At 4:13 PM -0400 4/14/10, Al wrote:
>Incidentally, about formatting scripts, one of the reasons I like
>phpEdit is that it has a terrific code beautifier. You can set it
>for phpDoc or Pear rendering. And, it auto indents, etc. as you
>enter stuff.
>
>Al...........

Unfortunately, there is no phpEdit version for the Mac.

Currently, I use GoLive (without all the WYSIWYG bloatware), but it
limitations are showing. I like Eclipse, but the learning curve is
high and has more features than I need.

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 15.04.2010 15:11:34 von Phpster

On Thu, Apr 15, 2010 at 8:55 AM, tedd wrote:
> At 4:13 PM -0400 4/14/10, Al wrote:
>>
>> Incidentally, about formatting scripts, one of the reasons I like phpEdi=
t
>> is that it has a terrific code beautifier. =A0You can set it for phpDoc =
or
>> Pear rendering. And, it auto indents, etc. as you enter stuff.
>>
>> Al...........
>
> Unfortunately, there is no phpEdit version for the Mac.
>
> Currently, I use GoLive (without all the WYSIWYG bloatware), but it
> limitations are showing. I like Eclipse, but the learning curve is high a=
nd
> has more features than I need.
>
> Cheers,
>
> tedd
>
> --
> -------
> http://sperling.com =A0http://ancientstones.com =A0http://earthstones.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Sorry, should have copied the list

try netbeans http://netbeans.org/kb/articles/mac.html



--=20

Bastien

Cat, the other other white meat

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 15.04.2010 15:24:43 von Ashley Sheridan

--=-gqDMrafVIWFEJggALnnC
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Thu, 2010-04-15 at 08:55 -0400, tedd wrote:

> At 4:13 PM -0400 4/14/10, Al wrote:
> >Incidentally, about formatting scripts, one of the reasons I like
> >phpEdit is that it has a terrific code beautifier. You can set it
> >for phpDoc or Pear rendering. And, it auto indents, etc. as you
> >enter stuff.
> >
> >Al...........
>
> Unfortunately, there is no phpEdit version for the Mac.
>
> Currently, I use GoLive (without all the WYSIWYG bloatware), but it
> limitations are showing. I like Eclipse, but the learning curve is
> high and has more features than I need.
>
> Cheers,
>
> tedd
>
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
>


Have you tried Coder on the Mac? Most developers I know who use Macs
(it's not the oxymoron it sounds! :p ) tend to use Coder. It's pretty
good, and while I've not used it myself, I've seen enough to like it. In
a perfect world my editor would be somewhere between Coder and Kate (the
KDE Advanced Text Editor) with the best bits of both thrown in.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-gqDMrafVIWFEJggALnnC--

Re: Basic switch statement

am 15.04.2010 23:55:00 von Jason Pruim

On Apr 15, 2010, at 8:55 AM, tedd wrote:

> At 4:13 PM -0400 4/14/10, Al wrote:
>> Incidentally, about formatting scripts, one of the reasons I like
>> phpEdit is that it has a terrific code beautifier. You can set it
>> for phpDoc or Pear rendering. And, it auto indents, etc. as you
>> enter stuff.
>>
>> Al...........
>
> Unfortunately, there is no phpEdit version for the Mac.
>
> Currently, I use GoLive (without all the WYSIWYG bloatware), but it
> limitations are showing. I like Eclipse, but the learning curve is
> high and has more features than I need.


Hey tedd

I just recently started using netbeans and it looks like it may fit
the bill... it's simple enough to understand but can be extended if
you want to. It also runs better on my Mac then Eclipse ever did. Just
something that might be worth checking out :)



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 15.04.2010 23:56:12 von Jason Pruim

On Apr 15, 2010, at 9:24 AM, Ashley Sheridan wrote:

> On Thu, 2010-04-15 at 08:55 -0400, tedd wrote:
>>
>
>
> Have you tried Coder on the Mac? Most developers I know who use Macs
> (it's not the oxymoron it sounds! :p )

Most Mac people would say the morons use Windows ;) But that's
another story for another list! :)



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 16.04.2010 01:11:28 von Adam Richardson

--00148531ab674b712804844e9d30
Content-Type: text/plain; charset=ISO-8859-1

On Thu, Apr 15, 2010 at 5:55 PM, Jason Pruim wrote:

>
> On Apr 15, 2010, at 8:55 AM, tedd wrote:
>
> At 4:13 PM -0400 4/14/10, Al wrote:
>>
>>> Incidentally, about formatting scripts, one of the reasons I like phpEdit
>>> is that it has a terrific code beautifier. You can set it for phpDoc or
>>> Pear rendering. And, it auto indents, etc. as you enter stuff.
>>>
>>> Al...........
>>>
>>
>> Unfortunately, there is no phpEdit version for the Mac.
>>
>> Currently, I use GoLive (without all the WYSIWYG bloatware), but it
>> limitations are showing. I like Eclipse, but the learning curve is high and
>> has more features than I need.
>>
>
>
> Hey tedd
>
> I just recently started using netbeans and it looks like it may fit the
> bill... it's simple enough to understand but can be extended if you want to.
> It also runs better on my Mac then Eclipse ever did. Just something that
> might be worth checking out :)
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
+1 Netbeans

--
Nephtali: PHP web framework that functions beautifully
http://nephtaliproject.com

--00148531ab674b712804844e9d30--

Re: Basic switch statement

am 16.04.2010 11:38:19 von ro0ot.w00t

2010/4/16 Adam Richardson :
> On Thu, Apr 15, 2010 at 5:55 PM, Jason Pruim =
wrote:
>
>>
>> On Apr 15, 2010, at 8:55 AM, tedd wrote:
>>
>> =A0At 4:13 PM -0400 4/14/10, Al wrote:
>>>
>>>> Incidentally, about formatting scripts, one of the reasons I like phpE=
dit
>>>> is that it has a terrific code beautifier. =A0You can set it for phpDo=
c or
>>>> Pear rendering. And, it auto indents, etc. as you enter stuff.
>>>>
>>>> Al...........
>>>>
>>>
>>> Unfortunately, there is no phpEdit version for the Mac.
>>>
>>> Currently, I use GoLive (without all the WYSIWYG bloatware), but it
>>> limitations are showing. I like Eclipse, but the learning curve is high=
and
>>> has more features than I need.
>>>
>>
>>
>> Hey tedd
>>
>> I just recently started using netbeans and it looks like it may fit the
>> bill... it's simple enough to understand but can be extended if you want=
to.
>> It also runs better on my Mac then Eclipse ever did. Just something that
>> might be worth checking out :)
>>
>>
>>
> +1 Netbeans
>
+3 Netbeans
Because
+ it's able to manage huge projects and huge files,
+ has the best code completion and
+ I'm not missing any features but one. ;-)

It also runs great on linux. IMHO it beats the Zend IDE, Eclipse as
well as Komodo Edit /ide.

Regards

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 16.04.2010 15:06:10 von Robert Cummings

Jan G.B. wrote:
> 2010/4/16 Adam Richardson :
>> On Thu, Apr 15, 2010 at 5:55 PM, Jason Pruim wrote:
>>
>>> On Apr 15, 2010, at 8:55 AM, tedd wrote:
>>>
>>> At 4:13 PM -0400 4/14/10, Al wrote:
>>>>> Incidentally, about formatting scripts, one of the reasons I like phpEdit
>>>>> is that it has a terrific code beautifier. You can set it for phpDoc or
>>>>> Pear rendering. And, it auto indents, etc. as you enter stuff.
>>>>>
>>>>> Al...........
>>>>>
>>>> Unfortunately, there is no phpEdit version for the Mac.
>>>>
>>>> Currently, I use GoLive (without all the WYSIWYG bloatware), but it
>>>> limitations are showing. I like Eclipse, but the learning curve is high and
>>>> has more features than I need.
>>>>
>>>
>>> Hey tedd
>>>
>>> I just recently started using netbeans and it looks like it may fit the
>>> bill... it's simple enough to understand but can be extended if you want to.
>>> It also runs better on my Mac then Eclipse ever did. Just something that
>>> might be worth checking out :)
>>>
>>>
>>>
>> +1 Netbeans
>>
> +3 Netbeans
> Because
> + it's able to manage huge projects and huge files,
> + has the best code completion and
> + I'm not missing any features but one. ;-)
>
> It also runs great on linux. IMHO it beats the Zend IDE, Eclipse as
> well as Komodo Edit /ide.

+googol Joe

It runs in a terminal!

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 16.04.2010 18:45:24 von TedD

At 9:06 AM -0400 4/16/10, Robert Cummings wrote:
>
>It runs in a terminal!
>
>Cheers,
>Rob.

That's not good. Airport security frowns on that.

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Basic switch statement

am 16.04.2010 18:56:33 von List Manager

tedd wrote:
> At 9:06 AM -0400 4/16/10, Robert Cummings wrote:
>>
>> It runs in a terminal!
>>
>> Cheers,
>> Rob.
>
> That's not good. Airport security frowns on that.
>
> Cheers,
>
> tedd
>

Mac users might get a little upset if Airport security doesn't allow them to use
their terminals to run

--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php