I'm getting more and more the feeling that when I design my programing language it will have 3 spaces for indentation.
And there will be no ifs-expressions, only match-expressions.

@vascorsd

To be honest I was thinking about 4 mandatory spaces (no tab, no different amount of spaces, possibly no more than one way to express a computation).

But I'm also thinking of no `if` only match/switch.

@Shamar If I make something, for sure I'd go with the spaces mandatory with given size at the language level and no tabs too.

In a language with patterns and matching an "if" is useless since a "case" always is more powerful and subsumes it. So having an "if" is really not needed at all.

@vascorsd

to be fair I can think of cases where sequences of `if/else if` cannot be easily subsumed by a `match/case` statement, not even if you evaluate the case selection expressions (as PHP did, as far as I can remember).

I mean something like

switch(true){
case isMonday(): print "Monday ";
case isSunday(): print "Sunday";
case isJune(): print "June ";
default: print "hi! ";
}

would print "Monday June ", but would not (easily) subsume "if/elif" (as far as I can think right now).

@Shamar I'm not sure I follow, each case must be exclusive, there's no continuing matching on multiple cases after matching on one.

Multiple conditions can easily be done like:

match (isMonday, isJune):
| (true, true) => "monday in june"
| _ => "other days don't care"

@vascorsd

They are mutually exclusive in C (and most other languages, afaik) but I've seen at least one language using:

1) non-constants as case expression
2) non-exclusive branches

A recent example is React's Router dom's Switch (but I've seen this before)

I don't like this approach but I was looking for an `if/elif` idiomatic alternative in an if-less language.

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.