If-Expressions vs Statements

The cluster debates the use of traditional if-else statements versus conditional expressions like ternary operators, cond, and unless, focusing on syntax, readability, and language features that treat if as an expression.

πŸ“‰ Falling 0.4x Programming Languages
6,421
Comments
20
Years Active
5
Top Authors
#4398
Topic ID

Activity Over Time

2007
12
2008
63
2009
102
2010
178
2011
203
2012
259
2013
349
2014
262
2015
248
2016
377
2017
400
2018
469
2019
559
2020
446
2021
532
2022
608
2023
546
2024
377
2025
415
2026
16

Keywords

IF L1 gss.js L11963 ifunless.html wikipedia.org I.e apache.org github.com COND conditional expression operator ant expressions statements statement erlang code languages

Sample Comments

saagarjha β€’ Apr 26, 2025 β€’ View on HN

Surely you are not putting code behind an if/else

keymone β€’ Nov 11, 2016 β€’ View on HN

why are you so certain? is it maybe because you've programmed your whole life using ifs and they look more natural to you?

__sb__ β€’ Jan 27, 2013 β€’ View on HN

Are inline if statements considered good form? I rarely see them in use and I've heard people complain about them before.

igl β€’ Sep 19, 2017 β€’ View on HN

Everything is an expression. Including if statements. There is no need of such syntax abominations.

tptacek β€’ Jan 3, 2011 β€’ View on HN

It's an if statement written differently.

croo β€’ Feb 27, 2025 β€’ View on HN

Nice! Feature request : conditional expressions should start with the "else" branch.

jpz β€’ Nov 26, 2020 β€’ View on HN

It simplifies the expression of if/then/elsif/elsif/else, even if it's not total.Why not steal it?

Skunkleton β€’ Jul 2, 2019 β€’ View on HN

Aren’t features like if-expressions just that?

aib β€’ Jul 6, 2018 β€’ View on HN

The reason it's not the same as if...else is that it's freaking backwards :D

marshray β€’ Jan 2, 2012 β€’ View on HN

There is an 'if' expression, it's just spelled '?' and else is ':'. Mentioned a few posts up.