3 ms·
This trick can only save people who remember to use it. Warnings emitted by tooling save everyone. Also it's slightly awkward to read, as mentioned by others a
by paol 10y ago
This trick can only save people who remember to use it. Warnings emitted by tooling save everyone.
Also it's slightly awkward to read, as mentioned by others already.
- busterarm 10y agoThe trick saves the person writing the code and anyone modifying it down the road. You can't force everyone who edits your code to have linters and warnings turned on. Not everyone follows bests practices.
- michaelmior 10y agoDoes it? You also can't force everyone who edits your code to follow your conventions.
- digler999 10y agoactually you can, depending on the management structure in an organization :)
- yellowapple 10y agoWarnings can only save people who bother to read them. Yoda conditionals save everyone trying to run or compile the code in question. It goes both ways ;) Re: awkwardness, it doesn't feel awkward at all to me; given that Erlang and Elixir use assignment for destructuring and pattern-matching, Yoda conditionals feel very natural to me in comparison. For example, this is valid Elixir code: foo = {1, 2} bar = if {baz, 2} = foo do 525600 end IO.inspect foo # prints {1,2} IO.inspect bar # prints 525600 IO.inspect baz # prints 1