Re: [go-nuts] Is it possible to simplify this snippet?

2019-05-01 Thread Gopal M
ternary can be there is Go, Since most of the programmers are used to it.
Readability is the issue of programmer who writes and reads it, I don't see
any point in restricting this..

On Thu, May 2, 2019 at 3:51 AM Andy Balholm  wrote:

> You could have a cleaner switch statement if you had a list of the keys
> that were pressed, instead of needing to check each one individually:
>
> func whichKeys(keysToCheck ...keyID) []keyID {
> var result []keyID
> for _, k := range keysToCheck {
> if rl.IsKeyDown(k) {
> result = append(result, k)
> }
> }
>
> return result
> }
>
> for _, k := range whichKeys(rl.KeyA, rl.KeyD, rl.KeyW, rl.KeyS) {
> switch k {
> case rl.KeyA:
> p.Rect.X -= 1
> case rl.KeyD:
> p.Rect.X += 1
> case rl.KeyW:
> p.Rect.Y -= 1
> case rl.KeyS:
> p.Rect.Y += 1
> }
> }
>
> Andy
>
>
> On May 1, 2019, at 2:51 PM, Burak Serdar  wrote:
>
> On Wed, May 1, 2019 at 2:31 PM  wrote:
>
>
> Great example of why future Go updates should include the ternary operator.
> Your code is mess-ey when written using keywords 'if' or 'switch'
> but  using '?' it becomes much cleaner
>
> p.Rect.X +=  rl.IsKeyDown(rl.KeyA) ? -1:0   +  (rl.IsKeyDown(rl.KeyD) ? 1
> : 0 )
> p.Rect.Y +=  rl.IsKeyDown(rl.KeyW) ? -1:0   +  (rl.IsKeyDown(rl.KeyS) ? 1
> : 0 )
>
>
> I don't think this is readable at all. I think the cascading-ifs
> version is much easier to read.
>
> You could do something like the following, but I think pointless
> unless there's more to the original snippet:
>
> checkKey:=func(k, v int) int {
>  if rl.IsKeyDown(k) {
>return v
>  }
> return 0
> }
> p.Rect.X+=checkKey(rl.KeyA,-1)+checkKey(rl.KeyD,1)
> p.Rect.Y+=checkKey(rl.KeyW,-1)+checkKey(,rl.KeyS,1)
>
>
> On Wednesday, May 1, 2019 at 8:38:10 AM UTC-4, гусь wrote:
>
>
> if rl.IsKeyDown(rl.KeyA) {
> p.Rect.X -= 1
> }
> if rl.IsKeyDown(rl.KeyD) {
> p.Rect.X += 1
> }
> if rl.IsKeyDown(rl.KeyW) {
> p.Rect.Y -= 1
> }
> if rl.IsKeyDown(rl.KeyS) {
> p.Rect.Y += 1
> }
>
>
> --
> 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.
>


-- 
Regards,
M. Gopal

-- 
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] Any recommendation for structured logging library in Golang?

2020-11-17 Thread Gopal M
go.uber.org/zap

On Wed, Nov 18, 2020 at 12:48 PM Mike Spreitzer  wrote:

> > From: ChrisLu 
> > To: golang-nuts 
> > Date: 11/17/2020 11:22 PM
> > Subject: [EXTERNAL] [go-nuts] Any recommendation for structured
> > logging library in Golang?
> > Sent by: golang-nuts@googlegroups.com
> >
> > I am considering moving from glog to structured logging. I tried
> > logrus, go-kit, uber/zap, but could not find one good fit. In short,
> > this is the desired format:
> > [info][timestamp] [filename:line_number] message k1=v1 k2=v2 ...
> > It shows the correct file name(need to pop out a few call stacks)
> > and line number in a customizable format, not as key-value pair for
> > each line which is just too verbose to have the extra "time=" "file=".
> > Please let me know the one you actually use.
> >
> > Thanks!
> > Chris
>
> How about one that has fine-grained debug leveling, like glog or klog,
> too?
>
> Thanks,
> Mike
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/OF42CB2A54.2706B41C-ON85258624.0027F1D3-85258624.00280B00%40notes.na.collabserv.com
> .
>


-- 
Regards,
M. Gopal

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


Re: [go-nuts] Golang import issue .

2022-07-19 Thread Gopal M
Hi Sunday Ajayi,

Pl avoid screenshots... :-)
Finding it difficult to decode / Seems to be no full information available
to understand.

Will you be able to send the zipped project ?

On Tue, Jul 19, 2022 at 9:44 PM Sunday Ajayi  wrote:

> Hi Team,
>
> I am having an issue import functions into another.
>
> Attached is the error and my directory and code structure.
>
>
> Regards,
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/4dfaed27-d123-4eab-b70e-02e0cdb05091n%40googlegroups.com
> 
> .
>


-- 
Regards,
M. Gopal

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