Ternary Operator Poll
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
9 posts
• Page 1 of 1
Ternary Operator Poll
by Rob Cashwalker » 12 Sep 2011, 14:55
Ternary Operator:
Pros:
Single line of code for basic functionality for example:
Confusing to new programmers
Simpler to modify if-else block in future
Discuss and Vote!
- Code: Select all
condition ? operation if true : operation if false;
Pros:
Single line of code for basic functionality for example:
Cons:Sometimes I've needed a final variable, but I need it assigned based on a condition. A ternary operator is much simpler than an if-else with a temp variable.
Confusing to new programmers
Simpler to modify if-else block in future
Discuss and Vote!
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: Ternary Operator Poll
by slapshot5 » 12 Sep 2011, 23:34
I voted allow because of this:
Sometimes I've needed a final variable, but I need it assigned based on a condition. A ternary operator is much simpler than an if-else with a temp variable.
It's just cleaner. Outside of this, I've never had use for them.
-slapshot5
Sometimes I've needed a final variable, but I need it assigned based on a condition. A ternary operator is much simpler than an if-else with a temp variable.
It's just cleaner. Outside of this, I've never had use for them.
-slapshot5
- slapshot5
- Programmer
- Posts: 1391
- Joined: 03 Jan 2010, 17:47
- Location: Mac OS X
- Has thanked: 25 times
- Been thanked: 68 times
Re: Ternary Operator Poll
by Hellfish » 12 Sep 2011, 23:43
I voted allow. I do agree with Con #1 but IMO it is not *that* complicated to learn to use, once you stumble upon it. As for Con #2, it's a couple of seconds worth of cut & pasting at most to convert it if need be, it doesn't bother me.
So now you're
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
-
Hellfish - Programmer
- Posts: 1297
- Joined: 07 Jun 2009, 10:41
- Location: South of the Pumphouse
- Has thanked: 110 times
- Been thanked: 169 times
Re: Ternary Operator Poll
by friarsol » 13 Sep 2011, 01:03
I voted allow as well. I think Con # 1 isn't a valid concern. New programmers don't know a lot of stuff, but that shouldn't be a reason to limit how others program. When I was a new programmer I loved stumbling on new ways to make my code more concise.
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: Ternary Operator Poll
by Max mtg » 13 Sep 2011, 02:20
I voted allow, because... it was my idea originally to review checkstyle limitations.
Con #1: new progs would learn it on sight
#2: don't be lazy. If the condition clause seems to be too long, declare a boolean for it.
Con #1: new progs would learn it on sight
#2: don't be lazy. If the condition clause seems to be too long, declare a boolean for it.
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: Ternary Operator Poll
by jendave » 13 Sep 2011, 05:46
Interesting poll since ternary operators have always been allowed. There is not currently nor has ever been a restriction on them.
Re: Ternary Operator Poll
by Rob Cashwalker » 13 Sep 2011, 13:26
OK, who voted "What's a Ternary Operator?"... show yourself!
Dave, I wouldn't have given it much consideration either until it was mentioned that it could be restricted.... Then I thought about it and read up on the topic. And read it again, because it still wasn't clear. Then actually looking for it in code, I kinda got it... So if I'm having this much trouble wrapping my head around it (and I'm a fairly experienced programmer) then at least one other person must be confused too.
If it's the sort of thing that Checkstyle can flag, then flag it.. doesn't mean it MUST be changed... if someone needs it in the code, then can't they add a @suppress code or something?
Dave, I wouldn't have given it much consideration either until it was mentioned that it could be restricted.... Then I thought about it and read up on the topic. And read it again, because it still wasn't clear. Then actually looking for it in code, I kinda got it... So if I'm having this much trouble wrapping my head around it (and I'm a fairly experienced programmer) then at least one other person must be confused too.
If it's the sort of thing that Checkstyle can flag, then flag it.. doesn't mean it MUST be changed... if someone needs it in the code, then can't they add a @suppress code or something?
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: Ternary Operator Poll
by DennisBergkamp » 13 Sep 2011, 14:06
I think we currently have some of these in the code anyway (unless they were removed).
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Ternary Operator Poll
by jendave » 13 Sep 2011, 15:14
Up until a few days ago, checkstyle would flag it. The official Sun style guide allows them so I removed the flag per Max's request. @Suppress can be used but that is ugly in my opinion.Rob Cashwalker wrote:If it's the sort of thing that Checkstyle can flag, then flag it.. doesn't mean it MUST be changed... if someone needs it in the code, then can't they add a @suppress code or something?
9 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 38 guests