3 ms·
I have a large Elixir project with less than 10 branches (if then else) and they were written by other developers. Conditional logic is done either in pattern m
by pmontra 7y ago
I have a large Elixir project with less than 10 branches (if then else) and they were written by other developers. Conditional logic is done either in pattern matching in function definitions (and some guard) or case/cond or with/else.
I guess case/cond can be implemented with the return mechanism of Chaos. Maybe it's going to feel weird, maybe not.
There is no pattern matching and I got the feeling that's going to complicate things but again, it can be emulated to some degree but the return mechanism. Instead of
def a(0), do: "a"
def a(1), do: "b"
def a(_n), do: "c"
Probably we'll be writing
str def a(n)
num x = n
end {
x == 0 : "a"
x == 1 : "b"
default: "c"
}
Having to define that x variable feels like a waste of code and reasoning on x instead of n (the argument of the function) is a pity. Maybe the function body can be empty. I didn't install the language.
I wonder how that scales on real world cases, for example matching the internals of some complex data structure.
- curryst 7y agoPattern matching is still branching. An elegant way of expressing it, but it is branching none the less.
- imtringued 7y agoI am now wondering what the benefit of Chaos' approach is. Chaos is making some pretty substantial tradeoffs. Going with conventional pattern matching (as part of the declaration) isn't such a big leap.