1. T(r)ip of the day?

Last night, whilst churning out lines of our lovely Eu, I needed to have
a section of code which set a variable iPos to 1 if a variable iTotal
was 1 and iPos to 2 otherwise. My first attempt was:

  if iTotal = 1 then
     iPos = 1
  else
     iPos = 2
  end if

At closer inspection I managed to reduce this two one line of code,
which is a hell of a lot more succinct and well faster. Comparing the
number of assignments, lines and comparisons we can see that it is
superior.

  iPos = (iTotal > 1) + 1

Well, I don't know if that will be of use, but it was for me. How about
starting a little thread of tips like this? Especially when the Eu
newsgroup gets going.

Later,
Matt Sephton
--
u5ms at csc.liv.ac.uk
http://www.csc.liv.ac.uk/~u5ms/

new topic     » topic index » view message » categorize

2. Re: T(r)ip of the day?

Matt, nice work... and a very creative solution. I seek throug my code
to improve such constructions after seeing this.

MK

> At closer inspection I managed to reduce this two one line of code,
> which is a hell of a lot more succinct and well faster. Comparing the
> number of assignments, lines and comparisons we can see that it is
> superior.
>
>   iPos = (iTotal > 1) + 1

new topic     » goto parent     » topic index » view message » categorize

3. Re: T(r)ip of the day?

> At closer inspection I managed to reduce this two one line of code,
> which is a hell of a lot more succinct and well faster. Comparing the
> number of assignments, lines and comparisons we can see that it is
> superior.

But less readable!

Adriaan H Rienks I.
>
>   iPos = (iTotal > 1) + 1

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu