----- Original Message -----
From: "Sacha V. Chua" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, December 03, 2001 10:30 AM
Subject: Re: [plug] Interesting small Math problem
> On Thu, Nov 29, 2001 at 11:57:46AM +0800, fooler wrote:
>
> > injecting parenthesis on a given expression is the most complex and
> > challenging part here. it is depends on what parenthesis insertion rules
you
>
> <points out yet again that using postfix notation makes all questions of
> parenthesizing moot>
>
> I have no idea why people still think in infix for this kind of problem!
> ;)
whether you use postfix or infix is still the same. yes there is a finite
rule here.. it just knowing the associative , distributative, etc properties
of a given expression... but hey, this problem can be easily solve if we
spend time on this but take note , this problem cannot apply in our daily
lives.. in short its a useless problem!... this problem is just an ego
boosting. it is more on the mathematical side than the programming side.. id
rather spent my time on the problem that will help our lives better.
what is clean and elegant code if you got the wrong results? yes all
programmer wish to have a clean and elagant code. but take note, not all
clean and elegant code is a good program! for example, writing a factorial
program. you have two options here, recursive and iterative.
recursive:
double factorial(double n) {
if (n < 2) {
return (1);
} else {
return (n * factorial(n -1));
}
}
iterative:
double factorial;
if (n < 2) {
factorial = 1;
}else {
for (factorial = n ; n != 2; factorial = factorial * --n);
}
now which of them is clean and elegant code? it looks like the recursive is
clean and elegant but what about speed? the iterative is more faster than
the recursive because of the expensive call due to recursive which takes
more clock ticks than the iteratative one. you see what i mean?
now if you have a formula which takes faster to solve, then thats fine if
and only if the result is correct. but if not, then you have to back off and
do the most basic thing to do which is using the brute force algorithm
first... until you got the correct answer then thats the time to polish,
find that formula and improve your algorithm.
there are three basic rules that im always followed
1. functionality
2. speed
3. size
1. functionality - whether its clean or robust as long the result is correct
and you meet your deadline. this is usually a common pitfall of a
programmer, they are spending more time on *bones* than the *meat*. or let
say, who is a good programmer? the one who makes a robust program but gives
the correct results and meet his/her deadline or the one who makes an
elegant code that gives the correct results also but it takes time to
finish?
2. speed - of course its not only on the functionality but also the speed...
yes if you derived a clean and elegant code but suffer the speed, its
useless!!. one good example is the above example.
3. size - you got the functionality and speed but if you got a bloated
program, its still useless! bloated program is only good if your OS is a
single user and single task OS because it is run one at a time. but running
multiple instances of your bloated program makes the difference.
so therefore i dont care whethere you use postfix or whatever as long ive
met those three rules.
fooler.
_
Philippine Linux Users Group. Web site and archives at http://plug.linux.org.ph
To leave: send "unsubscribe" in the body to [EMAIL PROTECTED]
To subscribe to the Linux Newbies' List: send "subscribe" in the body to
[EMAIL PROTECTED]