News for hackers. Stuff that matters.
Re:New case studies about Google’s use of Go by andykx on Friday August 28, 2020 @01:17AM (#24301576)
Would most people actually do that? That example seems like pretty idiomatic Go. I imagine junior developers would write that.
Re:New case studies about Google’s use of Go by erik_seaberg on Friday August 28, 2020 @01:50AM (#24301736)
I would typically expect

  anyBlue := false
  for _, c in range col {
          ready, err := c.IsReady()
          if err != nil {
                  return nil, fmt.Errorf("isReady failed: %v", err)
          }
          if !ready {
                  continue
          }
          x, err := ConvertToX(c)
          if err != nil {
                  return nil, fmt.Errorf("convertToX failed: %v", err)
          }
          color, err := x.GetColor()
          if err != nil {
                  return nil, fmt.Errorf("getColor failed: %v", err)
          }
          if color == BLUE {
                  anyBlue = true
                  break
          }
  }
which badly obscures what’s going on but demands no cleverness at all (except that some might forget the “break” and still get the right answer).
Re:New case studies about Google’s use of Go by tmerr on Friday August 28, 2020 @09:34PM (#24312489)
If IsReady, ConvertToX, and GetColor can return errors then this isn't that far off. But then you're not making an apples to apples comparison. You would have to extend your functional example so that it also handles errors. Unless it already does, and I am missing something.
Re:New case studies about Google’s use of Go by erik_seaberg on Saturday August 29, 2020 @05:28PM (#24319562)
What I wrote should be pretty close to valid Scala, which handles exceptions. I can imagine wanting to skip an isReady failure, which looks like

  col.filter(c => Try(c.isReady).getOrElse(false))
  .map(convertToX).any(_.color == BLUE)
Re:New case studies about Google’s use of Go by tmerr on Monday August 31, 2020 @08:30AM (#24330755)
I see. Then in part the comparison is showing off exception handling, not FP.

Rust is a good example of functional lang without exceptions (panics aside).

In Rust there are many cases where I could use FP but opt not to because it can make error handling more awkward. For example to collect the result of a map operation to a vector, and if there is an error along the way you want to abort the entire operation. In functional this means collecting to a Result<Vec<T>>. Not sure if I'm just tired today but I can think of how to do it in 5 seconds with a loop. I suspect functional solution would be uglier.

Re:New case studies about Google’s use of Go by steveklabnik on Monday August 31, 2020 @09:35AM (#24331305)
Rust’s collect will do this for you. It’s even an example in the documentation.
Re:New case studies about Google’s use of Go by tmerr on Monday August 31, 2020 @10:05AM (#24331558)
Thanks! I learned something new.:)

https://doc.rust-lang.org/stable/rust-by-example/error/iter_...

This is easy to miss if you are mainly reading reference docs. I probably read the getting started guide at a time before there was a section on it.

My other comment in this thread comes to mind https://news.ycombinator.com/item?id=24300057

Re:New case studies about Google’s use of Go by steveklabnik on Monday August 31, 2020 @10:22AM (#24331724)
I was thinking of the final example in https://doc.rust-lang.org/stable/std/iter/trait.Iterator.htm... , glad we have it in both places!

I don’t personally really agree with what you’ve said, but that’s fine. Different people perceive things differently.

Re:New case studies about Google’s use of Go by tmerr on Monday August 31, 2020 @12:25PM (#24333002)
No problems. There are enough dimensions involved in what makes a language good that Im pretty sure I could rationalize why any language is better than another, measured along only one of them.

Robustness. Speed. Simplicity. Easiness. Conciseness. Writability. Readability.

Hard to tell which are independent vs correlated, let alone how they factor into productivity. And productivity is also a function of the kind of problem you work on.