logoalt Hacker News

lpribis • yesterday at 3:11 PM • 1 reply • view on HN

> returning 2 values

> act on context structures

Same semantics but mutating context is much harder to track, so yes it is preferred to return 2 values.


Replies

Kevin_Flynn • yesterday at 5:03 PM

So, returning 2 values is more performant than returning 1.

How does this affect branch prediction ?

When code is structued:

  ...

  result = function1(arg1,arg2,etc);
  if ( !result ) handle_error(result);

  result = function2(arg1,arg2,etc);
  if ( !result ) handle_error(result);

  ...
branch prediction performs well.

I guess if you're checking and branching on 2 values, it performs twice as well ?

➕ show 1 reply