View Single Post
Old 11-28-2010, 07:47 PM   #29
Flint
Snowflake
 
Join Date: Mar 2006
Location: Dystopia
Posts: 13,136
Quote:
Originally Posted by Perry Winkle View Post
Your solution depends on side effects.
This is, of course, semantics, but no, it doesn't.

I had a solution to design: how to test for two conditions.

I figured, while either one is false, correct that one.

Quote:
while !(a) or !(b)
{
if !(a)
call (a)

if !(b)
call (b)
}

What could be simpler, or easier to understand?

Let's say I am leaving the house. Did I lock the door (a)? Did I turn off the lights (b)? While either one is false: if (a) is false I lock the door, if (b) is false I turn off the lights. When neither one is false I am done. This is common sense.

I understand that if I were doing this in the "real world" things would be more involved and this might cease to be feasible for a variety of reasons that I have yet to consider, but in essence, this is my conception of how loops work and what they are supposed to (are DESIGNED to) do.

What I don't understand is why you guys find what I did confusing. I used regular, human logic.

Quote:
In the real world, you want functions to have as few side-effects as possible. Ideally, a function would have no side-effect other than its return value. Some languages even ENFORCE this restriction.
What are the undesirable "side effects" of my functions??? My functions didn't do anything but return a value until I moved some parts of main function into them so you guys could understand the elegant simplicity of my while/if/if loop.

I could put it back this way:

Code:
while ((!passLength(password)) || (!containDigit(password))) 
{
if (!passLength(password))
{
cout << "Passwords must be at least 6 characters long" << endl;
cout << "Please enter a password1: ";
cin.getline(password, SIZE);
(passLength(password)); //(a)
}

if (!containDigit(password))
{
cout << "Passwords must include at least on digit (1-9)" << endl;
cout << "Please enter a password2: ";
cin.getline(password, SIZE);
(containDigit(password)); //(b)
} 
}
Does that help you to understand that I designed it this way on purpose? This is not accidental, there are no "side effects" ...
__________________
******************
There's a level of facility that everyone needs to accomplish, and from there
it's a matter of deciding for yourself how important ultra-facility is to your
expression. ... I found, like Joseph Campbell said, if you just follow whatever
gives you a little joy or excitement or awe, then you're on the right track.

. . . . . . . . . . . . . . . . . . . . . . . . . . Terry Bozzio

Last edited by Flint; 11-28-2010 at 08:03 PM.
Flint is offline   Reply With Quote