Skip to content

Comment on Ask HN: Why Are Conditionals Important?

Comments

There are styles of programming with no conditionals, especially in purely functional languages.

A common technique inside compilers is to separate out which code gets run, and which result gets used. If everything is side-effect-free, then there's no harm in running the code whose result won't get used. In highly parallel systems, you can just run both versions and select at the end. So you can rewrite:

  if foo < 2:
    a = foo
  else
    a = 2
to:
  a = phi(foo<2, 2, foo)
(the phi operator is taken from SSA notation. See https://llvm.org/docs/LangRef.html#phi-instruction if you're unfamiliar)

I don't need to understand that code to tell you there is a control flow mechanism somewhere using a condition.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.