News for hackers. Stuff that matters.
Re:Green vs. Brown Programming Languages by ikiris on Thursday April 22, 2021 @08:39PM (#26909804)
This sounds like really bad code was allowed to be checked in, not the fault of the language. You can make terrible code in almost any language.

The above does not match my experience in maintaining large go codebases because of proper code reviews and expectation of writing maintainable code.

Re:Green vs. Brown Programming Languages by gher-shyu3i on Thursday April 22, 2021 @09:22PM (#26910065)
Nope, we have a very rigorous linting and review process. It's the shortcomings of the language.
Re:Green vs. Brown Programming Languages by ikiris on Friday April 23, 2021 @04:02PM (#26918590)
how are your complaints about your bad variable names shortcomings of the language and not the code you accept?
Re:Green vs. Brown Programming Languages by gher-shyu3i on Friday April 23, 2021 @06:14PM (#26919830)
Because it's literally in the standard library of golang, and everyone copies its style.
Re:Green vs. Brown Programming Languages by majewsky on Friday April 23, 2021 @09:45PM (#26921485)
There is no law that requires the use of the same variable naming style as std. Also,

> interface{} everywhere because of no generics

It would be good to know the domain here. Looking at my own fair share of Go code in productive systems (probably around 100-200 KLOC, written over the last 6 years), interface{} is really really rare. It appears in some library functions which genuinely accept basically any type, in the same way as json.Marshal(), fmt.Printf() or sql.Stmt.Execute() in std.

Other than that, I don't think I've ever had a case where I used interface{} instead of defining a more specific interface (plus adapter types to implement that interface on foreign types if necessary).

The only big mess that I've come across in Go land is kubernetes/client-go. I can't wait for generics to replace this metastasizing heap of autogenerated code.

Re:Green vs. Brown Programming Languages by gher-shyu3i on Saturday April 24, 2021 @07:31AM (#26924129)
> There is no law that requires the use of the same variable naming style as std. Also,

While that's technically true, it doesn't work out in practice because people look to the standard library as "the way" to write golang. It's basically an implied rule and I haven't seen anyone not folllow it so far.

> It would be good to know the domain here

Both infrastructure level work as well as CRUD type work.

> interface{} is really really rare

We have to use them everywhere for things like JSON parsing, config file handling, and pagerduty integration. Not to mention wrappers around SQL handling (e.g. batch inserts, pagination, etc.)

Generics will fix some things in the language, but not all. There are too many issues with it like the ones I already mentioned. It's still a very cludgy language to work with.

Re:Green vs. Brown Programming Languages by majewsky on Sunday April 25, 2021 @01:32PM (#26934591)
> JSON parsing, config file handling

I assume you're not referring to things like json.Marshal(), where the function argument is legitimately of type interface{} since it really accepts any value.

Hence I'm going to assume that you're referring to situations where a value can have one of multiple types (e.g. a float value that sometimes gets provided as a string). It's true that people sometimes unmarshal into interface{} and then type-assert in those scenarios, but that use of interface{} is a code smell that should be flagged in review. The proper way is to unmarshal into a custom type with a json.Unmarshaler implementation that accepts all possible input formats (and vice versa for json.Marshaler if encoding is required). This is a real-world example from one of my codebases: https://github.com/sapcc/limes/blob/d833228e976ac1ddc4b95779...

Re:Green vs. Brown Programming Languages by gher-shyu3i on Wednesday April 28, 2021 @10:11AM (#26969563)
Algebraic types would solve the issue in the example you're giving. However, those don't exist in golang either.
Re:Green vs. Brown Programming Languages by ikiris on Saturday April 24, 2021 @05:10PM (#26928280)
Having worked with the people doing those standard libraries, you're pulling justifications out of your butt for bad practices.

Just as a start: variables names should always be clear by context. You only see the one letter ones if its literally the next line or similar use case. Also, bare interface{} should basically never be the case for a function signature.

None of the code you've described thus far would pass a proper review.

Re:Green vs. Brown Programming Languages by gher-shyu3i on Wednesday April 28, 2021 @10:14AM (#26969590)
Code bases in reality still do what I'm describing, and they pass code reviews. Kubernetes is one example of the atrocities caused by the language.