[go-nuts] Re: built-in alternative to bcrypt?

2019-04-24 Thread Henry
Hello,

If you want to store passwords, then bcrypt 
, scrypt 
, and argon2 
 are commonly used. They are 
available in Go's extended library. 

SHA is a hashing algorithm but by itself is not meant for password storage. 
Unlike bcrypt, scrypt and argon2, SHA is designed to be fast. It is meant 
to be used in conjunction with other cryptographic primitives.

All those mentioned above are one way hashing algorithms. If you use any of 
them to 'protect' email addresses, you will not be able to recover those 
addresses. You need encryption and not hashing to protect those email 
addresses.

If you are not familiar with cryptographic primitives, you are better off 
using higher level cryptographic libraries such as NaCL 
. There are many things that 
may go wrong when building your own cryptographic solution. 

On Monday, April 22, 2019 at 5:14:48 PM UTC+7, whiteh...@googlemail.com 
wrote:
>
> I'm porting some code over to Go, and currently looking at some password 
> hashing.  I'm wondering if there is a 'standard library' alternative to 
> using bcrypt?
>
> I am concerned about the Go binary size, since I'm already at 15MB!  So 
> I'm trying to limit external dependencies as much as possible.  
>
> The data being stored is not critical or sensitive, just some email 
> address mainly.  
>
> From my research it sounds like 'golang.org/pkg/crypto/sha512/' might be 
> what I need, but I dont see any clear alternative for the following 
> functions below:  
>
> I'm still new to Go, so I'm wondering what would be the recommended 
> solution using the standard library please?
>
> Peter
>
>
> bcrypt.GenerateFromPassword
>
> bcrypt.CompareHashAndPassword
>

-- 
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] Re: Go if else syntax .. suggested replacement

2019-04-24 Thread Matt Harden
On Wed, Apr 24, 2019 at 8:42 PM David Koblas  wrote:

> IMHO I've wanted a switch expression, rather than a switch statement for a
> while.
>
I've wanted that too, but what we already have really isn't that bad.

> value := switch test {
>   case true => "red"
>   case false => "blue"
> }
>
> value := "blue"
if test {
  value = "red"
}

> value := switch item.(type) {
>   case int => item
>   case string => strconv.Atoi(item)
>   case time.Time => {
> ... something more involved ... returning an int
>   }
> }
>
> Note that the above won't work; you must have a default case as well, for
almost any switch expression.

value := 0
switch v := item.(type) {
  case int:
value = v
  case string:
value = strconv.Atoi(v)
  case time.Time:
...
}

> Sure, not as compact as ternary -- but far more powerful and useful.
> On 4/24/19 9:40 PM, Michael Jones wrote:
>
> switch test {
> case true:
>   //..code block for test=true
> case false:
>   //..code block for test=false
> }
>
> On Wed, Apr 24, 2019 at 4:42 PM Dan Kortschak  wrote:
>
>> How would you preclude it?
>>
>> On Wed, 2019-04-24 at 16:28 -0700, lgod...@gmail.com wrote:
>> > I am NOT in favor of allowing nested ternary operations
>>
>> --
>> 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. Jones michael.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.
>
> --
> 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] Re: Go if else syntax .. suggested replacement

2019-04-24 Thread David Koblas
IMHO I've wanted a switch expression, rather than a switch statement for 
a while.


value := switch test {
  case true => "red"
  case false => "blue"
}

or

value := switch item.(type) {
  case int => item
  case string => strconv.Atoi(item)
  case time.Time => {
    ... something more involved ... returning an int
  }
}

Sure, not as compact as ternary -- but far more powerful and useful.

On 4/24/19 9:40 PM, Michael Jones wrote:

switch test {
case true:
  //..code block for test=true
case false:
  //..code block for test=false
}

On Wed, Apr 24, 2019 at 4:42 PM Dan Kortschak > wrote:


How would you preclude it?

On Wed, 2019-04-24 at 16:28 -0700, lgod...@gmail.com
 wrote:
> I am NOT in favor of allowing nested ternary operations

-- 
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. Jones
michael.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.


--
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] Re: Go if else syntax .. suggested replacement

2019-04-24 Thread Robert Engels
Wow that was some bad typing + bad auto correct...

> On Apr 24, 2019, at 9:15 PM, Robert Engels  wrote:
> 
> Your original proposal did not have the colon and also implied the {} were 
> mandatory. And what stops the sane syntax from. Ring nested ?
> 
>> On Apr 24, 2019, at 6:28 PM, lgod...@gmail.com wrote:
>> 
>> Just to clarify :  My original proposal was to include as part  of Go the 
>> syntax
>> 
>> (test) ? {
>> { //..code block for test=true
>> } : {
>>   //..code block for test=false
>> } 
>> 
>> I am NOT in favor of allowing nested ternary operations
>> 
>> In addition, I also propose allowing un-nested '?' as an alternative 
>> assignment statement i.e.  var = (temp >80) ? "red": "blue"
>> 
>> Thus, any further discussion of this topic should not involve issues related 
>> to nested ternary operations 
>> 
>>> On Tuesday, April 23, 2019 at 9:05:31 PM UTC-4, 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 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] Re: Go if else syntax .. suggested replacement

2019-04-24 Thread Robert Engels
Your original proposal did not have the colon and also implied the {} were 
mandatory. And what stops the sane syntax from. Ring nested ?

> On Apr 24, 2019, at 6:28 PM, lgod...@gmail.com wrote:
> 
> Just to clarify :  My original proposal was to include as part  of Go the 
> syntax
> 
> (test) ? {
> { //..code block for test=true
> } : {
>   //..code block for test=false
> } 
> 
> I am NOT in favor of allowing nested ternary operations
> 
> In addition, I also propose allowing un-nested '?' as an alternative 
> assignment statement i.e.  var = (temp >80) ? "red": "blue"
> 
> Thus, any further discussion of this topic should not involve issues related 
> to nested ternary operations 
> 
>> On Tuesday, April 23, 2019 at 9:05:31 PM UTC-4, 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 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] Re: Go if else syntax .. suggested replacement

2019-04-24 Thread Dan Kortschak
I don't think that's an answer to my comment. Was it intended to be?

lgodio wrote that they wanted ternary operators, but were not
advocating that it be possible to allow nested ternary operations. I
don't see how this is possible if you write the grammar as the only
sensible interpretation

TernExpr = Expression "?" Expression ":" Expression .

Given that TernExpr would be an Expression.

The only way out of the natural possibility of having nested ternary
operator expressions would be a special case

TernExpr = NonTernExpr "?" NonTernExpr ":" NonTernExpr .

Which would then need documentation to explain it, and numerous posts here 
complaining about this weird edge case and how they should be allowed to write 
code however they want.



On Wed, 2019-04-24 at 18:40 -0700, Michael Jones wrote:
> switch test {
> case true:
>   //..code block for test=true
> case false:
>   //..code block for test=false
> }
> 
> On Wed, Apr 24, 2019 at 4:42 PM Dan Kortschak 
> wrote:
> 
> > 
> > How would you preclude it?
> > 
> > On Wed, 2019-04-24 at 16:28 -0700, lgod...@gmail.com wrote:
> > > 
> > > I am NOT in favor of allowing nested ternary operations
> > --
> > 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] Re: Go if else syntax .. suggested replacement

2019-04-24 Thread Michael Jones
switch test {
case true:
  //..code block for test=true
case false:
  //..code block for test=false
}

On Wed, Apr 24, 2019 at 4:42 PM Dan Kortschak  wrote:

> How would you preclude it?
>
> On Wed, 2019-04-24 at 16:28 -0700, lgod...@gmail.com wrote:
> > I am NOT in favor of allowing nested ternary operations
>
> --
> 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] Re: Go if else syntax .. suggested replacement

2019-04-24 Thread Dan Kortschak
How would you preclude it?

On Wed, 2019-04-24 at 16:28 -0700, lgod...@gmail.com wrote:
> I am NOT in favor of allowing nested ternary operations

-- 
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] Re: Go if else syntax .. suggested replacement

2019-04-24 Thread lgodio2
Just to clarify :  My original proposal was to include as part  of Go the 
syntax

(test) ? {
{ //..code block for test=true
} : {
  //..code block for test=false
} 

I am NOT in favor of allowing nested ternary operations

In addition, I also propose allowing un-nested '?' as an alternative 
assignment statement i.e.  var = (temp >80) ? "red": "blue"

Thus, any further discussion of this topic should not involve issues 
related to nested ternary operations 

On Tuesday, April 23, 2019 at 9:05:31 PM UTC-4, 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 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+ replacement

2019-04-24 Thread Ronny Bangsund
I occasionally read this list, and sometimes I stop by the Go Slack. There 
are many channels there, and the general one might actually be the least 
interesting to many. I mostly follow the VSCode discussions/live help 
channel, and sometimes there's activity in other project-specific or 
regional channels.

Browsing #golang on Twitter sometimes at least shows some interesting 
projects. Maybe even people to follow.

-- 
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.


[go-nuts] Re: Is there a way to force to pass some function or error check when Debugging?

2019-04-24 Thread jake6502


On Tuesday, April 23, 2019 at 1:43:52 AM UTC-4, hui zhang wrote:
>
> I am debugging a linux server program in local mac machine.
> some code related to environment check , such as check mount point etc.
>
> I want to pass this check ,   how ?
>
>- I try it set return error var to nil.  but it seems not working in 
>devel for now.
>- I imagine to mock function, but not sure how to do it when debugging.
>- I knew the convenient way is to change source code directly .   But 
>there is a lot of code to change .  I don't want to mess it up
>
> any advice?
>
>
Your post is far to vague for me to even begin giving advice. I would 
suggest that you try to give more detail so that we can get a clear picture 
of what you have and what you are trying to accomplish.  

-- 
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] cannot use CallBack (type func(*_Ctype_char, *_Ctype_char, _Ctype_ulong)) as type *[0]byte in argument to _Cfunc_reload_pattern_db

2019-04-24 Thread Jan Mercl
On Wed, Apr 24, 2019 at 4:16 PM Nitish Saboo  wrote:

> >>Why size_t, char is going to be undefined here ? I followed the exact steps 
> >>mentioned in 'https://github.com/golang/go/wiki/cgo#function-variables'  
> >>under the topic 'Function pointer callback'.
> I have to pass the callback function to the C code.

size_t is going to be undefined because you're not including the
header that defines it before using the type. Or you may just get
lucky, as the compiler may include the right header in the translation
unit for you anyway, because CGO needs that type as well. In that
case, your code may break anytime in the future.

-- 
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] cannot use CallBack (type func(*_Ctype_char, *_Ctype_char, _Ctype_ulong)) as type *[0]byte in argument to _Cfunc_reload_pattern_db

2019-04-24 Thread Nitish Saboo
On Wed, Apr 24, 2019 at 1:51 PM Nitish Saboo 
wrote:
>
> Hi,
>
> I followed the link '
https://github.com/golang/go/wiki/cgo#function-variables' and  made the
following changes:
> 1)main.go
> package main
> //#cgo CFLAGS: -I./syslog-ng-3.6.2/
> //#cgo LDFLAGS: syslog-node.so
> //#cgo LDFLAGS: -L/usr/local/lib/ -lsyslog-ng
> //#cgo LDFLAGS: -L/usr/local/lib/syslog-ng -ldbparser
> //#cgo CFLAGS: -I.
> //void callOnMeGo_cgo(char *key, char *value, size_t value_len);  <

size_t is going to be undefined here.. Also the chars after ';' should
not be there

>>Why size_t, char is going to be undefined here ? I followed the exact
steps mentioned in 'https://github.com/golang/go/wiki/cgo#function-variables'
under the topic 'Function pointer callback'.
I have to pass the callback function to the C code.

> // #include "syslog-node1.h"
> //#include 
> import "C"
>
> //export CallBack
> func CallBack(key *C.char, value *C.char, value_len C.size_t){
>
> if remap, ok := field_mappings[C.GoString(key)]; ok {
> fmt.Println(key, remap)//Need to check how field mappings work
> }
>
> }
>
> func ReloadPatternDB(opts Y){

Where from type Y comes?
>> Y is simply a struct
type Y struct{
 x string
z map[string]string
}

>
> x := C.CString(opts.x)
> C.reload_pattern_db(x, (C.key_value_cb)(unsafe.Pointe
r(C.callOnMeGo_cgo)));
>
> }
>
> 2)Created a file 'cfuncs.go'
> 
> package main

Package main must have func main(). Where it is?

>>I had missed it.Added the func main()  but that did not resolve the issue.

*Following is the error that I am receiving:*

# command-line-arguments
*/tmp/go-build729657300/b001/_cgo_main.o:/tmp/go-build/cgo-generated-wrappers:2:
undefined reference to `callOnMeGo_cgo'*
collect2: error: ld returned 1 exit status
makefile:6: recipe for target 'main' failed
make: *** [main] Error 2


I feel the issue is with the makefile.Looks like the makefile is not able
to locate the method ' *callOnMeGo_cgo'.*Let me know if my understanding is
correct ?
Can someone help me in resolving the issue ?

Thanks

On Wed, Apr 24, 2019 at 5:39 PM Jan Mercl <0xj...@gmail.com> wrote:

> On Wed, Apr 24, 2019 at 1:51 PM Nitish Saboo 
> wrote:
> >
> > Hi,
> >
> > I followed the link '
> https://github.com/golang/go/wiki/cgo#function-variables' and  made the
> following changes:
> > 1)main.go
> > package main
> > //#cgo CFLAGS: -I./syslog-ng-3.6.2/
> > //#cgo LDFLAGS: syslog-node.so
> > //#cgo LDFLAGS: -L/usr/local/lib/ -lsyslog-ng
> > //#cgo LDFLAGS: -L/usr/local/lib/syslog-ng -ldbparser
> > //#cgo CFLAGS: -I.
> > //void callOnMeGo_cgo(char *key, char *value, size_t value_len);  <
>
> size_t is going to be undefined here.. Also the chars after ';' should
> not be there
>
> > // #include "syslog-node1.h"
> > //#include 
> > import "C"
> >
> > //export CallBack
> > func CallBack(key *C.char, value *C.char, value_len C.size_t){
> >
> > if remap, ok := field_mappings[C.GoString(key)]; ok {
> > fmt.Println(key, remap)//Need to check how field mappings work
> > }
> >
> > }
> >
> > func ReloadPatternDB(opts Y){
>
> Where from type Y comes?
>
> >
> > x := C.CString(opts.x)
> > C.reload_pattern_db(x,
> (C.key_value_cb)(unsafe.Pointer(C.callOnMeGo_cgo)));
> >
> > }
> >
> > 2)Created a file 'cfuncs.go'
> > 
> > package main
>
> Package main must have func main(). Where it is?
>

-- 
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.


[go-nuts] Re: Does fmt.Fprint use WriteString ?

2019-04-24 Thread codiglot
That's interesting and good to know. I guess it should be expected given 
that Fprint does a bit more work using it's internal printer struct and 
buffer.

On Tuesday, April 23, 2019 at 1:43:55 PM UTC-4, Constantin Konstantinidis 
wrote:
>
> The result is equivalent but a micro-benchmark shows that pkg io is 3x 
> faster.
>
> go version go1.12.2 windows/amd64
> pkg: github.com/iWdGo/GoCompilerEfficiency/src/writestring
> BenchmarkFmtWriteString-4 
> 
>  50  2002 ns/op
> BenchmarkIoWriteString-4 200   635 ns/op
> PASS
>
>
> This is irrelevant is the string requires some build.
> (sorry for the typo above)
>

-- 
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] Re: Gomobile Reverse Bindings: Cannot import any android packages

2019-04-24 Thread Mark Bauermeister
Yea. Turns out that was indeed the issue. I tried accessing a method that 
didn't actually exist.

Unfortunately, your code doesn't work either. It leads to a segmentation 
violation/nil pointer error.
I suspect one needs to somehow get the right context from the Java side. 
Question is how.

I already tried an OnCreate override func, but that one is somehow never 
called.

On Wednesday, 24 April 2019 15:08:02 UTC+2, ma...@eliasnaur.com wrote:
>
>
>
> On Wednesday, April 24, 2019 at 2:34:34 PM UTC+2, Mark Bauermeister wrote:
>>
>> I'm currently experimenting with Gomobile Reverse Bindings (my hope is to 
>> eventually be able to call getFilesDir(), so I can save my SQLite3 DB on 
>> mobile) and it is, quite literally, driving me insane.
>> I've followed the sparse information available, was able to successfully 
>> work with 'import "Java/java/lang/System" and call 
>> "System.currentTimeMillis()".
>>
>> Now I'm trying to import "Java/android/content" and it fails outright, 
>> stating that the package "Java/android/content" cannot be found.
>>
>> What is the correct import path for Android packages, or is there 
>> something else I need to do that I'm missing?
>>
>
> Note that reverse binding packages will only be generated if you use a 
> type from it; importing is unfortunately not enough.
>
> Perhaps
>
> import "Java/android/content"
>
> var ctx content.Context
> ctx.GetFilesDir()
>
> is enough to get further.
>
> The reverse bindings are very fickle, sorry.
>
>  - elias
>

-- 
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] Re: Gomobile Reverse Bindings: Cannot import any android packages

2019-04-24 Thread mail


On Wednesday, April 24, 2019 at 2:34:34 PM UTC+2, Mark Bauermeister wrote:
>
> I'm currently experimenting with Gomobile Reverse Bindings (my hope is to 
> eventually be able to call getFilesDir(), so I can save my SQLite3 DB on 
> mobile) and it is, quite literally, driving me insane.
> I've followed the sparse information available, was able to successfully 
> work with 'import "Java/java/lang/System" and call 
> "System.currentTimeMillis()".
>
> Now I'm trying to import "Java/android/content" and it fails outright, 
> stating that the package "Java/android/content" cannot be found.
>
> What is the correct import path for Android packages, or is there 
> something else I need to do that I'm missing?
>

Note that reverse binding packages will only be generated if you use a type 
from it; importing is unfortunately not enough.

Perhaps

import "Java/android/content"

var ctx content.Context
ctx.GetFilesDir()

is enough to get further.

The reverse bindings are very fickle, sorry.

 - elias

-- 
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] Gomobile Reverse Bindings: Cannot import any android packages

2019-04-24 Thread Mark Bauermeister
I'm currently experimenting with Gomobile Reverse Bindings (my hope is to 
eventually be able to call getFilesDir(), so I can save my SQLite3 DB on 
mobile) and it is, quite literally, driving me insane.
I've followed the sparse information available, was able to successfully 
work with 'import "Java/java/lang/System" and call 
"System.currentTimeMillis()".

Now I'm trying to import "Java/android/content" and it fails outright, 
stating that the package "Java/android/content" cannot be found.

What is the correct import path for Android packages, or is there something 
else I need to do that I'm missing?

-- 
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] Change in virtual memory patterns in Go 1.12

2019-04-24 Thread kevin . a . conaway
Hi Michael,

I found my way to this thread as we are experiencing similar issues in one 
of our applications after upgrading from 1.11.1 to 1.12.4.  Our application 
has a lot of persistent, large, busy maps so we periodically recreate them 
per https://github.com/golang/go/issues/20135.  What we are seeing is that 
MemStats.HeapSys and MemStats.HeapReleased begin to grow linearly together 
while MemStates.HeapIdle stays relatively constant.  Other measures, like 
the system memory usage or the process RSS are also relatively flat.

I applied your patch on the 1.12.4 tag and it looked good in that 
HeapSys/HeapReleased stopped growing  

Please let me know if I can provide any other details here.

Thank you

On Tuesday, April 16, 2019 at 1:34:52 PM UTC-4, Michael Knyszek wrote:
>
> Hey Rémy,
>
> If you have a chance, could you please try out this patch 
> ? It's been known to 
> help the other application Austin mentioned with virtual memory footprint 
> and it should patch cleanly onto the go1.12. Let me know what you see! It'd 
> help us to confirm the root cause of the VSS growth.
>
> Thanks,
> Michael
>
> On Tue, Apr 16, 2019 at 11:03 AM Austin Clements  > wrote:
>
>> On Tue, Apr 16, 2019 at 1:23 AM Rémy Oudompheng > > wrote:
>>
>>> Thanks Austin,
>>>
>>> The application workload is a kind of fragmentation torture test as it
>>> involves a mixture of many long-lived small and large (>100 MB)
>>> objects, with regularly allocated short-lived small and large objects.
>>> I have tried creating a sample synthetic reproducer but did not
>>> succeed at the moment.
>>>
>>> Regarding the max_map_count, your explanation is very clear and I
>>> apparently missed the large comment in the runtime explaining all of
>>> that.
>>> Do you expect a significant drawback between choosing 2MB or 16MB as
>>> the granularity of the huge page flag manipulation in the case of huge
>>> heaps ?
>>>
>>
>> Most likely this will just cause less use of huge pages in your 
>> application. This could slow it down by putting more pressure on the TLB. 
>> In a sense, this is a self-compounding issue since huge pages can be highly 
>> beneficial to huge heaps.
>>
>> Regarding the virtual memory footprint, it changed radically with Go
>>> 1.12. It basically looks like a leak and I saw it grow to more than
>>> 1TB where the actual heap total size never exceeds 180GB.
>>> Although I understand that it is easy to construct a situation where
>>> there is repeatedly no available contiguous interval of >100MB in the
>>> address space, it is a significant difference from Go 1.11 where the
>>> address space would grow to 400-500GB for a similar workload and stay
>>> flat after that, and I could not find an obvious change in the
>>> allocator explaining the phenomenon (and unfortunately my resources do
>>> not allow for an easy live comparison of both program lifetimes).
>>>
>>> Am I right saying that scavenging method or frequency does not
>>> (cannot) affect at all virtual memory footprint and dynamics ?
>>>
>>
>> It certainly can affect virtual memory footprint because of how 
>> scavenging affects the allocator's placement policy. Though even with the 
>> increased VSS, I would expect your application to have lower RSS with 1.12. 
>> In almost all cases, lower RSS with higher VSS is a fine trade-off, though 
>> lower RSS with the same VSS would obviously be better. But it can be 
>> problematic when it causes the map count (which is roughly proportional to 
>> the VSS) to grow too large. It's also unfortunate that Linux even has this 
>> limit; it's the only OS Go runs on that limits the map count.
>>
>> We've seen one other application experience VSS growth with the 1.12 
>> changes, and it does seem to require a pretty unique allocation pattern. 
>> Michael (cc'd) may be zeroing in on the causes of this and may have some 
>> patches for you to try if you don't mind. :)
>>
>> Regards,
>>> Rémy.
>>>
>>> Le mar. 2 avr. 2019 à 16:15, Austin Clements >> > a écrit :
>>> >
>>> > Hi Rémy. We often fight with vm.max_map_count in the runtime, sadly. 
>>> Most likely this comes from the way the runtime interacts with Linux's 
>>> transparent huge page support. When we scavenge (release to the OS) only 
>>> part of a huge page, we tell the OS not to turn that huge page frame back 
>>> into a huge page since that would just make that memory used again. 
>>> Unfortunately, each time we do this counts as a separate "mapping" just to 
>>> track that one flag. These "mappings" are always at least 2MB, but you have 
>>> a large enough virtual address space to reach the max_map_count even then. 
>>> You can see this in /proc/PID/smaps, which should list mostly contiguous 
>>> neighboring regions that differ only in a single "VmFlags" bit.
>>> >
>>> > We did make memory scavenging more aggressive in Go 1.12 (+Michael 
>>> Knyszek), though I would have expected it to converge to roughly the same 
>>> "huge 

Re: [go-nuts] how to test main function coverage with different args

2019-04-24 Thread J. Santos
Hi,

I think you could set the `os.Args` before calling your main.

--
Jota


On Tue, Apr 23, 2019, 6:03 AM hui zhang  wrote:

> how to test main function coverage with different args  to  enhance
> coverage rate
> how to cover the red part ? for you can set args once a time
>
> func Test_main(m *testing.T) {
>main2()
> }
>
>
> go test -coverprofile coverage.cov -args xxx.conf go tool cover
> -html=coverage.cov -o coverage.html
>
> --
> 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] [RFC][Gomobile] Wrote a series of posts on Gomobile

2019-04-24 Thread Reto
On Tue, Apr 23, 2019 at 08:46:15PM -0700, Girish Koundinya wrote:
> Any feedback is welcome :)

Well, for starters please return early from functions instead of nesting it 4 
levels deep, like in the example below (getContacts)
https://gist.githubusercontent.com/koundinya/a0d18ba4b830e3bb86f65aced026acbe/raw/f06fc5b8cd2dad7ec3af3f04de46c37337d4e6fb/contact_library.go

second, should in that same function the http.Get call ever fail you will panic

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

-- 
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] cannot use CallBack (type func(*_Ctype_char, *_Ctype_char, _Ctype_ulong)) as type *[0]byte in argument to _Cfunc_reload_pattern_db

2019-04-24 Thread Jan Mercl
On Wed, Apr 24, 2019 at 1:51 PM Nitish Saboo  wrote:
>
> Hi,
>
> I followed the link 
> 'https://github.com/golang/go/wiki/cgo#function-variables' and  made the 
> following changes:
> 1)main.go
> package main
> //#cgo CFLAGS: -I./syslog-ng-3.6.2/
> //#cgo LDFLAGS: syslog-node.so
> //#cgo LDFLAGS: -L/usr/local/lib/ -lsyslog-ng
> //#cgo LDFLAGS: -L/usr/local/lib/syslog-ng -ldbparser
> //#cgo CFLAGS: -I.
> //void callOnMeGo_cgo(char *key, char *value, size_t value_len);  <

size_t is going to be undefined here.. Also the chars after ';' should
not be there

> // #include "syslog-node1.h"
> //#include 
> import "C"
>
> //export CallBack
> func CallBack(key *C.char, value *C.char, value_len C.size_t){
>
> if remap, ok := field_mappings[C.GoString(key)]; ok {
> fmt.Println(key, remap)//Need to check how field mappings work
> }
>
> }
>
> func ReloadPatternDB(opts Y){

Where from type Y comes?

>
> x := C.CString(opts.x)
> C.reload_pattern_db(x, 
> (C.key_value_cb)(unsafe.Pointer(C.callOnMeGo_cgo)));
>
> }
>
> 2)Created a file 'cfuncs.go'
> 
> package main

Package main must have func main(). Where it is?

-- 
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.


[go-nuts] Benchmark Issue with list of cpu counts

2019-04-24 Thread pointadvance
I'm writing a simple benchmark to observe speedup with increased cores, I'm 
having an issue where the for core count of 1, it still uses GOMAXPROCS (in 
my case 4, hyper-threading turned off).

I'm thinking its just a flag is not set right, but I'm putting foward 
everything I know, because I think its still pretty weird for default 
behaviour.

I'm putting *1.* version and environment info, *2.* benchmark source code, 
*3.* benchmark results with instruction called, *4.* cpu info

*1.* version and environment info:
$ go version
go version go1.12.1 linux/amd64

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/point/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/point/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 
-fdebug-prefix-map=/tmp/go-build577448577=/tmp/go-build 
-gno-record-gcc-switches"


*2.* benchmark source code
scale_test.go
package scale

import "testing"

func BenchmarkScale(b *testing.B) {
for i := 0; i < b.N; i++ {
scale(b)
}
}

scale.go
package scale

import (
"math"
"runtime"
"testing"
)

func scale(b *testing.B) {

const max int = 12
l := int(math.Pow(2, 30))
NP := runtime.GOMAXPROCS(0)

var a [max]int
slice := max / NP

done := make(chan bool)
worker := func(P int, prod chan bool) {
for i := P * slice; i < (P+1)*slice; i++ {
for j := 0; j < l; j++ {
a[i]++
}
}
prod <- true
}

b.ResetTimer()

for p := 0; p < NP; p++ {
go worker(p, done)
}

for p := 0; p < NP; p++ {
<-done
}

}

*3.* benchmark results with instruction called

Ran with 1 core for multiple times, consistent, time as expected
$ go test -bench=. -cpu 1 -trace trace.out -count 5
goos: linux
goarch: amd64
BenchmarkScale120830211783 ns/op
BenchmarkScale120846636262 ns/op
BenchmarkScale120913565823 ns/op
BenchmarkScale120811254293 ns/op
BenchmarkScale120819699212 ns/op
PASS
ok  _/Demo104.225s

Similar for 2 cores, relatively reasonable timings
$ go test -bench=. -cpu 2 -trace trace.out -count 5
goos: linux
goarch: amd64
BenchmarkScale-2  112717158624 ns/op
BenchmarkScale-2  112811024997 ns/op
BenchmarkScale-2  112774018625 ns/op
BenchmarkScale-2  112770698880 ns/op
BenchmarkScale-2  112757689969 ns/op
PASS
ok  _/Demo63.835s

Similar for 3 cores, relatively reasonable timings
$ go test -bench=. -cpu 3 -trace trace.out -count 5
goos: linux
goarch: amd64
BenchmarkScale-3  110820517159 ns/op
BenchmarkScale-3  110761484928 ns/op
BenchmarkScale-3  110730973532 ns/op
BenchmarkScale-3  110834395953 ns/op
BenchmarkScale-3  111004999207 ns/op
PASS
ok  _/Demo54.158s

Similar for 4 cores, relatively reasonable timings
$ go test -bench=. -cpu 4 -trace trace.out -count 5
goos: linux
goarch: amd64
BenchmarkScale-4  18597505567 ns/op
BenchmarkScale-4  18523662979 ns/op
BenchmarkScale-4  18578160668 ns/op
BenchmarkScale-4  18585568729 ns/op
BenchmarkScale-4  18526519203 ns/op
PASS
ok  _/Demo42.817s

Running all of them repeatedly, the first reading is similar to the 
readings a 4 cores, not consistent with those at 1 core
$ go test -bench=. -cpu 1,2,3,4 -trace trace.out -count 5
goos: linux
goarch: amd64
BenchmarkScale18164198465 ns/op
BenchmarkScale120826667395 ns/op
BenchmarkScale120804635058 ns/op
BenchmarkScale120794385469 ns/op
BenchmarkScale120816750891 ns/op
BenchmarkScale-2  112706414818 ns/op
BenchmarkScale-2  112708898913 ns/op
BenchmarkScale-2  112770280120 ns/op
BenchmarkScale-2  112775216602 ns/op
BenchmarkScale-2  112636852361 ns/op
BenchmarkScale-3  110756340731 ns/op
BenchmarkScale-3  111045028650 ns/op
BenchmarkScale-3  111089450739 ns/op
BenchmarkScale-3  110771597158 ns/op
BenchmarkScale-3  110991225203 ns/op
BenchmarkScale-4  18142770549 ns/op
BenchmarkScale-4  18448329795 ns/op
BenchmarkScale-4  18436012552 ns/op
BenchmarkScale-4  18011377874 ns/op
BenchmarkScale-4  18069116380 ns/op
PASS
ok  _/Demo250.779s

Obviously would exhibit itself better 

Re: [go-nuts] cannot use CallBack (type func(*_Ctype_char, *_Ctype_char, _Ctype_ulong)) as type *[0]byte in argument to _Cfunc_reload_pattern_db

2019-04-24 Thread Nitish Saboo
Hi,

I followed the link '
https://github.com/golang/go/wiki/cgo#function-variables' and  made the
following changes:
*1)main.go*
package main
//#cgo CFLAGS: -I./syslog-ng-3.6.2/
//#cgo LDFLAGS: syslog-node.so
//#cgo LDFLAGS: -L/usr/local/lib/ -lsyslog-ng
//#cgo LDFLAGS: -L/usr/local/lib/syslog-ng -ldbparser
//#cgo CFLAGS: -I.
//void callOnMeGo_cgo(char *key, char *value, size_t value_len);  <
// #include "syslog-node1.h"
//#include 
import "C"

//export CallBack
func CallBack(key *C.char, value *C.char, value_len C.size_t){

if remap, ok := field_mappings[C.GoString(key)]; ok {
fmt.Println(key, remap)//Need to check how field mappings work
}

}

func ReloadPatternDB(opts Y){

x := C.CString(opts.x)
C.reload_pattern_db(x,
(C.key_value_cb)(unsafe.Pointer(C.callOnMeGo_cgo)));

}

2)Created a file 'cfuncs.go'
**
package main

/*

#include 

// The gateway function
void callOnMeGo_cgo(char *key, char *value, size_t value_len)
{
printf("C.callOnMeGo_cgo(): called");
return CallBack(key, value, value_len);
}
*/
import "C"


*3)Following is my C header file:*
#ifndef _TEST_H_
#define _TEST_H_

#include 

typedef void (*key_value_cb)(const char* key, const char* value, size_t
value_len);
int initialize_engine(const char* filename, const char* module_path,
key_value_cb cb);
int reload_pattern_db(const char* filename, key_value_cb cb);
void match(const char* pattern, size_t pattern_len, const char* program,
size_t program_len);

#endif



*4)My make file:*
.PHONY: all clean

all: main

main: syslog-node.so main.go syslog-node1.h
go build -v -x main.go

syslog-node.so: syslog-node.c syslog-node1.h cfuncs.go
gcc -L/usr/local/lib -lsyslog-ng -o syslog-node.so
-L/usr/local/lib/syslog-ng -ldbparser -c `pkg-config --libs --cflags
glib-2.0` -I/usr/local/include/syslog-ng/ -I./syslog-ng-3.6.2/
-I/usr/local/include/eventlog/ -I. syslog-node.c

clean:
rm main
rm syslog-node.so


*5) When I run the make command, I get the following error *
v$ make
gcc -L/usr/local/lib -lsyslog-ng -o syslog-node.so
-L/usr/local/lib/syslog-ng -ldbparser -c `pkg-config --libs --cflags
glib-2.0` -I/usr/local/include/syslog-ng/ -I./syslog-ng-3.6.2/
-I/usr/local/include/eventlog/ -I. syslog-node.c
go build -v -x main.go
WORK=/tmp/go-build729657300
command-line-arguments
mkdir -p $WORK/b001/
cd /home/nitish/Documents/goworkspace/src/Syslogng/node-syslog-ng-dev
CGO_LDFLAGS='"-g" "-O2" "syslog-node.so" "-L/usr/local/lib/" "-lsyslog-ng"
"-L/usr/local/lib/syslog-ng" "-ldbparser"'
/usr/local/go/pkg/tool/linux_amd64/cgo -objdir $WORK/b001/ -importpath
command-line-arguments -- -I $WORK/b001/ -g -O2
-I/home/nitish/Documents/goworkspace/src/Syslogng/node-syslog-ng-dev/syslog-ng-3.6.2
-I/home/nitish/Documents/goworkspace/src/Syslogng/node-syslog-ng-dev
./main.go
cd $WORK
gcc -fno-caret-diagnostics -c -x c - || true
gcc -Qunused-arguments -c -x c - || true
gcc -fdebug-prefix-map=a=b -c -x c - || true
gcc -gno-record-gcc-switches -c -x c - || true
cd $WORK/b001
TERM='dumb' gcc -I
/home/nitish/Documents/goworkspace/src/Syslogng/node-syslog-ng-dev -fPIC
-m64 -pthread -fmessage-length=0
-fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I ./
-g -O2
-I/home/nitish/Documents/goworkspace/src/Syslogng/node-syslog-ng-dev/syslog-ng-3.6.2
-I/home/nitish/Documents/goworkspace/src/Syslogng/node-syslog-ng-dev -o
./_x001.o -c _cgo_export.c
TERM='dumb' gcc -I
/home/nitish/Documents/goworkspace/src/Syslogng/node-syslog-ng-dev -fPIC
-m64 -pthread -fmessage-length=0
-fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I ./
-g -O2
-I/home/nitish/Documents/goworkspace/src/Syslogng/node-syslog-ng-dev/syslog-ng-3.6.2
-I/home/nitish/Documents/goworkspace/src/Syslogng/node-syslog-ng-dev -o
./_x002.o -c main.cgo2.c
TERM='dumb' gcc -I
/home/nitish/Documents/goworkspace/src/Syslogng/node-syslog-ng-dev -fPIC
-m64 -pthread -fmessage-length=0
-fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -I ./
-g -O2
-I/home/nitish/Documents/goworkspace/src/Syslogng/node-syslog-ng-dev/syslog-ng-3.6.2
-I/home/nitish/Documents/goworkspace/src/Syslogng/node-syslog-ng-dev -o
./_cgo_main.o -c _cgo_main.c
cd /home/nitish/Documents/goworkspace/src/Syslogng/node-syslog-ng-dev
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0
-fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -o
$WORK/b001/_cgo_.o $WORK/b001/_cgo_main.o $WORK/b001/_x001.o
$WORK/b001/_x002.o -g -O2 syslog-node.so -L/usr/local/lib/ -lsyslog-ng
-L/usr/local/lib/syslog-ng -ldbparser
# command-line-arguments
/tmp/go-build729657300/b001/_cgo_main.o:/tmp/go-build/cgo-generated-wrappers:2:
undefined reference to `callOnMeGo_cgo'
collect2: error: ld returned 1 exit status
makefile:6: recipe for target 'main' failed
make: *** [main] Error 2


Can someone please point me the what am I missing in my make file or
something else in my code base that will resolve this error ?

Thanks

On Wed, 

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] cannot use CallBack (type func(*_Ctype_char, *_Ctype_char, _Ctype_ulong)) as type *[0]byte in argument to _Cfunc_reload_pattern_db

2019-04-24 Thread Jan Mercl
On Wed, Apr 24, 2019 at 10:47 AM Nitish Saboo  wrote:

> ./main.go:80:32: cannot use key (type *_Ctype_char) as type string in map 
> index

func CallBack(ckey *C.char, value *C.char, value_len C.size_t){
key := C.GoString(ckey)
if remap, ok := field_mappings[key]; ok {
fmt.Println(key, remap)
}
}


> ./main.go:91:21: cannot use CallBack (type func(*_Ctype_char, *_Ctype_char, 
> _Ctype_ulong)) as type *[0]byte in argument to _Cfunc_reload_pattern_db
> ./main.go:143:21: cannot use CallBack (type func(*_Ctype_char, *_Ctype_char, 
> _Ctype_ulong)) as type *[0]byte in argument to

See https://github.com/golang/go/wiki/cgo#function-variables:

"Because of the pointer passing rules Go code can not pass a
function value directly to C. "

-- 
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] cannot use CallBack (type func(*_Ctype_char, *_Ctype_char, _Ctype_ulong)) as type *[0]byte in argument to _Cfunc_reload_pattern_db

2019-04-24 Thread Nitish Saboo
Hi,

I am facing the following issue:

I have a GO code that has to be called from the C code:

var field_mappings map[string]string = map[string]string{
" A": "a",
"B": "b",
"C": "c",
"D": "d"}


//export CallBack
func CallBack(key *C.char, value *C.char, value_len C.size_t){

if remap, ok := field_mappings[key]; ok {
fmt.Println(key, remap)
}

}

I am passing this callback method to the C function

func ReloadPatternDB(opts Y){
   
   x := C.CString(opts.x)
   C.reload_pattern_db(x, CallBack);

}


int reload_pattern_db(const gchar* filename, key_value_cb cb)
{
 
 //
 
}

Following is my C header file:

#ifndef _TEST_H_
#define _TEST_H_

#include 

typedef void (*key_value_cb)(const char* key, const char* value, size_t 
value_len);
int initialize_engine(const char* filename, const char* module_path, 
key_value_cb cb);
int reload_pattern_db(const char* filename, key_value_cb cb);
void match(const char* pattern, size_t pattern_len, const char* program, 
size_t program_len);

#endif


When I compile the GO code I am getting the following error:

# command-line-arguments
./main.go:80:32: cannot use key (type *_Ctype_char) as type string in map 
index
./main.go:91:21: cannot use CallBack (type func(*_Ctype_char, *_Ctype_char, 
_Ctype_ulong)) as type *[0]byte in argument to _Cfunc_reload_pattern_db
./main.go:143:21: cannot use CallBack (type func(*_Ctype_char, 
*_Ctype_char, _Ctype_ulong)) as type *[0]byte in argument to 


I am new to GO and CGO.Can someone please point out the error and help me 
out ?

Thanks

-- 
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.


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

2019-04-24 Thread wilk
On 24-04-2019, lgod...@gmail.com wrote:
> --=_Part_538_706677508.1556067911841
> Content-Type: multipart/alternative; 
>   boundary="=_Part_539_1965717614.1556067911841"
>
> --=_Part_539_1965717614.1556067911841
> Content-Type: text/plain; charset="UTF-8"
>
> It sure would be nice if Go syntax allowed programmers to replace 

I suggest you to use switch case...

-- 


-- 
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] Re: how to test main function coverage with different args

2019-04-24 Thread Miki Tebeka
You can use table driven test, see 
https://github.com/golang/go/wiki/TableDrivenTests

On Tuesday, April 23, 2019 at 12:03:15 PM UTC+3, hui zhang wrote:
>
> how to test main function coverage with different args  to  enhance 
> coverage rate
> how to cover the red part ? for you can set args once a time
>
> func Test_main(m *testing.T) {
>main2()
> }
>
>
> go test -coverprofile coverage.cov -args xxx.conf go tool cover 
> -html=coverage.cov -o coverage.html
>
>

-- 
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.