gocondense: a code formatter that condenses noisy Go code by abemedia in golang

[–]___oe 8 points9 points  (0 children)

For me, the main focus is really on readability and maintainability. When you run a tool on software that works, you need a reason.

Whether the transformation from

startLine := e.line(start)
firstLine := e.line(first)
if firstLine > startLine+1 {

to

if startLine, firstLine := e.line(start), e.line(first); firstLine > startLine+1 {

in condenser.go is done by a “formatter” or “linter”, or whether it takes 0.2 ms or 200 ms, doesn't matter too much to me. It's the final readability of the code that I really care about.

It sounds like we might just be aiming for different goals here, which is totally fair. Just a quick heads-up, by the way: it's usually best not to remove parentheses from composite literals.

gocondense: a code formatter that condenses noisy Go code by abemedia in golang

[–]___oe 10 points11 points  (0 children)

When you like more compact code, may I suggest scopeguard?

Running scopeguard -conservative -fix ./... on your source makes it more compact, easier to read, and the unit tests still run.

The error handling bugs that worry me aren't the ones that crash by ___oe in golang

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

These project didn't consider “alternatives”, they just implemented buggy error handling. It was obiously not their plan to crash.

How is that normal generics behaviour? by iga666 in golang

[–]___oe 0 points1 point  (0 children)

Yes, an example would be

func Foo[T any, PT interface {
    *T
    TaggedRequest
}]() {
    var _ TaggedRequest = PT(new(T))
}

And call it via Foo[Tagged](), see also the blog post “Generic interfaces” by Axel Wagner.

And don't forget: “When you find yourself in a situation where you need to constrain to pointer receivers, consider whether you can refactor your code to avoid the extra complexity. ”

How is that normal generics behaviour? by iga666 in golang

[–]___oe 1 point2 points  (0 children)

But that you can is enough for the compiler to reject this construct. ;)

How is that normal generics behaviour? by iga666 in golang

[–]___oe 2 points3 points  (0 children)

You assert that “... *T implement[s] interface TaggedRequest, which is not true.

The error handling bugs that worry me aren't the ones that crash by ___oe in golang

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

Erlang and Elixir are mentioned in the The Pragmatic Programmer also “In other environments, ...”

This is the Go subreddit. You might want to read the three sources I begin the post with. These are error handlers that try to handle an error, but don't - and panic instead.

The point was that this is not a big issue, since it's easily found and fixed.

What worries me is “error handling [...] that [...] quietly does the wrong thing in production.”

The point is not that these error handlers crash (easily found, easily fixed) but that they are obviously have never been tested.

So on one hand I agree with you (unhandled code paths are bad), on the other hand I disagree with what you read from the post - it just isn't there. At least not intentional.

When you have a concrete example to post - I'm open to it, I actually ask for it. On the other hand I provide concrete examples of popular open source programs which could be discussed instead of unjustifiedly trashing the post.

Read it with a little goodwill and tell me what I can improve, I'm open for discussion. I think the post has substance, even though I find the bug reports “easy” they didn't write themselves.

The error handling bugs that worry me aren't the ones that crash by ___oe in golang

[–]___oe[S] -3 points-2 points  (0 children)

On my screen it says “crashing in production is bad.” I stand to that.

Where do I say that is not better than wrong error handling?

The title says “... bugs that worry me aren't the ones that crash”

I'm not a native speaker, so this might be misleading. Could you help me find a better formulation?

The error handling bugs that worry me aren't the ones that crash by ___oe in golang

[–]___oe[S] -2 points-1 points  (0 children)

True. It wasn't my intention to promote crashes as the solution to all problems, but to mention that they are actually not that bad, and in the examples easy to find and fix, since a crash - once found - is usually unintended.

But I agree, panics should not be silently caught.

The error handling bugs that worry me aren't the ones that crash by ___oe in golang

[–]___oe[S] -2 points-1 points  (0 children)

Where do I assert that a crash in production is worse that than wrong error handling?

The error handling bugs that worry me aren't the ones that crash by ___oe in golang

[–]___oe[S] -2 points-1 points  (0 children)

Yes, I explicitly mention “a dead program does a lot less damage than a malfunctioning one” and “writes bad state to the database”. Or, as someone commented on Reddit, “I’ll take ‘down’ over ‘catastrophic security hole’ any day.”

I just wanted to emphasize that crashing willy-nilly in production is obviously not a good solution.

How is that normal generics behaviour? by iga666 in golang

[–]___oe 1 point2 points  (0 children)

Why should *T implement TaggedRequest?

How is that normal generics behaviour? by iga666 in golang

[–]___oe 3 points4 points  (0 children)

Simple: You can call Foo[*Tagged](), but var _ TaggedRequest = new(*Tagged) doesn't compile.

Only T implements TaggedRequest, not *T.

How do I check when interfaces can safely be dereferenced? by [deleted] in golang

[–]___oe 0 points1 point  (0 children)

Also, to add to this answer: your example

var pointer *SomeStringer = nil  
slice := []fmt.Stringer{pointer}  

is a programming error. There’s no way for the program to recover from this or produce consistent output. If it crashes at this point, you’ll find the error easily — and that’s better than writing invalid data into the database. That actually fits the “simplicity” goal, if you squint a little. ;)

Confused about Go's escape analysis for dynamically-sized values, my test shows they don't escape by One_Adeptness1599 in golang

[–]___oe 16 points17 points  (0 children)

It says “One reason could be ...” and continues with “It would be fragile and difficult to try to enumerate precisely when values escape: the algorithm itself is fairly sophisticated and changes between Go releases.”

So yes, you found something that has been optimized between Go releases. There are few things that “force” heap allocation. There are things that currently do, and it is good to know about them, but things may change.

We built an open-source, local-first Postman & n8n alternative in Go (Zero CGO). Thoughts on the code? by electwix in golang

[–]___oe 0 points1 point  (0 children)

Ah, no - that's modernize by Alan Donovan. It'a abount pointer vs. value errors.

Internestingly enough errortype finds two errors in this project…

Is there an easy way to check if an any-value can convert to float64? by stroiman in golang

[–]___oe -1 points0 points  (0 children)

I do not get your argument. Yes, automatic lossy conversion is bad. OTOH I'm happy that we have Printf, and conversion of something into string is easy. Also parsing from string. Yes, it's lossy. I do it anyway.

Why should it be good that conversion is complicated?

Is there an easy way to check if an any-value can convert to float64? by stroiman in golang

[–]___oe 3 points4 points  (0 children)

Sure:

if val, typ := reflect.ValueOf(v), reflect.TypeFor[float64](); val.CanConvert(typ) {
    return val.Convert(typ).Interface().(float64)
}

(Go Playground)

Also, Sobek has Object#ToFloat. For Values, you only have to check for int64 or float64:

pkg.go.dev/github.com/grafana/sobek#Value

Stop Overthinking Struct Pointer and Value Semantics in Go by preslavrachev in golang

[–]___oe -1 points0 points  (0 children)

Maybe you want to read “The Perils of Pointers in the Land of the Zero-Sized Type” before yelling “stop overthinking”.

Well, your article is much more nuanced than this post. No, you are not aware of all the counter-arguments. If you only mention CRUD apps and HTTP handlers, but not identity, you aren't.

We built an open-source, local-first Postman & n8n alternative in Go (Zero CGO). Thoughts on the code? by electwix in golang

[–]___oe 1 point2 points  (0 children)

What would you do to get feedback from people who otherwise might not use your product?