I hate to triple-post, but removing ternary seems similar to the 'removing
c-style for loops' proposal that was recently accepted:
To quote:
The C-style for-loop appears to be a mechanical carry-over from C rather
than a genuinely Swift-specific construct. It is rarely used and not very
Swift-like.
You could say the same thing about ternary. Rarely used; not very
Swift-like, conflicting with the use of ? for optionals; seems to be
disliked (rationally or irrationally) by many; and in almost all cases you
can achieve the same exact thing, but ostensibly more readable, with a few
extra lines.
Ā·Ā·Ā·
On Tue, Dec 15, 2015 at 11:18 AM Dennis Lysenko via swift-evolution < swift-evolution@swift.org> wrote:
Also, +1 to removing ?: ternary in general. It does not match the
atmosphere of Swift. Where you can write:self.x = a ? b : c
self.y = a ? d : e
self.z = a ? f : gYou could just write
if a {
self.x = b
self.y = d
self.z = f
} else {
self.x = c
self.y = e
self.z = g
}Now it's easier to scan for what changes when a is true. With
if-expressions, this would scale even better to multiple
conditions/declarations.On Tue, Dec 15, 2015 at 11:14 AM Dennis Lysenko < > dennis.s.lysenko@gmail.com> wrote:
Can we just have if-expressions and Xcode indent if-statements the way
that Ruby style guides suggest?let x = if y < 0 {
z * z - 4
} else {
8
}Works fantastically well in Ruby, for me. Looks a bit strange to the
untrained eye but that went away for me pretty much the first time I wrote
one of these. It's:- More readable than ternary
- Not shoehorning complex logic onto one line
- All indented to the same indentation levelAnd we don't have the 80-char line delimiter or length limit in Swift,
with Xcode also using a slightly smaller font size than most other IDEs, so
indentation should not be that much of an issue. Admittedly, ruby style
dictates two-space indentation which makes this type of code slightly
shallower.On Tue, Dec 15, 2015 at 5:34 AM Al Skipp via swift-evolution < >> swift-evolution@swift.org> wrote:
On 15 Dec 2015, at 06:41, Paul Ossenbruggen via swift-evolution < >>> swift-evolution@swift.org> wrote:
Agreed, I was thinking to I really want turn something that was 2
characters into 10 and will I really be happy with that at the end of the
day. A properly formatted ternary can be quite easy to read, it is when
people get sloppy and try to cram too much into one expression that they
get really hard to follow. For example,return (a<b) ? (b<c) ? b : (a<c) ? c : a : (a<c) ? a : (b<c) ? c : b;
If formatted like this becomes easier follow the logic (at least to me):
return a < b
? b < c
? b
: a < c
? c
: a
: a < c
? a
: b < c
? c
: bIām happy to make use of the ternary operator, but never in a nested
fashion. It looks neat and succinct on first glance, but is quite
impenetrable to read. I donāt think thereās a way to make such nested
expressions easily comprehensible. Nested āif/else/thenā expressions will
be equally bewildering.On a purely stylistic level I think simple, āif/then/elseā expressions,
would have a more Swift vibe to them than the ternary operator. Well, that
would be the case if it didnāt introduce the confusion between expressions
and statements.I do still however like the Switch Expressions.
I agree. The Switch expression proposal is worth pursuing, itās
something Iād really like to see in the language. One concern I have is
that it faces the same dilemma of the āifā expression proposal, that is,
how to make the distinction between a statement and an expression
unambiguous?Hereās a suggestion, it might be terrible (Iāve not had my third cup of
tea of the morning yet), but how about a different keyword? I know, I feel
guilty for the suggestion already, but here it is:switch == statement
match == expressionThe syntax you (@Paul) have already suggested for the feature wouldnāt
change, but instead of āswitchā, itād use the āmatchā keyword for the
expression form. Good, bad, terrible? What do people think?Al
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution