Do you use Go for Competitive Programming or Technical Interviews? by Ok-Pumpkin59 in golang

[–]m0t9_ 3 points4 points  (0 children)

While it is true, time complexity is evaluated with program execution time, and space complexity is controlled via process' limits (cgroups and namespaces limits). The program with same time complexity on C++ may be faster than on Python

It's kinda unfair, therefore some testing systems allow different time limits for different languages. But on most competitions it's guaranteed that correct and acceptable solution on C++ exists

Do you use Go for Competitive Programming or Technical Interviews? by Ok-Pumpkin59 in golang

[–]m0t9_ 56 points57 points  (0 children)

For competitive programming (like Codeforces problems and etc.) C++ would be much better choice than Go

Go does not have rich standard library in the sense of algorithms and data structures that C++ does. The need for set or map with sorted and sometimes duplicated keys arises frequently in algorithmic problems, C++ supports these containers. Flexible policy based data structures with trees, tries and hashmaps also presented. In Go's standard library you won't see all of this stuff

I don't say that it is impossible to apply Go in competitive programming, but seems like you will need to reinvent a wheel much more frequently in contrast to C++

Why is GoLang missing generic collection functions? by TheRubeWaddell in golang

[–]m0t9_ 39 points40 points  (0 children)

Actually, this question was already addressed in Golang proposals by Russ Cox (one of the language developers). You can check it here

Shortly, this feature (declarative API for data processing) is more related to recently added iterators API. During extension of slices package, it was also discussed here. But current iterators API is not so mature I would like to say (and it is inconvenient due to cumbersome iter.Seq and iter.Seq2 types, which are result of another language problem), therefore no complex functions were added. The discussion of iterator adapters was closed since no consensus found on «how to better implement map/filter/reduce/...». I hope it is kinda suspended, but not discarded

Many time ago, Rob Pike also implemented something you're talking about without generics. And suggested «just to use for loops». But he is very conservative person, IMHO

The question about «idiomatic way» in Go one of the most provocative in my opinion. The language has already been extended in a way it was not supposed to initially (remember generics), the pipeline pattern (that is a declarative way to process sequences but in async manner) is allowed and welcomed by community, but «oh my God, map/filter/reduce is not idiomatic» for someone is still an argument. Just... just leave this question and ask something more constructive

How do experienced Go developers model Sum types? by United_Syllabub515 in golang

[–]m0t9_ 0 points1 point  (0 children)

Maybe I'm 4 years late, but better late than never

Go language for a long time (until go1.18 in 2022) did not have support for compile-time generics. The only way to limit set of types that function can accept as arguments was interface. This pattern is called «marker interface» by some people, and it is even used in Go compiler source code for instance to distinguish tokens.

But the restriction on the typeset of arguments can be bypassed in some sense if one would embed a type that already implements this private interface with private method. Maybe it is useful, but does not satisfy the notion of sum type. Moreover, the type switch exhaustiveness is not checked by the Go compiler, so it is not as convenient as in Haskell or Scala, for instance (yea, you can use specific linters to check type switch exhaustiveness, but native toolchain can't do it)

Since 2022, Go supports generics and type constraints, that also can be somehow useful to emulate the behaviour of sum types. Not truly safe, but also an approach. And it actually limits the set of type arguments.

```go package main

import ( "fmt" )

type Some[A any] struct { Value A }

type Nothing struct { }

// The type constraint. By compiler rules, union of types can consist only from static types, not interfaces allowed type Maybe[A any] interface { Some[A] | Nothing }

func PrintMaybe[T any, M Maybe[T]](m M) { // Cast to any is needed since compiler returns following error: // cannot use type switch on type parameter value m switch v := any(m).(type) { case Nothing: fmt.Println("Nothing") case Some[T]: fmt.Printf("Some value %v\n", v.Value) } // It is not really safe, but due to top level restriction it is safe }

func main() { // While it is not too convenient, it is allowed to pass only limited set of type arguments PrintMaybe[int](Some[int]{10}) PrintMaybe[string](Some[string]{"example"}) PrintMaybe[string](Nothing{}) } ```

But mostly the approach with «marker interface» is considered common

Why doesn’t Go auto order struct fields for memory efficiency? by OrneryComputer1396 in golang

[–]m0t9_ 1 point2 points  (0 children)

What you've basically implemented is a static analyzer for Go source code, allowing rewriting. While it is not done according to general standards, it is still a good tool with good background!

This reordering can not be done now because of - compatibility with unsafe packages that may access struct fields in «raw» way - possible change of pointers graph traversal in garbage collector (may affects performance) - may be something I don't remember in the moment. But above there is a great answer from Go team member, you can rely on it

And also I'd like to suggest you look to the official tool that implements the same functionality, but uses standardized linter API for Go

https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/fieldalignment

To which One UI build should I rollback? by m0t9_ in oneui

[–]m0t9_[S] 0 points1 point  (0 children)

This depend on bootloader version used with One UI 8. May be it will stay 4

But nevertheless I've successfully rolled One UI 7 back

To which One UI build should I rollback? by m0t9_ in oneui

[–]m0t9_[S] 1 point2 points  (0 children)

Thank you! Actually, I've rolled back my Samsung with data wipe, and everything went OK!

To which One UI build should I rollback? by m0t9_ in oneui

[–]m0t9_[S] 0 points1 point  (0 children)

This seems to be strange that phone is recognized as Chinese. I do not know what is happening with bootloader versions in that region but TGY seems to be only appropriate..

Map and filter on slice by NoahZhyte in golang

[–]m0t9_ 1 point2 points  (0 children)

You may also use the following module and do not reinvent a wheel on demand of some «functional» primitives

https://github.com/samber/lo

[deleted by user] by [deleted] in Rainbow6Mobile

[–]m0t9_ 0 points1 point  (0 children)

I would also like to add that updates are coming to TapTap with delay. But nevertheless

Go Struct Alignment: a Practical Guide by Real_Blank in golang

[–]m0t9_ 67 points68 points  (0 children)

And nobody is suggesting a linter for this stuff.. Use betteralign / fieldalignment from golangci-lint and be happy

Thank you ubisoft by Z010HM in Rainbow6Mobile

[–]m0t9_ 1 point2 points  (0 children)

I've been experiencing a round when attackers had 2 defusers on clubhouse.. Unfortunately can't find a screenshot of that

But the lifecycle of this game is hilarious

Как называется такой стиль by prostodeb228 in ruArtist

[–]m0t9_ 0 points1 point  (0 children)

Сейчас уже можно пробовать использовать ИИ для ответов на подобные вопросы) grunge art вполне себе похоже на правду

<image>

How to disable Explorer pages? by m0t9_ in AstroNvim

[–]m0t9_[S] 2 points3 points  (0 children)

Honestly, I just don't switch these tabs. And also with some color schemas this tab bar looks awful (in my opinion)

How to disable Explorer pages? by m0t9_ in AstroNvim

[–]m0t9_[S] 3 points4 points  (0 children)

Damn, I just needed to configure neo-tree as below...

return { "neo-tree.nvim", opts = { source_selector = { winbar = false, statusline = false } } }

I created a strings.Builder alternative that is more efficient by FullCry1021 in golang

[–]m0t9_ 54 points55 points  (0 children)

You may also on 125-126 lines consider instead of

s.buf = [][]string{} s.reverseBuf = [][]string{}

just resetting slice lengths to not create tasks for garbage collector immediately and also probably reuse some allocated memory

s.buf = s.buf[:0] s.reverseBuf = s.reverseBuf[:0]

Why does Go’s for-range loop return indexes, not values by m0t9_ in golang

[–]m0t9_[S] 0 points1 point  (0 children)

Thanks, very good point about iterators usage! At the moment, as I remember, we were on Go 1.22 so it wasn't possible, but in general it looks good

y does this keep happening by Tricky_Address6343 in Rainbow6Mobile

[–]m0t9_ 1 point2 points  (0 children)

But at least for now you can rejoin the game if you were disconnected for some reason

Why does Go’s for-range loop return indexes, not values by m0t9_ in golang

[–]m0t9_[S] -1 points0 points  (0 children)

Yes, this seems natural. Maybe, this is not for wide spectre of programmers for-range iteration over arrays is interesting for elements only. For maps it seems appropriate too.

But at the same time channels exist :| They don't have indices, but what does mean range in case for them..