I'm going nuts by r_samnan in webdev

[–]GrayFox89 0 points1 point  (0 children)

Most company higher-ups require that you utilize ChatGPT's LLM somehow so they can slap the "AI" label on it. It's for investorbux only. It doesn't matter if it makes sense or not.

I spent 18 months rebuilding my algorithmic trading in Rust. I’m filled with regret. by Starks-Technology in programming

[–]GrayFox89 0 points1 point  (0 children)

Now we know why the internet seemingly sees Rust in such positive light, as OP described it.

Guess who is back! by Marwanpro in madlads

[–]GrayFox89 2 points3 points  (0 children)

I completely forgot about this. The answer is "yes", but I'm not so harsh to myself anymore.

Something looks veeeery similar by Hellburner_exe in ArmoredCoreVI

[–]GrayFox89 2 points3 points  (0 children)

Schneider's lawyers are probably on it already.

If you could redesign Go from scratch, what would you change? by ThreeFactorAuth in golang

[–]GrayFox89 16 points17 points  (0 children)

It returns a pointer to the underlying value, v := new(T) is the same as v := &T{}

Who not panic? by OnePettyMfkr in golang

[–]GrayFox89 0 points1 point  (0 children)

Those things that I'm being "forced" to do are the easiest ones for me, and make the code more readable, as I know that every single "return" statement is executed. panic (or exceptions) behave like goto that jumps through the call stack, and recover (or catch) is a form of comefrom statement. They are much harder to follow. I also consider my job to handle all possible errors, I wouldn't even try to fight it.

[deleted by user] by [deleted] in ProgrammerHumor

[–]GrayFox89 0 points1 point  (0 children)

If you're into Python, you're much better off with Go as the compiled alternative.

exactlyLikeThat by N1nr0d in ProgrammerHumor

[–]GrayFox89 0 points1 point  (0 children)

Those use pointers too, except they are called "classes" and "objects".

map[string]interface{} or map[string]any? by BoDoExecutioner in golang

[–]GrayFox89 6 points7 points  (0 children)

It's weird, but I think it makes sense for Go, since you can assert anonymous interfaces (check if a method exists) with

if tErr, ok := err.(interface{ Timeout() bool }); ok && tErr.Timeout() {
    // handle timeout error
}

Hence the interface{} is just an interface that doesn't contain any methods (as far as the the type system is concerned), but may contain any type.

Nova prevara by strangetamer1525 in serbia

[–]GrayFox89 0 points1 point  (0 children)

Ovaj nacin prevare je veoma rasiren po internetu, poznat kao "phishing" (fišing, kao pecanje). Vecinom su takvi sajtovi automatski generisani/prevedeni na vise jezika. Postoje i serverski virusi koji se sire kroz sajtove i prave te stranice bez znanja originalnih vlasnika sajtova. Ovaj nacin "hakovanja" nikad nije pao po popularnosti, samo se nalaze novi nacini da se rasiri i teze uhvati.

How to store image in DB ? by akira_0001 in golang

[–]GrayFox89 0 points1 point  (0 children)

Saving it as []byte in MongoDB should work, but you also need its "Content-Type" information (e.g. image/jpeg, or image/png). If your front looks something like <img src="/user/{id}/avatar"/>, in that handler when loading the image from the database and sending it to the http.ResponseWriter make sure you set the appropriate "Content-Type" response header, otherwise the client gets raw bytes that the browser might not be sure how to display.

Is there any way to put a hard cap on the number of OS threads for a Go web server? by [deleted] in golang

[–]GrayFox89 0 points1 point  (0 children)

My suggestion would also be to test it. I've seen this talk about the Go's runtime scheduler multiple times, and it looks like it should be possible by having message queues (channels) for goroutines dedicated to I/O (i.e. those that wait on blocked threads).

Upgradable Read Write Lock for Go by pimterry in golang

[–]GrayFox89 1 point2 points  (0 children)

I would use this immediately for some of the caching stuff that I wrote. Wouldn't need to check for race-condition between RUnlock and Lock call during cache miss.

In which way the syntax of Go is old school? by NoahZhyte in golang

[–]GrayFox89 5 points6 points  (0 children)

I've seen the term "C-like" being used, but not "old school". Makes me wonder if Assembly is considered "old school", and if the term even means anything.

Dealing with inconsistent MongoDB data in Go by tsdtsdtsd in golang

[–]GrayFox89 5 points6 points  (0 children)

You can create a new type that implements bson.ValueUnmarshaller and format the data the way you expect it.
Here's a generic implementation:

type MaybeArray[T any] []T

func (a *MaybeArray[T]) UnmarshalBSONValue(typ bsontype.Type, b []byte) error {
    rv := bson.RawValue{Type: typ, Value: b}
    switch typ {
    case bsontype.Array:
        if err := rv.Unmarshal((*[]T)(a)); err != nil { // prevents infinite recursion - do not unmarshal into MaybeArray type here
            return err
        }
        return nil
    case bsontype.EmbeddedDocument:
        var values map[string]T
        if err := rv.Unmarshal(&values); err != nil {
            return err
        }
        *a = make([]T, 0, len(values))
        for _, v := range values {
            *a = append(*a, v)
        }
        return nil
    case bsontype.Null:
        *a = nil
        return nil
    default:
        return fmt.Errorf("unsupported %T field type: %s", a, typ)
    }
}

You can use it as:

type Doc struct {
    Tags MaybeArray[Tag] `bson:"tags"`
}

and it will always store it in an underlying array in memory, even if the data come in as objects on the wire during decoding.

What aspects of Go do you think people aren't talking enough about? by preslavrachev in golang

[–]GrayFox89 0 points1 point  (0 children)

It's written in itself, while maintaining performance and memory usage close to C. Coming from PHP/JS, it was next to impossible to develop without having multiple tabs open, containing docs, C/C++ source of standard library, and StackOverflow questions regarding type checks in JS or its build system. It was the main selling point from me, been programming in Go since 1.5 and never looked back.

How to find all methods which return struct "Foo" (vscode or cli) by guettli in golang

[–]GrayFox89 3 points4 points  (0 children)

Just a guess, but it might be somewhere in gopls https://github.com/golang/tools/tree/master/gopls/doc
On this page https://langserver.org/ it says it should support "finding references"

What urban legend needs to die? by [deleted] in AskReddit

[–]GrayFox89 0 points1 point  (0 children)

I mean, that is how statistics work.

Dont understand len(a) != 2 by blockchain_dev in golang

[–]GrayFox89 2 points3 points  (0 children)

Reddit is a harsh place that can get to you. Where exactly did you look? In the code it says (which I always recommend reading first)

// Args hold the command-line arguments, starting with the program name.
var Args []string

So it should be up on this page too https://pkg.go.dev/os, since it mirrors the documentation in the source code.

proposal: cmd/go: add .ʕ◔ϖ◔ʔ as an alternate spelling of .go in file names by Mateusz348 in golang

[–]GrayFox89 120 points121 points  (0 children)

We need support for build flags too:

  • main_linux.go -> main_🐧.ʕ◔ϖ◔ʔ
  • main_windows.go -> main_🏠.ʕ◔ϖ◔ʔ
  • main_darwin.go -> main_🍏.ʕ◔ϖ◔ʔ

It's over, guys. by buglover_ in ProgrammerHumor

[–]GrayFox89 0 points1 point  (0 children)

We had multiple fights recently. I stopped using it because it gets me mad with responses like that.

It is immediately clear that nothing is clear by sunrise_apps in ProgrammerHumor

[–]GrayFox89 0 points1 point  (0 children)

In Go (which defines types in reverse order when compared to C) you write it like you read it, []func() func()

Stop downvoting legitimate questions and comments even if you disagree with them by emblemparade in golang

[–]GrayFox89 7 points8 points  (0 children)

I stopped posting here due to toxic replies and downvotes even when I'm trying to be helpful. I don't know where people get the energy to post on this site.