Re: [go-nuts] Go if else syntax .. suggested replacement

2019-05-14 Thread Michael Jones
On Mon, May 13, 2019 at 7:46 AM  wrote:

> Given the extent of responses to the original question by the Go community
> (pro and con), hopefully those responsible for Go syntax will re-visit the
> issue and decide whether Go statement "if test then {.. } else { .. }"
> prevents any possible abuse or confusion  that would occur if it were
> replaced with   ?test { ..} : { .. }
>

It is inconceivable that "if test then {.. } else { .. }" will be replaced
with "?test { ..} : { .. }" just as it is to consider changing red
octagonal stop signs to blue ovals. A massive, omnipresent change (such as
stop signs, power outlet plugs, which side of the road to drive on,
programming paradigms now natural to tens of millions of people, etc.)
needs an enormous motivation to be undertaken voluntarily--major problems
that must urgently be solved in the new way. Nothing in the email here
suggests anything more than personal preference and that is far too weak
for such a change even if the Go gods all liked it. This is a stewardship
issue.

(speaking as a non-god, but speaking truth)

-- 

*Michael T. jonesmichael.jo...@gmail.com *

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CALoEmQyLfKSJWMz9w_UiNK5qt%3Dhm_J_vbt8T6ZWg3Pviv9EgEw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-05-13 Thread lgodio2
Dave: Thanks for pursuing this issue and reporting back. 

Given the extent of responses to the original question by the Go community 
(pro and con), hopefully those responsible for Go syntax will re-visit the 
issue and decide whether Go statement "if test then {.. } else { .. }"  
prevents any possible abuse or confusion  that would occur if it were 
replaced with   ?test { ..} : { .. }

On Sunday, May 12, 2019 at 11:35:51 AM UTC-4, David Riley wrote:
>
> On May 12, 2019, at 06:55, Jesper Louis Andersen  > wrote:
>
> I don't think there are developers who find it unreadable once they know 
> the logic of that operator. However, if you don't know the rules, then it 
> looks like black magic.
>
> In large software developments, consistency beats convenience almost all 
> the time. You can somewhat easily add another developer, if the notation 
> rules are consistent. Whereas clever notational convenience costs for every 
> developer you add to the project. Giving people a choice means you have yet 
> another section in your style guide to understand and maintain.
>
> The deeper observation is that in a language with two syntactic classes, 
> statements and expressions, you can opt to have an if-like evaluation in 
> the expression class, or you can omit it. Go does the latter, where C does 
> the former. Of course, you can also define your language with a single 
> syntactic class. In that case, the above example can be written
>
> let color = if temperature > 80 then "red" else "green" in ...
>
> This style is used in a large selection of languages, which people often 
> call "functional languages". Though the lines of when something fits into 
> the moniker is somewhat blurry.
>
>
> As it happens, I did get to ask Ken Thompson about his reasoning when he 
> presented at VCF East last weekend.
>
> Ken said, as close to verbatim as my week-old memory gets, that they were 
> “too hard to compile right without the possibility of introducing subtle 
> bugs”. I didn’t press further, because there were plenty of people in line 
> to talk to him and I didn’t want to be rude; my assumption is that he was 
> talking about either order of expression execution, or the difficulty of 
> lumping the subexpressions together. He definitely didn’t have anything to 
> say about their potential for abuse or about them being confusing to new 
> programmers, but then we also didn’t talk long.
>
> Just adding that since I said I’d ask about it a few weeks ago.
>
> BTW, the video of his keynote chat with Brian Kernighan is not to be 
> missed; I was working the audio, so sorry about Brian’s levels, but he was 
> feeding back so I couldn’t turn him up any louder: 
> https://m.youtube.com/watch?v=EY6q5dv_B-o
>
>
> - Dave
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/86a25187-3a9c-4e28-adf6-eafeb7651bbd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-05-12 Thread David Riley
On May 12, 2019, at 06:55, Jesper Louis Andersen 
 wrote:
> 
> I don't think there are developers who find it unreadable once they know the 
> logic of that operator. However, if you don't know the rules, then it looks 
> like black magic.
> 
> In large software developments, consistency beats convenience almost all the 
> time. You can somewhat easily add another developer, if the notation rules 
> are consistent. Whereas clever notational convenience costs for every 
> developer you add to the project. Giving people a choice means you have yet 
> another section in your style guide to understand and maintain.
> 
> The deeper observation is that in a language with two syntactic classes, 
> statements and expressions, you can opt to have an if-like evaluation in the 
> expression class, or you can omit it. Go does the latter, where C does the 
> former. Of course, you can also define your language with a single syntactic 
> class. In that case, the above example can be written
> 
> let color = if temperature > 80 then "red" else "green" in ...
> 
> This style is used in a large selection of languages, which people often call 
> "functional languages". Though the lines of when something fits into the 
> moniker is somewhat blurry.

As it happens, I did get to ask Ken Thompson about his reasoning when he 
presented at VCF East last weekend.

Ken said, as close to verbatim as my week-old memory gets, that they were “too 
hard to compile right without the possibility of introducing subtle bugs”. I 
didn’t press further, because there were plenty of people in line to talk to 
him and I didn’t want to be rude; my assumption is that he was talking about 
either order of expression execution, or the difficulty of lumping the 
subexpressions together. He definitely didn’t have anything to say about their 
potential for abuse or about them being confusing to new programmers, but then 
we also didn’t talk long.

Just adding that since I said I’d ask about it a few weeks ago.

BTW, the video of his keynote chat with Brian Kernighan is not to be missed; I 
was working the audio, so sorry about Brian’s levels, but he was feeding back 
so I couldn’t turn him up any louder: https://m.youtube.com/watch?v=EY6q5dv_B-o


- Dave

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4EF0A6BE-E1A6-4844-A297-07BE31BA07A9%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-05-12 Thread Jesper Louis Andersen
I don't think there are developers who find it unreadable once they know
the logic of that operator. However, if you don't know the rules, then it
looks like black magic.

In large software developments, consistency beats convenience almost all
the time. You can somewhat easily add another developer, if the notation
rules are consistent. Whereas clever notational convenience costs for every
developer you add to the project. Giving people a choice means you have yet
another section in your style guide to understand and maintain.

The deeper observation is that in a language with two syntactic classes,
statements and expressions, you can opt to have an if-like evaluation in
the expression class, or you can omit it. Go does the latter, where C does
the former. Of course, you can also define your language with a single
syntactic class. In that case, the above example can be written

let color = if temperature > 80 then "red" else "green" in ...

This style is used in a large selection of languages, which people often
call "functional languages". Though the lines of when something fits into
the moniker is somewhat blurry.

On Wed, Apr 24, 2019 at 4:08 PM Mark Volkmann 
wrote:

> Are there really developers that find this unreadable?
>
> color := temperature > 80 ? “red” : “green”
>
> I know what you are going to say. People will nest them. But even nested
> usage can be readable when formatted nicely with one condition per line.
> Another alternative is to allow only unnested ternaries.
>
> R. Mark Volkmann
> Object Computing, Inc.
>
> > On Apr 24, 2019, at 8:58 AM, Jan Mercl <0xj...@gmail.com> wrote:
> >
> >> On Wed, Apr 24, 2019 at 3:48 PM L Godioleskky 
> wrote:
> >>
> >> The lack of a Go ternary operator is at odds with Go's major theme of
> clean and easy to read syntax. Those who choose not to use the ternary
> operator can always resort back to Go's current 'if -else' or 'case'
> syntax. So Go syntax suffers no negative impact by adding the ternary op to
> its syntax list.  Those opposed to the ternary op should not be allowed to
> deny it use other Go programmers, that consider it useful.
> >
> > That's backwards. Those who has to read the code can no more chose not
> > to decrypt the unreadable 4-level nested ternary operations instead of
> > 5 if statements.
> >
> > And to follow on your "logic". If you add to Go even just 10% of what
> > people consider useful, it will become a new C++, only much worse. And
> > again by your very logic. Why we, that haven't chosen to code in C++
> > in the first place, would be denied by others to use Go, when those
> > others have C++ already at hand?
> >
> > Let everyone use the language he/she likes. Why ruin it for others
> > instead of that by forcing Go to become the same as his/her other
> > favorite language?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
J.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAGrdgiVQkaDS%2B%3D%2BcSCRFGgK1bpaDJFy6fVAZr5xpMVxv%3D6PNhg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-05-07 Thread DrGo
I suggest that we first solve less controversial issues like the 
Israeli–Palestinian conflict.  

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/87430fd4-0244-4b3d-ae27-c27acd4f5ef9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-28 Thread Mike Schinkel
> As language choice becomes more arbitrary, and transpilers more common, 
> personal preferred syntax / language features may end up being handled like 
> code formatting rules. So In Peter++ I could then use all the syntax I like, 
> transpile that to WASM or LLVM, and someone else working on that code 
> transpiles it back into Gopher++ to make a change.

That appears to be more of a bug than a feature to me, and a nightmare of 
incompatible source code. Imagine everyone on a team having their source code 
in their own flavor of a language? And I have yet to see a transpiler maintain 
100% compatibility in both directions.

Sounds like pure hell to me.

IMO transpilers are a hack that come with lots of downsides. Also IMO 
developers use transpilers because those controlling the evolution of a 
language have not been responsive to the needs of their developers (I am mainly 
looking at CSS here, not Go.)

I for one pine for a day that will likely never come when transpilers are no 
longer needed for development (I am not referring to go generate here, but 
tools to input one language and output another.)

JMTCW.

-Mike

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-27 Thread Michael Jones
Agree completely. Despite my reasoned comfort with Go’s rationale I miss
quite a few “but I want to express this algorithm beautifully for the ages”
features. I don’t miss the ternary syntax but miss the natural way to say
“it is an assignment, first, but subject to logic, second.” Same as I miss
do...until/while, because the trivial workaround obscures the logic and I
feel I’ve cheated the reader. Likewise, I lay out structs so the variable
width parts (strings say) will be last so that the initializer will look as
non-bad as possible after gofmt. I understand the trade off, but wish the
literate style and beauty of mathematical typography had a better friend in
go.

On Sat, Apr 27, 2019 at 10:19 AM  wrote:

> Ada originally followed BCPL and Pascal in distinguishing between commands
> (statements) and expressions, compared say to Algol68 which was an
> expression language.
> BCPL had VALOF/RESULTIS to link the two realms. It also had a conditional
> expression (A -> B, C) with the same meaning as B's and C's later (A? B: C)
> [which is probably better syntax].
> Neither Pascal nor Ada had conditional expressions, for different reasons.
>
> Ada has since added both "if" and "case" as conditional expression forms
> (including "elseif"). There's a discussion in the 2012 Rationale:
> http://www.ada-auth.org/standards/12rat/html/Rat12-3-2.html A big reason
> for introducing them was to support writing preconditions and
> postconditions.
> there are quantifying expressions as well (ie, "for all", "for some").
> Originally, they were
> special pragmas in the SPARK subset but were finally promoted to be part
> of the language.
>
> Following the discussion above, I'd note though that one difference
> between (say)
>
> if a > b {
>m = a
> } else {
>m = b
> }
>
>and
>  m := b
>  if a > b {
>m = a
>  }
> is that the former emphasises that the two cases (assignments) are
> mutually exclusive (m is either a or it is b), as opposed to (m is b unless
> it then becomes a),
> not very interesting here but there can be more complex cases.
>
> In converting a C# program to Go I've had a few instances where converting
> to if/else was clumsier or even more obscure, often it seems in
> constructors converted to struct literals,
> but in practice it's a minor point. As someone observed, sometimes little
> helper functions restore the flow and improve clarity (count!=0?
> total/count: 0) => avg(total, count)
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
-- 

*Michael T. jonesmichael.jo...@gmail.com *

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-27 Thread charles . forsyth
Ada originally followed BCPL and Pascal in distinguishing between commands 
(statements) and expressions, compared say to Algol68 which was an 
expression language.
BCPL had VALOF/RESULTIS to link the two realms. It also had a conditional 
expression (A -> B, C) with the same meaning as B's and C's later (A? B: C) 
[which is probably better syntax].
Neither Pascal nor Ada had conditional expressions, for different reasons.

Ada has since added both "if" and "case" as conditional expression forms 
(including "elseif"). There's a discussion in the 2012 Rationale:
http://www.ada-auth.org/standards/12rat/html/Rat12-3-2.html A big reason 
for introducing them was to support writing preconditions and 
postconditions.
there are quantifying expressions as well (ie, "for all", "for some"). 
Originally, they were 
special pragmas in the SPARK subset but were finally promoted to be part of 
the language.

Following the discussion above, I'd note though that one difference between 
(say)

if a > b {
   m = a
} else {
   m = b
}

   and
 m := b
 if a > b {
   m = a
 }
is that the former emphasises that the two cases (assignments) are mutually 
exclusive (m is either a or it is b), as opposed to (m is b unless it then 
becomes a),
not very interesting here but there can be more complex cases. 

In converting a C# program to Go I've had a few instances where converting 
to if/else was clumsier or even more obscure, often it seems in 
constructors converted to struct literals,
but in practice it's a minor point. As someone observed, sometimes little 
helper functions restore the flow and improve clarity (count!=0? 
total/count: 0) => avg(total, count)

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-26 Thread 'Keith Randall' via golang-nuts


On Wednesday, April 24, 2019 at 2:03:01 PM UTC-7, Kurtis Rader wrote:
>
> On Wed, Apr 24, 2019 at 1:14 PM andrey mirtchovski  > wrote:
>
>> Here's the lore associated with the subject: Ken wanted ternary, Rob
>> and Robert did not. They overruled Ken (remember, early on all three
>> had to agree for a feature to go in). The end.
>>
>> The number of frivolous and egregious abuse of ternary that I've seen
>> in _modern_ C code is too high.jpg
>>
>
> +100 to that sentiment. While the brevity of a ternary expression 
> is  useful for trivial cases it tends to be abused. For your 
> amusement/horror here are just a few, of a couple hundred, examples of 
> ternary being abused in the AT AST (which includes ksh) source:
>
>
> https://github.com/att/ast/blob/e770c77e9816e156c6df4a455e71b5f9fff79310/src/cmd/ksh93/edit/hexpand.c#L447
>
>
> https://github.com/att/ast/blob/e770c77e9816e156c6df4a455e71b5f9fff79310/src/cmd/ksh93/sh/string.c#L344-L346
>
>
> https://github.com/att/ast/blob/8504cd407846d192881a94d507333697f016a85a/src/lib/libast/include/sfio.h#L359-L360
>
>
> https://github.com/att/ast/blob/8504cd407846d192881a94d507333697f016a85a/src/lib/libast/include/cdt.h#L313-L316
>
>
> https://github.com/att/ast/blob/e770c77e9816e156c6df4a455e71b5f9fff79310/src/lib/libz/deflate.c#L597-L609
>
> For those who don't want to follow those links this is the code from the 
> first URL above:
>
> lc_unicodeliterals = quote=='u' ? 1 : quote=='U' ? 0 : !!(ast.locale.set & 
> AST_LC_unicodeliterals);
>
>
That one has the !! operator in it also, sweet twofer!
(It's the second link, not the first.)
 

> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-26 Thread Michael Jones
The last time there was a big thread about this, I explained how GCC added
“value of brace block is value of last expression” to allow great power,
and a fellow poster explained how this came into being with Algol-68.

There is long history in these ideas, and much value, but Go specifically
chose not to be an expression language. The limits of this are clear in the
++ statement vs c’s ++ operator. Huge, delicious power in the latter, tepid
bit of economy in the former. It was a loss. The offsetting gain was
believed to be in avoiding the four decades of confusion about ++ order of
evaluation in function arguments and other situations.

It’s natural to miss power long held. The Go experiment is about team
efficiency in a far simpler language. It feels a great success to me
despite the frustration of feeling muzzled.

On Fri, Apr 26, 2019 at 6:18 AM Mike Schinkel  wrote:

> I was assuming the compiler did not eliminate it. If it does then my point
> is moot.
>
> -Mike
>
> Sent from my iPad
>
> > On Apr 26, 2019, at 9:13 AM, Ian Lance Taylor  wrote:
> >
> >> On Thu, Apr 25, 2019 at 10:57 PM Mike Schinkel 
> wrote:
> >>
> >> Marcus Low wrote:
> >>>
> >>> datalen := removedKeyken // removedKeyken must have been int32 in your
> example.
> >>> if value != nil {
> >>>   datalen = len(value)
> >>> }
> >>
> >>
> >> The issue with this is it makes two assignments when value != nil
> instead of just one.
> >
> > In what sense is that an issue?  If you are concerned about
> > performance, note that the compiler can eliminate the initial
> > assignment in the value == nil case if it is costly.
> >
> > Ian
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
-- 

*Michael T. jonesmichael.jo...@gmail.com *

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-26 Thread Mike Schinkel
I was assuming the compiler did not eliminate it. If it does then my point is 
moot.

-Mike

Sent from my iPad

> On Apr 26, 2019, at 9:13 AM, Ian Lance Taylor  wrote:
> 
>> On Thu, Apr 25, 2019 at 10:57 PM Mike Schinkel  wrote:
>> 
>> Marcus Low wrote:
>>> 
>>> datalen := removedKeyken // removedKeyken must have been int32 in your 
>>> example.
>>> if value != nil {
>>>   datalen = len(value)
>>> }
>> 
>> 
>> The issue with this is it makes two assignments when value != nil instead of 
>> just one.
> 
> In what sense is that an issue?  If you are concerned about
> performance, note that the compiler can eliminate the initial
> assignment in the value == nil case if it is costly.
> 
> Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-26 Thread Ian Lance Taylor
On Thu, Apr 25, 2019 at 10:57 PM Mike Schinkel  wrote:
>
> Marcus Low wrote:
>>
>> datalen := removedKeyken // removedKeyken must have been int32 in your 
>> example.
>> if value != nil {
>>datalen = len(value)
>> }
>
>
> The issue with this is it makes two assignments when value != nil instead of 
> just one.

In what sense is that an issue?  If you are concerned about
performance, note that the compiler can eliminate the initial
assignment in the value == nil case if it is costly.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-26 Thread Mike Schinkel
> David Riley  wrote:
> same potential for abuse (no one is gonna stop you from nesting expressions).

Yes, but only assuming it were implemented as an expression.

However, if it were instead implemented as an “if-assignment" statement?

result := if temperature > 80 
   then "red"
   else "green"


Having it be a statement instead would not address what everyone wants, but it 
would solve the excessive verbosity of referencing “result” three times and 
having to explicitly declare its type, or having to assign to it only to have 
its value immediately overwritten:

var result string
if temperature > 80 {
   result = "red"
} else {
   result = "green"
}

And it would do those things without the downsides mentioned thus far in this 
thread. 

-Mike

P.S. And for me personally, it would help reduce the carpel-tunnel flareups I 
get from having to type so damn many shift-brace keystrokes.  :-)

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-26 Thread David Riley
On Apr 26, 2019, at 2:12 AM, Mike Schinkel  wrote:
> 
> Given that, I am curious what your thoughts would be if this were possible in 
> Go instead?
>  
>color := if temperature > 80 then “red” else “green” 
> 
> And especially if this formatting were valid:
> 
>color := if temperature > 80 
>   then “red” 
>   else “green” 

That is pretty close to how Python added a ternary operator:

foo = bar if a==b else baz

More Pythonic, but same potential for abuse (no one is gonna stop you from 
nesting expressions).


- Dave

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-26 Thread djadala


On Friday, April 26, 2019 at 9:12:06 AM UTC+3, Mike Schinkel wrote:
>
> On Thursday, April 25, 2019 at 10:20:54 AM UTC-4, Sam Whited wrote:
>>
>> On Wed, Apr 24, 2019, at 14:08, Mark Volkmann wrote: 
>> > Are there really developers that find this unreadable? 
>> > 
>> > color := temperature > 80 ? “red” : “green” 
>>
>> Yes. 
>>
>> What is "?"? If I've never seen that before I have no easy way to search 
>> for that, and a random symbol me nothing about what it does. Go 
>> specifically tries to stick to keywords because even if you've never 
>> seen them before it's generally easier to figure out what they do (or to 
>> search for them if you're not sure). 
>>
>
> Given that, I am curious what your thoughts would be if this were possible 
> in Go instead?
>  
>color := if temperature > 80 then “red” else “green” 
>
> And especially if this formatting were valid:
>
>color := if temperature > 80 
>   then “red” 
>   else “green” 
>


Hi,
this is valid now:

color := func() string {
if temperature > 80 {
return "red"
}
return "green"
}()


https://play.golang.org/p/U7Lc92mq315 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-26 Thread Mike Schinkel
On Thursday, April 25, 2019 at 10:20:54 AM UTC-4, Sam Whited wrote:
>
> On Wed, Apr 24, 2019, at 14:08, Mark Volkmann wrote: 
> > Are there really developers that find this unreadable? 
> > 
> > color := temperature > 80 ? “red” : “green” 
>
> Yes. 
>
> What is "?"? If I've never seen that before I have no easy way to search 
> for that, and a random symbol me nothing about what it does. Go 
> specifically tries to stick to keywords because even if you've never 
> seen them before it's generally easier to figure out what they do (or to 
> search for them if you're not sure). 
>

Given that, I am curious what your thoughts would be if this were possible 
in Go instead?
 
   color := if temperature > 80 then “red” else “green” 

And especially if this formatting were valid:

   color := if temperature > 80 
  then “red” 
  else “green” 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread Mike Schinkel

Marcus Low wrote:
>
> datalen := removedKeyken // removedKeyken must have been int32 in your 
> example.
> if value != nil {
>datalen = len(value)
> }
>

The issue with this is it makes two assignments when value != nil instead 
of just one.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread Dan Kortschak
Please understand that my use of ?: in the proposed grammar is
irrelevant. Using the syntax proposed here leads to the same problem.

You have self contradictory claims below:

   1. the change is only a swapping of 'if' => '?' and 'else' => ':' with
  no semantic change: "My proposal  regarding ? test {...} : {.. } in
  is nothing more, nothing less than  a replacement for if (test) {
  ... } else {... }   i.e. 'if' and 'else' are replaced by symbols '?'
  and ';' .."
   2. the change will result in conditional statements becoming
  expressions: "second part of my proposal called for allowing
  statements like x = (test) ? 1 : 0 to compile in Go."

1. and 2. are mutually exclusive since changing conditional statements
into conditional expressions is a sematic change.

In addition to this, there is a reduced readability for cases where
there are 'if { } else if { } else { }' chains (particularly if you
prohibit nesting as you want to.

The idea of prohibiting nesting is not feasible without introducing
special rules. Currently the grammar for conditionals is this:

IfStmt = "if" [ SimpleStmt ";" ] Expression Block [ "else" ( IfStmt |
Block ) ] .

Which, if we simplify out the optional pre-condition statement we get
this:

IfStmt = "if" Expression Block [ "else" ( IfStmt | Block ) ] .

If we make the IfStmt into an IfExpr, to be useful, we end up with
along the lines of this (we need a new production that I am ignoring,
but you should get the idea):

IfExpr = "if" Expression ( Block | Expression ) [ "else" ( IfExpr |
Block | Expression ) ] .

And, IfExpr will need to be an Expression (otherwise there was no point).

So, how do you prevent the following (using current syntax, but with these new 
semantics).

```
if c == if test {
a
} else {
b
} {
fmt.Println("test is true and c == a or test is false and c == 
b")
} else {
fmt.Println("test is true and c != a or test is false and c != 
b")
}
```

(which is a nightmare to reason about already, even without new glyph-
based syntax)

The only way to prevent that is to special case the IfExpr, which
complicates the grammar and requires explanation of the special case,
and as I said before, ongoing go-nuts threads explaining why the
special case exists.

It's worthwhile trying to understand the arguments against the proposal
before you argue against the.

On Thu, 2019-04-25 at 17:27 -0700, lgod...@gmail.com wrote:
> To Kortschak and all others participating in this debate :
> 
> Please don't get hung up over my choice of symbol '?' . 
> My choice of symbol '?' and ';' is causing people to equate my
> proposal 
> with a proposal to adopt C's ternary operator in Go. This is not what
> I 
> intended to propose.
> 
> My proposal  regarding ? test {...} : {.. } in is nothing more,
> nothing 
> less than  a replacement for 
> if (test) { ... } else {... }   i.e. 'if' and 'else' are replaced by 
> symbols '?' and ';' ..
> 
> For example I propose that a statement like  ? (x >-1) { y=x; z= x*x
> } : { 
> y=x*x; z= y  } compile in Go
> EXACTLY THE SAME way that Go currently compiles the same statement
> with 
> symbol '?' replaced by 'if' and ';' replaced by 'else' . Currently,
> neither 
> C++, C nor Go will compile the above statement 
> 
> The  second part of my proposal called for allowing statements like x
> = 
> (test) ? 1 : 0 to compile in Go.
> C will currently  compile this statement but Go will not. But I
> stress 
> again, I intended Go to compile this   
> statement exactly the same way it compiles if (test) { x=1}  else {
> x=0 }  
> AND that no nested '?' symbols are allowed in a single assignment
> statement.
> 
> In short, I'm proposing a cleaner way to write Go 'if'  'else'
> statements,  
> nothing more, nothing less.
> 
> If anyone can offer a concrete example of how my proposed statement
> will 
> cause problems in Go, just  replace my chosen symbol '?' with 'if'
> and 
> symbol ';' with 'else'  and you'll have a statement that will
> currently 
> compile in Go (and cause the same problems)
> 
> 
> 
>  ..  
> On Thursday, April 25, 2019 at 5:15:23 PM UTC-4, kortschak wrote:
> > 
> > 
> > The difference is that the ternary operator is an expression and
> > the 
> > if...else is a statement. If you're only suggesting a syntax
> > change, 
> > then the difference becomes one of readability. 
> > 
> > I'll ask again, how would you preclude nesting without making the 
> > language more complex? 
> > 
> > On Thu, 2019-04-25 at 13:38 -0700, lgo...@gmail.com 
> > wrote: 
> > > 
> > > Rob: 
> > > 
> > > Am I missing something ?? 
> > > The proposed syntax  
> > > test ? {  
> > > } : {  
> > > }   
> > > 
> > > with no-nesting allowed is equivalent to 
> > > if test {  
> > > //. 
> > > } else { 
> > > // ..  
> > > }  
> > > ..The former is just a cleaner way of writing the latter 
> > > 
> > > Any complaints regarding 'abuse' associated 

Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread Robert Engels
The problem is that Go already has if and else and else if (which would look 
really weird in your proposal)

Changing a word to a symbol does not enhance meaning -  it reduces it, and 
increases the learning curve. 

 Like I said, you will probably like Ada - lots of symbols there. 

> On Apr 25, 2019, at 7:27 PM, lgod...@gmail.com wrote:
> 
> To Kortschak and all others participating in this debate :
> 
> Please don't get hung up over my choice of symbol '?' . 
> My choice of symbol '?' and ';' is causing people to equate my proposal with 
> a proposal to adopt C's ternary operator in Go. This is not what I intended 
> to propose.
> 
> My proposal  regarding ? test {...} : {.. } in is nothing more, nothing less 
> than  a replacement for 
> if (test) { ... } else {... }   i.e. 'if' and 'else' are replaced by symbols 
> '?' and ';' ..
> 
> For example I propose that a statement like  ? (x >-1) { y=x; z= x*x } : { 
> y=x*x; z= y  } compile in Go
> EXACTLY THE SAME way that Go currently compiles the same statement with 
> symbol '?' replaced by 'if' and ';' replaced by 'else' . Currently, neither 
> C++, C nor Go will compile the above statement 
> 
> The  second part of my proposal called for allowing statements like x = 
> (test) ? 1 : 0 to compile in Go.
> C will currently  compile this statement but Go will not. But I stress again, 
> I intended Go to compile this   
> statement exactly the same way it compiles if (test) { x=1}  else { x=0 }  
> AND that no nested '?' symbols are allowed in a single assignment statement.
> 
> In short, I'm proposing a cleaner way to write Go 'if'  'else' statements,  
> nothing more, nothing less.
> 
> If anyone can offer a concrete example of how my proposed statement will 
> cause problems in Go, just  replace my chosen symbol '?' with 'if' and symbol 
> ';' with 'else'  and you'll have a statement that will currently compile in 
> Go (and cause the same problems)
> 
> 
> 
>  ..  
>> On Thursday, April 25, 2019 at 5:15:23 PM UTC-4, kortschak wrote:
>> The difference is that the ternary operator is an expression and the 
>> if...else is a statement. If you're only suggesting a syntax change, 
>> then the difference becomes one of readability. 
>> 
>> I'll ask again, how would you preclude nesting without making the 
>> language more complex? 
>> 
>> On Thu, 2019-04-25 at 13:38 -0700, lgo...@gmail.com wrote: 
>> > Rob: 
>> > 
>> > Am I missing something ?? 
>> > The proposed syntax  
>> > test ? {  
>> > } : {  
>> > }   
>> > 
>> > with no-nesting allowed is equivalent to 
>> > if test {  
>> > //. 
>> > } else { 
>> > // ..  
>> > }  
>> > ..The former is just a cleaner way of writing the latter 
>> > 
>> > Any complaints regarding 'abuse' associated with the former equally 
>> > apply  
>> > to the latter 
>> > 
>> > On Thursday, April 25, 2019 at 11:47:21 AM UTC-4, Rob 'Commander' 
>> > Pike  
>> > wrote: 
>> > > 
>> > > 
>> > > I am pretty sure that the decision not to have ?: in Go was a 
>> > > unanimous  
>> > > decision by Robert, Ken and myself after almost no discussion. It 
>> > > is too  
>> > > easy to abuse, as the FAQ states. 
>> > > 
>> > > -rob 
>> > > 
>> > > 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread lgodio2
To Kortschak and all others participating in this debate :

Please don't get hung up over my choice of symbol '?' . 
My choice of symbol '?' and ';' is causing people to equate my proposal 
with a proposal to adopt C's ternary operator in Go. This is not what I 
intended to propose.

My proposal  regarding ? test {...} : {.. } in is nothing more, nothing 
less than  a replacement for 
if (test) { ... } else {... }   i.e. 'if' and 'else' are replaced by 
symbols '?' and ';' ..

For example I propose that a statement like  ? (x >-1) { y=x; z= x*x } : { 
y=x*x; z= y  } compile in Go
EXACTLY THE SAME way that Go currently compiles the same statement with 
symbol '?' replaced by 'if' and ';' replaced by 'else' . Currently, neither 
C++, C nor Go will compile the above statement 

The  second part of my proposal called for allowing statements like x = 
(test) ? 1 : 0 to compile in Go.
C will currently  compile this statement but Go will not. But I stress 
again, I intended Go to compile this   
statement exactly the same way it compiles if (test) { x=1}  else { x=0 }  
AND that no nested '?' symbols are allowed in a single assignment statement.

In short, I'm proposing a cleaner way to write Go 'if'  'else' statements,  
nothing more, nothing less.

If anyone can offer a concrete example of how my proposed statement will 
cause problems in Go, just  replace my chosen symbol '?' with 'if' and 
symbol ';' with 'else'  and you'll have a statement that will currently 
compile in Go (and cause the same problems)



 ..  
On Thursday, April 25, 2019 at 5:15:23 PM UTC-4, kortschak wrote:
>
> The difference is that the ternary operator is an expression and the 
> if...else is a statement. If you're only suggesting a syntax change, 
> then the difference becomes one of readability. 
>
> I'll ask again, how would you preclude nesting without making the 
> language more complex? 
>
> On Thu, 2019-04-25 at 13:38 -0700, lgo...@gmail.com  wrote: 
> > Rob: 
> > 
> > Am I missing something ?? 
> > The proposed syntax  
> > test ? {  
> > } : {  
> > }   
> > 
> > with no-nesting allowed is equivalent to 
> > if test {  
> > //. 
> > } else { 
> > // ..  
> > }  
> > ..The former is just a cleaner way of writing the latter 
> > 
> > Any complaints regarding 'abuse' associated with the former equally 
> > apply  
> > to the latter 
> > 
> > On Thursday, April 25, 2019 at 11:47:21 AM UTC-4, Rob 'Commander' 
> > Pike  
> > wrote: 
> > > 
> > > 
> > > I am pretty sure that the decision not to have ?: in Go was a 
> > > unanimous  
> > > decision by Robert, Ken and myself after almost no discussion. It 
> > > is too  
> > > easy to abuse, as the FAQ states. 
> > > 
> > > -rob 
> > > 
> > > 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread Tyler Compton
>
> There are many counter-examples. What is the likelihood that someone who
> is not familiar with the "?" operator will be familiar with the operators
> for getting (*) and dereferencing (&) a pointer. And what is "<-"?
> Certainly people not familiar with Go will initially be confused by
> operators related to channels.
>

>
If you allow people to use pointers, will they use pointers to pointers to
> pointers to pointers?
>

Sure, every language feature has a complexity cost and a chance for abuse.
However, the win for having pointers is, to me, a thousand times more
significant than that of the ternary operator, so it helps outweigh the
drawbacks that pointers introduce.


> On Thu, Apr 25, 2019 at 9:19 AM Sam Whited  wrote:
>
>> On Wed, Apr 24, 2019, at 14:08, Mark Volkmann wrote:
>> > Are there really developers that find this unreadable?
>> >
>> > color := temperature > 80 ? “red” : “green”
>>
>> Yes.
>>
>> What is "?"? If I've never seen that before I have no easy way to search
>> for that, and a random symbol me nothing about what it does. Go
>> specifically tries to stick to keywords because even if you've never
>> seen them before it's generally easier to figure out what they do (or to
>> search for them if you're not sure).
>>
>> Not to mention that even if you do know what they do, that specific
>> statement isn't the problem. If you allow people to do that, they'll end
>> up trying to nest it 5 levels deep. Go tries not to give people the
>> tools to shoot themselves in the foot for some tiny perceived advantage.
>>
>> —Sam
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread Dan Kortschak
The difference is that the ternary operator is an expression and the
if...else is a statement. If you're only suggesting a syntax change,
then the difference becomes one of readability.

I'll ask again, how would you preclude nesting without making the
language more complex?

On Thu, 2019-04-25 at 13:38 -0700, lgod...@gmail.com wrote:
> Rob:
> 
> Am I missing something ??
> The proposed syntax 
> test ? { 
> } : { 
> }  
> 
> with no-nesting allowed is equivalent to
> if test { 
> //.
> } else {
> // .. 
> } 
> ..The former is just a cleaner way of writing the latter
> 
> Any complaints regarding 'abuse' associated with the former equally
> apply 
> to the latter
> 
> On Thursday, April 25, 2019 at 11:47:21 AM UTC-4, Rob 'Commander'
> Pike 
> wrote:
> > 
> > 
> > I am pretty sure that the decision not to have ?: in Go was a
> > unanimous 
> > decision by Robert, Ken and myself after almost no discussion. It
> > is too 
> > easy to abuse, as the FAQ states.
> > 
> > -rob
> > 
> > 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread lgodio2
Rob:

Am I missing something ??
The proposed syntax 
test ? { 
} : { 
}  

with no-nesting allowed is equivalent to
if test { 
//.
} else {
// .. 
} 
..The former is just a cleaner way of writing the latter

Any complaints regarding 'abuse' associated with the former equally apply 
to the latter

On Thursday, April 25, 2019 at 11:47:21 AM UTC-4, Rob 'Commander' Pike 
wrote:
>
> I am pretty sure that the decision not to have ?: in Go was a unanimous 
> decision by Robert, Ken and myself after almost no discussion. It is too 
> easy to abuse, as the FAQ states.
>
> -rob
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread 'Thomas Bushnell, BSG' via golang-nuts
I'm a big fan of the ternary operator in general. Maybe this is because I'm
an old timey Lisper. A lot of the things people see as "abuse" or "too
complex" are equally problems with || and &&.

This is also true for Jan's point: that ?: affects control flow by omitting
execution sometimes. It would be lovely to say that in an expression, the
subexpressions are always evaluated. But Go did the usual thing, declaring
that && and || proceed conditionally.

If x and y are booleans, in fact, then "a ? x : y" is identical to "(a &&
x) || (!a && y)". We have all see boolean spaghetti. At the same time, I
get sad whenever I see things like "if a { return x == y; } else { return
false; }".

I don't mind Go's choice, however. It's a pragmatic and sensible choice: a
bunch of people, for whatever reason, find && and || easy to reason about,
and ?: annoying. Making code transparent is an important goal, so if you
want to target those readers, avoid ?:. And a language like Go, designed to
facilitate making things easy to understand over maximum economy of
characters, sensibly omits ?:.

This fits with good Go style, which tends to avoid "else" more than a lot
of other languages, making ?: standout all the more, with it's mandatory
"else" clause. And, unlike && and ||, ?: works with all types, thus making
it more pervasive when used.

Frankly, I would have preferred the Pascal approach here, which is more in
line with what Jan says: decouple entirely control flow from syntax of
expressions, and stop the experiment of having expression syntax imply
control flow. That means that && and || might "short circuit" but also
might not, and you would not be able to assume anything about the order of
subexpression execution. But, at the same time, I have no quarrel with the
pragmatic decision for Go to define those exactly instead.




On Thu, Apr 25, 2019 at 3:15 PM Jan Mercl <0xj...@gmail.com> wrote:

> On Thu, Apr 25, 2019 at 8:58 PM  wrote:
> >
> > Rob : how can it be abused if the compiler wont allow nested ? operators
> ??
>
> Rather easily. Just by fuzzilly mixing the otherwise purposely
> distinct syntax of expressions and control flow.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread Jan Mercl
On Thu, Apr 25, 2019 at 8:58 PM  wrote:
>
> Rob : how can it be abused if the compiler wont allow nested ? operators ??

Rather easily. Just by fuzzilly mixing the otherwise purposely
distinct syntax of expressions and control flow.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread lgodio2
Rob : how can it be abused if the compiler wont allow nested ? operators ??

On Thursday, April 25, 2019 at 11:47:21 AM UTC-4, Rob 'Commander' Pike 
wrote:
>
> I am pretty sure that the decision not to have ?: in Go was a unanimous 
> decision by Robert, Ken and myself after almost no discussion. It is too 
> easy to abuse, as the FAQ states.
>
> -rob
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread Mark Volkmann
There are many counter-examples. What is the likelihood that someone who is
not familiar with the "?" operator will be familiar with the operators for
getting (*) and dereferencing (&) a pointer. And what is "<-"? Certainly
people not familiar with Go will initially be confused by operators related
to channels.

If you allow people to use pointers, will they use pointers to pointers to
pointers to pointers?

On Thu, Apr 25, 2019 at 9:19 AM Sam Whited  wrote:

> On Wed, Apr 24, 2019, at 14:08, Mark Volkmann wrote:
> > Are there really developers that find this unreadable?
> >
> > color := temperature > 80 ? “red” : “green”
>
> Yes.
>
> What is "?"? If I've never seen that before I have no easy way to search
> for that, and a random symbol me nothing about what it does. Go
> specifically tries to stick to keywords because even if you've never
> seen them before it's generally easier to figure out what they do (or to
> search for them if you're not sure).
>
> Not to mention that even if you do know what they do, that specific
> statement isn't the problem. If you allow people to do that, they'll end
> up trying to nest it 5 levels deep. Go tries not to give people the
> tools to shoot themselves in the foot for some tiny perceived advantage.
>
> —Sam
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
R. Mark Volkmann
Object Computing, Inc.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread Rob Pike
I am pretty sure that the decision not to have ?: in Go was a unanimous
decision by Robert, Ken and myself after almost no discussion. It is too
easy to abuse, as the FAQ states.

-rob

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread ugorji
FYI I recently posted a proposal for some unambiguous syntax which would 
give a lot of the value of ternary operators i.e. write the 5 line if-else 
block in the FAQ as a 1-liner, without the drawbacks, while IMO preserving 
the simplicity of the go language in approachability, readability and 
orthogonality.

Please review http://golang.org/issue/31659 and share your thoughts. 

On Wednesday, April 24, 2019 at 8:05:07 AM UTC-4, Mark Volkmann wrote:
>
>
> > On Apr 24, 2019, at 6:22 AM, Robert Engels  > wrote: 
> > 
> > Though to the ops point, not sure why Go doesn’t have the ternary 
> operator - which is pretty ubiquitous. 
>
> The idea of adding the ternary operator to Go has been debated many times. 
> It’s clear that those in charge have a strong dislike for it. For me the 
> lack of the ternary operator is one of main things I dislike about Go. It’s 
> nails on a chalkboard for me to write a five line “if” statement when it 
> could have been a one line assignment statement. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread Sam Whited
On Wed, Apr 24, 2019, at 14:08, Mark Volkmann wrote:
> Are there really developers that find this unreadable?
>
> color := temperature > 80 ? “red” : “green”

Yes.

What is "?"? If I've never seen that before I have no easy way to search
for that, and a random symbol me nothing about what it does. Go
specifically tries to stick to keywords because even if you've never
seen them before it's generally easier to figure out what they do (or to
search for them if you're not sure).

Not to mention that even if you do know what they do, that specific
statement isn't the problem. If you allow people to do that, they'll end
up trying to nest it 5 levels deep. Go tries not to give people the
tools to shoot themselves in the foot for some tiny perceived advantage.

—Sam

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread Andrew Klager
>
> > Is this so bad?
>
> Yes, it's horrible as you'll loose any type information you had.
> Meaning the next thing you naturally had to do was type cast it, which
> isn't the nicest syntax to begin with.
> By then it's probably more work than just using if / else
>

So what you're saying is that Go needs a ternary operator and generics? ;)
But yeah, for assignment, you'd need a type specific operator, or you end
up with an if else (or at least an if) to do a type assertion, which
defeats the purpose... or just use if / else, agreed.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread Robert Engels
Go vet doesn’t report on structural issues - and those are far harder to work 
with/debug than code with the proper use of ternary operators (or even poor use)
Bad code is bad code no matter how you get there. 

On Apr 25, 2019, at 7:05 AM, Lucio  wrote:

>> 
>> But don't deny others the ability to choose the first alternative
>  
> That's not what's being denied: what is being denied, is the ability to write 
> nested ternaries I then have to debug. Fat lot of good it will do me, that  
> vet reports it to be a misuse.
> 
> Lucio. 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread Lucio

>
>
> But don't deny others the ability to choose the first alternative
>
 
That's not what's being denied: what is being denied, is the ability to 
write nested ternaries I then have to debug. Fat lot of good it will do me, 
that  vet reports it to be a misuse.

Lucio. 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Reto
On Wed, Apr 24, 2019 at 04:24:41PM -0500, Andrew Klager wrote:
> Is this so bad?

Yes, it's horrible as you'll loose any type information you had.
Meaning the next thing you naturally had to do was type cast it, which isn't 
the nicest syntax to begin with.
By then it's probably more work than just using if / else

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread andrey mirtchovski
Please do! We need to resolve this connundrum for the next 5
generations of computer programmers!

On Wed, Apr 24, 2019 at 8:41 PM David Riley  wrote:
>
> On Apr 24, 2019, at 5:25 PM, andrey mirtchovski  wrote:
> >
> >> I may easily misremember, but that doesn't match my recollection.  I
> >> don't remember what position Rob and Robert took, but as I recall Ken
> >> was generally opposed to the ternary operator.  He had been in part
> >> responsible for adding it to C, and felt that it had been a mistake.
> >>
> >> Ian
> >
> > I am happy to stand corrected. I believe it was an offhand comment by
> > either Rob or Russ in one of the early Go talks. Unfortunately hard to
> > find 10 years later, especially in non-transcribed videos.
>
> Well, Ken is giving the keynote at the Vintage Computer Festival East this 
> year, maybe I can ask him then. :-)
>
>
> - Dave
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread David Riley
On Apr 24, 2019, at 5:25 PM, andrey mirtchovski  wrote:
> 
>> I may easily misremember, but that doesn't match my recollection.  I
>> don't remember what position Rob and Robert took, but as I recall Ken
>> was generally opposed to the ternary operator.  He had been in part
>> responsible for adding it to C, and felt that it had been a mistake.
>> 
>> Ian
> 
> I am happy to stand corrected. I believe it was an offhand comment by
> either Rob or Russ in one of the early Go talks. Unfortunately hard to
> find 10 years later, especially in non-transcribed videos.

Well, Ken is giving the keynote at the Vintage Computer Festival East this 
year, maybe I can ask him then. :-)


- Dave


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Mark Volkmann
Nested ternaries are fairly readable in JavaScript these days due to the
use of Prettier for code formatting.
gofmt could do the same.
For example, this:

lc_unicodeliterals = quote=='u' ? 1 : quote=='U' ? 0 : !!(ast.locale.set &
AST_LC_unicodeliterals);

could be formatted to this:

lc_unicodeliterals =
  quote == 'u' ? 1 :
  quote == 'U' ? 0 :
  !!(ast.locale.set & AST_LC_unicodeliterals);

On Wed, Apr 24, 2019 at 4:02 PM Kurtis Rader  wrote:

> On Wed, Apr 24, 2019 at 1:14 PM andrey mirtchovski 
> wrote:
>
>> Here's the lore associated with the subject: Ken wanted ternary, Rob
>> and Robert did not. They overruled Ken (remember, early on all three
>> had to agree for a feature to go in). The end.
>>
>> The number of frivolous and egregious abuse of ternary that I've seen
>> in _modern_ C code is too high.jpg
>>
>
> +100 to that sentiment. While the brevity of a ternary expression
> is  useful for trivial cases it tends to be abused. For your
> amusement/horror here are just a few, of a couple hundred, examples of
> ternary being abused in the AT AST (which includes ksh) source:
>
>
> https://github.com/att/ast/blob/e770c77e9816e156c6df4a455e71b5f9fff79310/src/cmd/ksh93/edit/hexpand.c#L447
>
>
> https://github.com/att/ast/blob/e770c77e9816e156c6df4a455e71b5f9fff79310/src/cmd/ksh93/sh/string.c#L344-L346
>
>
> https://github.com/att/ast/blob/8504cd407846d192881a94d507333697f016a85a/src/lib/libast/include/sfio.h#L359-L360
>
>
> https://github.com/att/ast/blob/8504cd407846d192881a94d507333697f016a85a/src/lib/libast/include/cdt.h#L313-L316
>
>
> https://github.com/att/ast/blob/e770c77e9816e156c6df4a455e71b5f9fff79310/src/lib/libz/deflate.c#L597-L609
>
> For those who don't want to follow those links this is the code from the
> first URL above:
>
> lc_unicodeliterals = quote=='u' ? 1 : quote=='U' ? 0 : !!(ast.locale.set &
> AST_LC_unicodeliterals);
>
> --
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>


-- 
R. Mark Volkmann
Object Computing, Inc.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread lgodio2
For me, choosing to write

color = temp < 80 ? { "blue", "red") 

 vs 
func ternary(cond bool, pos, neg interface{}) interface{} {
if cond {
return pos
} else {
return neg
}
}
color := ternary( temp < 80, "blue", "red")

is a no brainer


On Wednesday, April 24, 2019 at 5:25:09 PM UTC-4, Andrew Klager wrote:
>
> Is this so bad?
>
> func ternary(cond bool, pos, neg interface{}) interface{} {
> if cond {
> return pos
> } else {
> return neg
> }
> }
>
> color := ternary( temp < 80, "blue", "red")
>
>
>
> On Wed, Apr 24, 2019 at 4:14 PM Chris Broadfoot <
> ch...@chrisbroadfoot.id.au > wrote:
>
>>
>>
>> On Wed, Apr 24, 2019 at 4:22 AM Robert Engels > > wrote:
>>
>>> Though to the ops point, not sure why Go doesn’t have the ternary 
>>> operator - which is pretty ubiquitous. 
>>>
>>
>> https://golang.org/doc/faq#Does_Go_have_a_ternary_form
>>  
>>
>>>
>>> On Apr 23, 2019, at 9:56 PM, Robert Engels >> > wrote:
>>>
>>> Why? You have saved 5 characters for no practical gain. I think you 
>>> would enjoy Ada. 
>>>
>>> On Apr 23, 2019, at 8:05 PM, lgo...@gmail.com  wrote:
>>>
>>> It sure would be nice if Go syntax allowed programmers to replace 
>>>
>>> if ( test) {
>>> ...do sonething
>>> } else {
>>> ..do something else
>>> }
>>>
>>> with 
>>>
>>> ? (test) {
>>> //...do something
>>> }
>>> {
>>> //..do something else
>>> }
>>>
>>> The ? operator can be anything the Go language team considers appropriate
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to golan...@googlegroups.com .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to golan...@googlegroups.com .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golan...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread lgodio2
If instead of writing:  temperature > 80 ? red : green
you choose to follow Marcus and write instead:
map[bool]string{true:"red",false:"green"}[temperature>80]

OR call 

func ternary(x int) int {
return map[bool]int{true:12345,false:-1}[x>0]
}

Go right ahead ! ..as they say,  "different strokes for different folks" 

But don't deny others the ability to choose the first alternative

On Wednesday, April 24, 2019 at 12:34:09 PM UTC-4, Marcus Low wrote:
>
> color := map[bool]string{true:"red",false:"green"}[temperature>80]
> Here you go.
>
> On Wednesday, April 24, 2019 at 10:08:53 PM UTC+8, Mark Volkmann wrote:
>>
>> Are there really developers that find this unreadable? 
>>
>> color := temperature > 80 ? “red” : “green” 
>>
>> I know what you are going to say. People will nest them. But even nested 
>> usage can be readable when formatted nicely with one condition per line. 
>> Another alternative is to allow only unnested ternaries. 
>>
>> R. Mark Volkmann 
>> Object Computing, Inc. 
>>
>> > On Apr 24, 2019, at 8:58 AM, Jan Mercl <0xj...@gmail.com> wrote: 
>> > 
>> >> On Wed, Apr 24, 2019 at 3:48 PM L Godioleskky  
>> wrote: 
>> >> 
>> >> The lack of a Go ternary operator is at odds with Go's major theme of 
>> clean and easy to read syntax. Those who choose not to use the ternary 
>> operator can always resort back to Go's current 'if -else' or 'case' 
>> syntax. So Go syntax suffers no negative impact by adding the ternary op to 
>> its syntax list.  Those opposed to the ternary op should not be allowed to 
>> deny it use other Go programmers, that consider it useful. 
>> > 
>> > That's backwards. Those who has to read the code can no more chose not 
>> > to decrypt the unreadable 4-level nested ternary operations instead of 
>> > 5 if statements. 
>> > 
>> > And to follow on your "logic". If you add to Go even just 10% of what 
>> > people consider useful, it will become a new C++, only much worse. And 
>> > again by your very logic. Why we, that haven't chosen to code in C++ 
>> > in the first place, would be denied by others to use Go, when those 
>> > others have C++ already at hand? 
>> > 
>> > Let everyone use the language he/she likes. Why ruin it for others 
>> > instead of that by forcing Go to become the same as his/her other 
>> > favorite language? 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread andrey mirtchovski
> I may easily misremember, but that doesn't match my recollection.  I
> don't remember what position Rob and Robert took, but as I recall Ken
> was generally opposed to the ternary operator.  He had been in part
> responsible for adding it to C, and felt that it had been a mistake.
>
> Ian

I am happy to stand corrected. I believe it was an offhand comment by
either Rob or Russ in one of the early Go talks. Unfortunately hard to
find 10 years later, especially in non-transcribed videos.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Andrew Klager
Is this so bad?

func ternary(cond bool, pos, neg interface{}) interface{} {
if cond {
return pos
} else {
return neg
}
}

color := ternary( temp < 80, "blue", "red")



On Wed, Apr 24, 2019 at 4:14 PM Chris Broadfoot 
wrote:

>
>
> On Wed, Apr 24, 2019 at 4:22 AM Robert Engels 
> wrote:
>
>> Though to the ops point, not sure why Go doesn’t have the ternary
>> operator - which is pretty ubiquitous.
>>
>
> https://golang.org/doc/faq#Does_Go_have_a_ternary_form
>
>
>>
>> On Apr 23, 2019, at 9:56 PM, Robert Engels  wrote:
>>
>> Why? You have saved 5 characters for no practical gain. I think you would
>> enjoy Ada.
>>
>> On Apr 23, 2019, at 8:05 PM, lgod...@gmail.com wrote:
>>
>> It sure would be nice if Go syntax allowed programmers to replace
>>
>> if ( test) {
>> ...do sonething
>> } else {
>> ..do something else
>> }
>>
>> with
>>
>> ? (test) {
>> //...do something
>> }
>> {
>> //..do something else
>> }
>>
>> The ? operator can be anything the Go language team considers appropriate
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Chris Broadfoot
On Wed, Apr 24, 2019 at 4:22 AM Robert Engels  wrote:

> Though to the ops point, not sure why Go doesn’t have the ternary operator
> - which is pretty ubiquitous.
>

https://golang.org/doc/faq#Does_Go_have_a_ternary_form


>
> On Apr 23, 2019, at 9:56 PM, Robert Engels  wrote:
>
> Why? You have saved 5 characters for no practical gain. I think you would
> enjoy Ada.
>
> On Apr 23, 2019, at 8:05 PM, lgod...@gmail.com wrote:
>
> It sure would be nice if Go syntax allowed programmers to replace
>
> if ( test) {
> ...do sonething
> } else {
> ..do something else
> }
>
> with
>
> ? (test) {
> //...do something
> }
> {
> //..do something else
> }
>
> The ? operator can be anything the Go language team considers appropriate
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread David Riley
On Apr 24, 2019, at 12:34 PM, Marcus Low  wrote:
> 
> On Wednesday, April 24, 2019 at 10:08:53 PM UTC+8, Mark Volkmann wrote:
>> Are there really developers that find this unreadable? 
>> 
>> color := temperature > 80 ? “red” : “green” 
>> 
>> I know what you are going to say. People will nest them. But even nested 
>> usage can be readable when formatted nicely with one condition per line. 
>> Another alternative is to allow only unnested ternaries. 
>> 

> color := map[bool]string{true:"red",false:"green"}[temperature>80]
> Here you go.

Pardon my bluntness, but it is silly to assert that this is anywhere near the 
readability of the ternary statement.  The entire point of the ternary 
statement is that it is concise and spartan; this is cluttered and overwrought.

Yes, people can (and will) abuse it.  That doesn't seem to have stopped us from 
having a reflection library, which is arguably much worse for readability and 
more pernicious compared to ternary statement abuse.

There are very few cases where you can force good coding hygiene by removing 
language features.  This isn't one of them.  If you wanted to force good coding 
style, put a check for nested ternaries in go vet along with other readability 
issues.


- Dave

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread David Riley
On Apr 24, 2019, at 8:04 AM, Mark Volkmann  wrote:
> 
> 
>> On Apr 24, 2019, at 6:22 AM, Robert Engels  wrote:
>> 
>> Though to the ops point, not sure why Go doesn’t have the ternary operator - 
>> which is pretty ubiquitous. 
> 
> The idea of adding the ternary operator to Go has been debated many times. 
> It’s clear that those in charge have a strong dislike for it. For me the lack 
> of the ternary operator is one of main things I dislike about Go. It’s nails 
> on a chalkboard for me to write a five line “if” statement when it could have 
> been a one line assignment statement.

I enthusiastically concur with this.  I understand the antagonism toward the 
ternary statement to a point, but there are some things that it just makes 
about a million times easier without sacrificing readability:



fmt.Printf("This parrot is %s.\n", is_dead ? "pining for the fjords" : "alive")



This isn't just a toy example.  Nothing (to my mind) is unclear about this 
statement.

I run into this sort of thing every day; the main thing the ternary statement 
relieves me of is either writing convoluted if/switch/map statements when a 
single line would do, or repeating myself. I'd have to do one or the other to 
resolve the above one-liner, and it wouldn't enhance readability in the 
slightest.


- Dave

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Ian Lance Taylor
On Wed, Apr 24, 2019 at 1:14 PM andrey mirtchovski
 wrote:
>
> Here's the lore associated with the subject: Ken wanted ternary, Rob
> and Robert did not. They overruled Ken (remember, early on all three
> had to agree for a feature to go in). The end.

I may easily misremember, but that doesn't match my recollection.  I
don't remember what position Rob and Robert took, but as I recall Ken
was generally opposed to the ternary operator.  He had been in part
responsible for adding it to C, and felt that it had been a mistake.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Kurtis Rader
On Wed, Apr 24, 2019 at 1:14 PM andrey mirtchovski 
wrote:

> Here's the lore associated with the subject: Ken wanted ternary, Rob
> and Robert did not. They overruled Ken (remember, early on all three
> had to agree for a feature to go in). The end.
>
> The number of frivolous and egregious abuse of ternary that I've seen
> in _modern_ C code is too high.jpg
>

+100 to that sentiment. While the brevity of a ternary expression
is  useful for trivial cases it tends to be abused. For your
amusement/horror here are just a few, of a couple hundred, examples of
ternary being abused in the AT AST (which includes ksh) source:

https://github.com/att/ast/blob/e770c77e9816e156c6df4a455e71b5f9fff79310/src/cmd/ksh93/edit/hexpand.c#L447

https://github.com/att/ast/blob/e770c77e9816e156c6df4a455e71b5f9fff79310/src/cmd/ksh93/sh/string.c#L344-L346

https://github.com/att/ast/blob/8504cd407846d192881a94d507333697f016a85a/src/lib/libast/include/sfio.h#L359-L360

https://github.com/att/ast/blob/8504cd407846d192881a94d507333697f016a85a/src/lib/libast/include/cdt.h#L313-L316

https://github.com/att/ast/blob/e770c77e9816e156c6df4a455e71b5f9fff79310/src/lib/libz/deflate.c#L597-L609

For those who don't want to follow those links this is the code from the
first URL above:

lc_unicodeliterals = quote=='u' ? 1 : quote=='U' ? 0 : !!(ast.locale.set &
AST_LC_unicodeliterals);

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread andrey mirtchovski
Here's the lore associated with the subject: Ken wanted ternary, Rob
and Robert did not. They overruled Ken (remember, early on all three
had to agree for a feature to go in). The end.

The number of frivolous and egregious abuse of ternary that I've seen
in _modern_ C code is too high.jpg

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Robert Engels
I agree, and I think the ternary represents the logic much cleaner than if/else 
in this case. This would be especially true if you could do:

final datalen := value==nil ? removedKeyken : len(value)

> On Apr 24, 2019, at 1:18 PM, Mark Volkmann  wrote:
> 
> I'm at a loss as to how that could be considered more readable that a single 
> ternary.
> You've successfully changed five lines to four lines, but that's still a long 
> way from one line.
> 
>> On Wed, Apr 24, 2019 at 12:15 PM Marcus Low  wrote:
>> Yeah of course I was joking... the solution I provided does work for the "I 
>> need a one-liner" mentality, though. 
>> 
>> I believe this following solution fits your use case, and is simpler to read 
>> too:
>> 
>> datalen := removedKeyken // removedKeyken must have been int32 in your 
>> example.
>> if value != nil {
>>datalen = len(value)
>> }
>> 
>> 
>> 
>>> On Thu, Apr 25, 2019 at 1:05 AM Robert Engels  wrote:
>>> I’m pretty sure you’re joking... but I think most are referring to simple 
>>> usages, like this (from my own code). Clearly, there are others was of 
>>> designing it to avoid the usage, but sometimes what is simple really is 
>>> simpler. 
>>> 
>>> var datalen int32
>>> if value == nil {
>>>datalen = removedKeyken 
>>> } else {
>>>datalen = len(value)
>>> }
>>> 
>>> 
>>> 
 On Apr 24, 2019, at 11:31 AM, Marcus Low  wrote:
 
 I personally do not find ternary operators to be readable in any form.
 For those who are truly desperate for that cosmetic one-line kick, though, 
 here's an example you can use (which looks just about as unreadable as any 
 ternary operator out there):
 
 // ternary returns 12345 if x is positive (x > 0).
 // It returns -1 otherwise.
 func ternary(x int) int {
 return map[bool]int{true:12345,false:-1}[x>0]
 }
 
 
 
> On Thursday, April 25, 2019 at 12:20:35 AM UTC+8, Robert Engels wrote:
> Yes, but the FAQ has similar concerns about readability and 
> maintainability as reasons for not having generics, but adds the language 
> “may change”... not sure that is consistent with the views on the tenant 
> operator. 
> 
> > On Apr 24, 2019, at 9:52 AM, Ian Lance Taylor  wrote: 
> > 
> > The lack of the ?: operator in Go is a FAQ: 
> > https://golang.org/doc/faq#Does_Go_have_a_ternary_form . 
> > 
> > Ian 
> 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 "golang-nuts" group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to golang-nuts+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
> 
> 
> -- 
> R. Mark Volkmann
> Object Computing, Inc.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Mark Volkmann
I'm at a loss as to how that could be considered more readable that a
single ternary.
You've successfully changed five lines to four lines, but that's still a
long way from one line.

On Wed, Apr 24, 2019 at 12:15 PM Marcus Low  wrote:

> Yeah of course I was joking... the solution I provided does work for the
> "I need a one-liner" mentality, though.
>
> I believe this following solution fits your use case, and is simpler to
> read too:
>
> datalen := removedKeyken // removedKeyken must have been int32 in your
> example.
> if value != nil {
>datalen = len(value)
> }
>
>
>
> On Thu, Apr 25, 2019 at 1:05 AM Robert Engels 
> wrote:
>
>> I’m pretty sure you’re joking... but I think most are referring to simple
>> usages, like this (from my own code). Clearly, there are others was of
>> designing it to avoid the usage, but sometimes what is simple really is
>> simpler.
>>
>> var datalen int32
>> if value == nil {
>>datalen = removedKeyken
>> } else {
>>datalen = len(value)
>> }
>>
>>
>>
>> On Apr 24, 2019, at 11:31 AM, Marcus Low  wrote:
>>
>> I personally do not find ternary operators to be readable in any form.
>> For those who are truly desperate for that cosmetic one-line kick,
>> though, here's an example you can use (which looks just about as unreadable
>> as any ternary operator out there):
>>
>> // ternary returns 12345 if x is positive (x > 0).
>> // It returns -1 otherwise.
>> func ternary(x int) int {
>> return map[bool]int{true:12345,false:-1}[x>0]
>> }
>>
>>
>>
>> On Thursday, April 25, 2019 at 12:20:35 AM UTC+8, Robert Engels wrote:
>>>
>>> Yes, but the FAQ has similar concerns about readability and
>>> maintainability as reasons for not having generics, but adds the language
>>> “may change”... not sure that is consistent with the views on the tenant
>>> operator.
>>>
>>> > On Apr 24, 2019, at 9:52 AM, Ian Lance Taylor 
>>> wrote:
>>> >
>>> > The lack of the ?: operator in Go is a FAQ:
>>> > https://golang.org/doc/faq#Does_Go_have_a_ternary_form .
>>> >
>>> > Ian
>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
R. Mark Volkmann
Object Computing, Inc.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Marcus Low
Yeah of course I was joking... the solution I provided does work for the "I
need a one-liner" mentality, though.

I believe this following solution fits your use case, and is simpler to
read too:

datalen := removedKeyken // removedKeyken must have been int32 in your
example.
if value != nil {
   datalen = len(value)
}



On Thu, Apr 25, 2019 at 1:05 AM Robert Engels  wrote:

> I’m pretty sure you’re joking... but I think most are referring to simple
> usages, like this (from my own code). Clearly, there are others was of
> designing it to avoid the usage, but sometimes what is simple really is
> simpler.
>
> var datalen int32
> if value == nil {
>datalen = removedKeyken
> } else {
>datalen = len(value)
> }
>
>
>
> On Apr 24, 2019, at 11:31 AM, Marcus Low  wrote:
>
> I personally do not find ternary operators to be readable in any form.
> For those who are truly desperate for that cosmetic one-line kick, though,
> here's an example you can use (which looks just about as unreadable as any
> ternary operator out there):
>
> // ternary returns 12345 if x is positive (x > 0).
> // It returns -1 otherwise.
> func ternary(x int) int {
> return map[bool]int{true:12345,false:-1}[x>0]
> }
>
>
>
> On Thursday, April 25, 2019 at 12:20:35 AM UTC+8, Robert Engels wrote:
>>
>> Yes, but the FAQ has similar concerns about readability and
>> maintainability as reasons for not having generics, but adds the language
>> “may change”... not sure that is consistent with the views on the tenant
>> operator.
>>
>> > On Apr 24, 2019, at 9:52 AM, Ian Lance Taylor 
>> wrote:
>> >
>> > The lack of the ?: operator in Go is a FAQ:
>> > https://golang.org/doc/faq#Does_Go_have_a_ternary_form .
>> >
>> > Ian
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Robert Engels
I’m pretty sure you’re joking... but I think most are referring to simple 
usages, like this (from my own code). Clearly, there are others was of 
designing it to avoid the usage, but sometimes what is simple really is 
simpler. 

var datalen int32
if value == nil {
   datalen = removedKeyken 
} else {
   datalen = len(value)
}



> On Apr 24, 2019, at 11:31 AM, Marcus Low  wrote:
> 
> I personally do not find ternary operators to be readable in any form.
> For those who are truly desperate for that cosmetic one-line kick, though, 
> here's an example you can use (which looks just about as unreadable as any 
> ternary operator out there):
> 
> // ternary returns 12345 if x is positive (x > 0).
> // It returns -1 otherwise.
> func ternary(x int) int {
> return map[bool]int{true:12345,false:-1}[x>0]
> }
> 
> 
> 
>> On Thursday, April 25, 2019 at 12:20:35 AM UTC+8, Robert Engels wrote:
>> Yes, but the FAQ has similar concerns about readability and maintainability 
>> as reasons for not having generics, but adds the language “may change”... 
>> not sure that is consistent with the views on the tenant operator. 
>> 
>> > On Apr 24, 2019, at 9:52 AM, Ian Lance Taylor  wrote: 
>> > 
>> > The lack of the ?: operator in Go is a FAQ: 
>> > https://golang.org/doc/faq#Does_Go_have_a_ternary_form . 
>> > 
>> > Ian 
>> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Marcus Low
color := map[bool]string{true:"red",false:"green"}[temperature>80]
Here you go.

On Wednesday, April 24, 2019 at 10:08:53 PM UTC+8, Mark Volkmann wrote:
>
> Are there really developers that find this unreadable? 
>
> color := temperature > 80 ? “red” : “green” 
>
> I know what you are going to say. People will nest them. But even nested 
> usage can be readable when formatted nicely with one condition per line. 
> Another alternative is to allow only unnested ternaries. 
>
> R. Mark Volkmann 
> Object Computing, Inc. 
>
> > On Apr 24, 2019, at 8:58 AM, Jan Mercl <0xj...@gmail.com > 
> wrote: 
> > 
> >> On Wed, Apr 24, 2019 at 3:48 PM L Godioleskky  > wrote: 
> >> 
> >> The lack of a Go ternary operator is at odds with Go's major theme of 
> clean and easy to read syntax. Those who choose not to use the ternary 
> operator can always resort back to Go's current 'if -else' or 'case' 
> syntax. So Go syntax suffers no negative impact by adding the ternary op to 
> its syntax list.  Those opposed to the ternary op should not be allowed to 
> deny it use other Go programmers, that consider it useful. 
> > 
> > That's backwards. Those who has to read the code can no more chose not 
> > to decrypt the unreadable 4-level nested ternary operations instead of 
> > 5 if statements. 
> > 
> > And to follow on your "logic". If you add to Go even just 10% of what 
> > people consider useful, it will become a new C++, only much worse. And 
> > again by your very logic. Why we, that haven't chosen to code in C++ 
> > in the first place, would be denied by others to use Go, when those 
> > others have C++ already at hand? 
> > 
> > Let everyone use the language he/she likes. Why ruin it for others 
> > instead of that by forcing Go to become the same as his/her other 
> > favorite language? 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Marcus Low
I personally do not find ternary operators to be readable in any form.
For those who are truly desperate for that cosmetic one-line kick, though, 
here's an example you can use (which looks just about as unreadable as any 
ternary operator out there):

// ternary returns 12345 if x is positive (x > 0).
// It returns -1 otherwise.
func ternary(x int) int {
return map[bool]int{true:12345,false:-1}[x>0]
}



On Thursday, April 25, 2019 at 12:20:35 AM UTC+8, Robert Engels wrote:
>
> Yes, but the FAQ has similar concerns about readability and 
> maintainability as reasons for not having generics, but adds the language 
> “may change”... not sure that is consistent with the views on the tenant 
> operator. 
>
> > On Apr 24, 2019, at 9:52 AM, Ian Lance Taylor  > wrote: 
> > 
> > The lack of the ?: operator in Go is a FAQ: 
> > https://golang.org/doc/faq#Does_Go_have_a_ternary_form . 
> > 
> > Ian 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Robert Engels
Yes, but the FAQ has similar concerns about readability and maintainability as 
reasons for not having generics, but adds the language “may change”... not sure 
that is consistent with the views on the tenant operator. 

> On Apr 24, 2019, at 9:52 AM, Ian Lance Taylor  wrote:
> 
> The lack of the ?: operator in Go is a FAQ:
> https://golang.org/doc/faq#Does_Go_have_a_ternary_form .
> 
> Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Ian Lance Taylor
The lack of the ?: operator in Go is a FAQ:
https://golang.org/doc/faq#Does_Go_have_a_ternary_form .

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Mark Volkmann
Are there really developers that find this unreadable?

color := temperature > 80 ? “red” : “green”

I know what you are going to say. People will nest them. But even nested usage 
can be readable when formatted nicely with one condition per line. Another 
alternative is to allow only unnested ternaries. 

R. Mark Volkmann
Object Computing, Inc.

> On Apr 24, 2019, at 8:58 AM, Jan Mercl <0xj...@gmail.com> wrote:
> 
>> On Wed, Apr 24, 2019 at 3:48 PM L Godioleskky  wrote:
>> 
>> The lack of a Go ternary operator is at odds with Go's major theme of clean 
>> and easy to read syntax. Those who choose not to use the ternary operator 
>> can always resort back to Go's current 'if -else' or 'case' syntax. So Go 
>> syntax suffers no negative impact by adding the ternary op to its syntax 
>> list.  Those opposed to the ternary op should not be allowed to deny it use 
>> other Go programmers, that consider it useful.
> 
> That's backwards. Those who has to read the code can no more chose not
> to decrypt the unreadable 4-level nested ternary operations instead of
> 5 if statements.
> 
> And to follow on your "logic". If you add to Go even just 10% of what
> people consider useful, it will become a new C++, only much worse. And
> again by your very logic. Why we, that haven't chosen to code in C++
> in the first place, would be denied by others to use Go, when those
> others have C++ already at hand?
> 
> Let everyone use the language he/she likes. Why ruin it for others
> instead of that by forcing Go to become the same as his/her other
> favorite language?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Jan Mercl
On Wed, Apr 24, 2019 at 3:48 PM L Godioleskky  wrote:
>
> The lack of a Go ternary operator is at odds with Go's major theme of clean 
> and easy to read syntax. Those who choose not to use the ternary operator can 
> always resort back to Go's current 'if -else' or 'case' syntax. So Go syntax 
> suffers no negative impact by adding the ternary op to its syntax list.  
> Those opposed to the ternary op should not be allowed to deny it use other Go 
> programmers, that consider it useful.

That's backwards. Those who has to read the code can no more chose not
to decrypt the unreadable 4-level nested ternary operations instead of
5 if statements.

And to follow on your "logic". If you add to Go even just 10% of what
people consider useful, it will become a new C++, only much worse. And
again by your very logic. Why we, that haven't chosen to code in C++
in the first place, would be denied by others to use Go, when those
others have C++ already at hand?

Let everyone use the language he/she likes. Why ruin it for others
instead of that by forcing Go to become the same as his/her other
favorite language?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread L Godioleskky
The lack of a Go ternary operator is at odds with Go's major theme of clean
and easy to read syntax. Those who choose not to use the ternary operator
can always resort back to Go's current 'if -else' or 'case' syntax. So Go
syntax suffers no negative impact by adding the ternary op to its syntax
list.  Those opposed to the ternary op should not be allowed to deny it use
other Go programmers, that consider it useful.


On Wed, Apr 24, 2019 at 8:31 AM Robert Engels  wrote:

> That’s not what he meant. It takes 5 lines for a trivial assignment
> if/else rather than 1 line with a ternary with no loss in readability.
>
> > On Apr 24, 2019, at 7:11 AM, Jan Mercl <0xj...@gmail.com> wrote:
> >
> >> On Wed, Apr 24, 2019 at 2:04 PM Mark Volkmann <
> r.mark.volkm...@gmail.com> wrote:
> >>
> >> The idea of adding the ternary operator to Go has been debated many
> times. It’s clear that those in charge have a strong dislike for it. For me
> the lack of the ternary operator is one of main things I dislike about Go.
> It’s nails on a chalkboard for me to write a five line “if” statement when
> it could have been a one line assignment statement.
> >
> > That's a nice example why Go does not have the ternary operator.
> > Fitting five if statements into one line makes the code probably
> > unreadable just for the imaginary gain of saving some vertical screen
> > space.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Robert Engels
That’s not what he meant. It takes 5 lines for a trivial assignment if/else 
rather than 1 line with a ternary with no loss in readability. 

> On Apr 24, 2019, at 7:11 AM, Jan Mercl <0xj...@gmail.com> wrote:
> 
>> On Wed, Apr 24, 2019 at 2:04 PM Mark Volkmann  
>> wrote:
>> 
>> The idea of adding the ternary operator to Go has been debated many times. 
>> It’s clear that those in charge have a strong dislike for it. For me the 
>> lack of the ternary operator is one of main things I dislike about Go. It’s 
>> nails on a chalkboard for me to write a five line “if” statement when it 
>> could have been a one line assignment statement.
> 
> That's a nice example why Go does not have the ternary operator.
> Fitting five if statements into one line makes the code probably
> unreadable just for the imaginary gain of saving some vertical screen
> space.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Jan Mercl
On Wed, Apr 24, 2019 at 2:04 PM Mark Volkmann  wrote:

> The idea of adding the ternary operator to Go has been debated many times. 
> It’s clear that those in charge have a strong dislike for it. For me the lack 
> of the ternary operator is one of main things I dislike about Go. It’s nails 
> on a chalkboard for me to write a five line “if” statement when it could have 
> been a one line assignment statement.

That's a nice example why Go does not have the ternary operator.
Fitting five if statements into one line makes the code probably
unreadable just for the imaginary gain of saving some vertical screen
space.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Mark Volkmann


> On Apr 24, 2019, at 6:22 AM, Robert Engels  wrote:
> 
> Though to the ops point, not sure why Go doesn’t have the ternary operator - 
> which is pretty ubiquitous. 

The idea of adding the ternary operator to Go has been debated many times. It’s 
clear that those in charge have a strong dislike for it. For me the lack of the 
ternary operator is one of main things I dislike about Go. It’s nails on a 
chalkboard for me to write a five line “if” statement when it could have been a 
one line assignment statement.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Robert Engels
Though to the ops point, not sure why Go doesn’t have the ternary operator - 
which is pretty ubiquitous. 

> On Apr 23, 2019, at 9:56 PM, Robert Engels  wrote:
> 
> Why? You have saved 5 characters for no practical gain. I think you would 
> enjoy Ada. 
> 
>> On Apr 23, 2019, at 8:05 PM, lgod...@gmail.com wrote:
>> 
>> It sure would be nice if Go syntax allowed programmers to replace 
>> 
>> if ( test) {
>> ...do sonething
>> } else {
>> ..do something else
>> }
>> 
>> with 
>> 
>> ? (test) {
>> //...do something
>> }
>> {
>> //..do something else
>> }
>> 
>> The ? operator can be anything the Go language team considers appropriate
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Jan Mercl
On Wed, Apr 24, 2019 at 3:05 AM  wrote:
>
> It sure would be nice if Go syntax allowed programmers to replace
>
> if ( test) {
> ...do sonething
> }

That's not how Go's if statement looks. Gofmt will remove the
superficial parentheses around 'test'.

Wrt the rest of the proposal, today, this is valid code:

if test {
foo()
}
{
bar()
}

How would one write the it under the proposal?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-23 Thread Robert Engels
Why? You have saved 5 characters for no practical gain. I think you would enjoy 
Ada. 

> On Apr 23, 2019, at 8:05 PM, lgod...@gmail.com wrote:
> 
> It sure would be nice if Go syntax allowed programmers to replace 
> 
> if ( test) {
> ...do sonething
> } else {
> ..do something else
> }
> 
> with 
> 
> ? (test) {
> //...do something
> }
> {
> //..do something else
> }
> 
> The ? operator can be anything the Go language team considers appropriate
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-23 Thread andrey mirtchovski
> ? (test) {
> //...do something
> }
> {
> //..do something else
> }

I believe the Go team considered this very carefully early on the
language's development and came to the decision to use "if test" for
"? (test)" and "} else {" for "}{" (without the implied newline). They
also threw in "} else if test {" for good measure, which your example
does not cover.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Go if else syntax .. suggested replacement

2019-04-23 Thread lgodio2
It sure would be nice if Go syntax allowed programmers to replace 

if ( test) {
...do sonething
} else {
..do something else
}

with 

? (test) {
//...do something
}
{
//..do something else
}

The ? operator can be anything the Go language team considers appropriate

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.