Live data from Hacker News

Show HN: Fo: An experimental language which adds generics on top of Go

github.com

41–50 of 125 posts

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#41
post #31
post #14

I liked certain aspects of Go, but lack of generics was a deal-breaker for me. You approached it a way better than I (and many others) did. Instead of arguing on forums you started writing code.

Isn't interface{} a generic?

No, interface {} is more like void pointers in C and C++ or Object in C# and Java. It can hold values of any type. One of the major selling points of actual generics is that they provide type safety, but interface {} doesn't provide that.

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#42
post #16

Interesting, now all you need to do is add exceptions :)

Golang already has an exceptions-equivalent construct in the shape of panic() and recover(): https://blog.golang.org/defer-panic-and-recover You’re free to write exception-full code using those constructs, although the community tends to use error return values for the most part.

panic() and recover() are not meant to be used like Java or C++ exceptions.

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#43

Interesting, now all you need to do is add exceptions :)

Perhaps. But if Go itself adds exceptions they're going to have to catch a MassDeveloperExodusException. The standard reason I see for people wanting exceptions in Go is because they're sick of writing the following: ```go thing, err := things.New() if err != nil { log.Fatalln(err.Error()) // Or `return err` } ``` But I would argue that it means they're not writing idiomatic go. A good reference for the value of erro…

Eh, rust’s result type has shown that you can do the same thing in way that is more type safe and more ergonomic.

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#44

Author here. I've been working on Fo part time for 4 months. Feel free to ask me anything.

Did you consider parameterized packages? The idea is you can declare a set of related objects/types/methods as well as have concrete type specific initialization. E.g.

  package stack[t]
  type Type []t
  func New() Type { return Type{} }
  ...
  
Then it can be used so:

  import s “stack”[int]
  var s1 = s.New()

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#45

Earlier quoted context omitted.

Perhaps. But if Go itself adds exceptions they're going to have to catch a MassDeveloperExodusException. The standard reason I see for people wanting exceptions in Go is because they're sick of writing the following: ```go thing, err := things.New() if err != nil { log.Fatalln(err.Error()) // Or `return err` } ``` But I would argue that it means they're not writing idiomatic go. A good reference for the value of erro…

Eh, rust’s result type has shown that you can do the same thing in way that is more type safe and more ergonomic.

Sure, if I had proper sum types + pattern matching in go that'd be great. I'm just saying that I'd prefer the status quo over adding exceptions specifically.

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#46
post #44

Author here. I've been working on Fo part time for 4 months. Feel free to ask me anything.

Did you consider parameterized packages? The idea is you can declare a set of related objects/types/methods as well as have concrete type specific initialization. E.g. package stack[t] type Type []t func New() Type { return Type{} } ... Then it can be used so: import s “stack”[int] var s1 = s.New()

Just as additional info to others, this is how Ada, Modula-2 and Modula-3 generics kind of work.

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#47

Earlier quoted context omitted.

Eh, rust’s result type has shown that you can do the same thing in way that is more type safe and more ergonomic.

Sure, if I had proper sum types + pattern matching in go that'd be great. I'm just saying that I'd prefer the status quo over adding exceptions specifically.

Oh for sure.

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#50
post #31

Earlier quoted context omitted.

Isn't interface{} a generic?

No, interface {} is more like void pointers in C and C++ or Object in C# and Java. It can hold values of any type. One of the major selling points of actual generics is that they provide type safety, but interface {} doesn't provide that.

Go type assertions are quite safe on the other hand, unlike C type casts. The only thing generics will do is to avoid that extra assertion step and the bit of overhead that's involved in that. You could argue wether it will actually increase readability of your code.
Post reply on HN