Hi
When looking at this I thought in terms of C and how it would code in
assembly. I also considered how easy and quick it would be to do jmp
instructions. On a slow Z80 it may make a difference on a superfast modern
machine would the difference be noticeable?
Considering this Style B is faster and more efficient. It is a long time
since I have done any assembler in C so please excuse my semi guesswork if I
have got this wrong.
John Eayrs
On Sunday 07 June 2009 20:01:47 Hugo Mills wrote:
> If you were writing a function with a fast path and a slow path,
> which style would you use to write the function?
>
>
> Style A:
>
> if can_use_fast_path:
> return "fast path result"
> # do slow stuff
> return "slow path result"
>
>
> Style B:
>
> result = "fast path result"
> if !can_use_fast_path:
> # do slow stuff
> result = "slow path result"
> return result
>
>
> Assume that the fast path is a single expression, and the slow path
> is at least tens of lines of code. Why would you pick one style over
> the other? Would you use a different idiom in different languages? If
> so, why?
>
> Discuss. :)
>
> Hugo.