News for hackers. Stuff that matters.
Re:Show HN: Fo: An experimental language which adds generics... by gtt on Tuesday June 12, 2018 @02:12PM (#17296137)
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.
Re:Show HN: Fo: An experimental language which adds generics... by awb on Tuesday June 12, 2018 @02:56PM (#17296685)
Isn't interface{} a generic?
Re:Show HN: Fo: An experimental language which adds generics... by thanatos_dem on Tuesday June 12, 2018 @03:08PM (#17296813)
Noooooo! interface{} is a raw type. It’s like “Object” in java land. It has no meaning in its own right, and needs to be carefully checked whenever you want to actually use it. The proliferation of interface{} across the go ecosystem is really unfortunate, and will be hard to correct once generics are finally supported.

I haven’t dug too far into the Fo code yet, but I’d guess that it’s doing something akin to type erasure in Java, and adding conversions and type checks transparently when compiling down to a go binary. Sort of like how if you ever pop open a class file and dig into it, you’ll never see any references to generics. Everything compiles down to objects in the end with generated type checks.

Re:Show HN: Fo: An experimental language which adds generics... by weberc2 on Tuesday June 12, 2018 @07:00PM (#17298866)
Well, it is in the literal sense that it enables generic algorithms, just like the one, unnamed static type in all dynamic languages. But of course this is pedantry and no one really means this when talking about generics.
Re:Show HN: Fo: An experimental language which adds generics... by cowboysauce on Tuesday June 12, 2018 @03:11PM (#17296858)
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... by jj2 on Tuesday June 12, 2018 @03:35PM (#17297164)
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.
Re:Show HN: Fo: An experimental language which adds generics... by pionar on Tuesday June 12, 2018 @04:00PM (#17297416)
Generics (when used/implemented correctly) provide way more than just elimination of type assertions. It provides compile-time type safety, rather than runtime safety. It also provides elimination of the overhead (which isn't trivial, reflection is not inconsequential) and boilerplate code. It also allows you to use the same function/method for many different types without having to resort to boxing everything to an interface/object.
Re:Show HN: Fo: An experimental language which adds generics... by eropple on Tuesday June 12, 2018 @04:34PM (#17297719)
Depending on the implementation, too, generics can be more friendly in other ways. C# emits code for both value types and reference types when appropriate and uses the correct paths as needed.
Re:Show HN: Fo: An experimental language which adds generics... by tapirl on Wednesday June 13, 2018 @09:21AM (#17302765)
unsafe.Pointer is the equivalent of C void pointer. interface{} is Any of Object in some other languages.
Re:Show HN: Fo: An experimental language which adds generics... by andrewstuart2 on Tuesday June 12, 2018 @03:05PM (#17296778)
No, you have to use reflection to determine the type at runtime. Generics use the compiler to prove the type at compile time so that the runtime can forego the much-slower reflective code paths.
Re:Show HN: Fo: An experimental language which adds generics... by ajkjk on Tuesday June 12, 2018 @03:04PM (#17296769)
No? Generics are type-checked at compile time.
Re:Show HN: Fo: An experimental language which adds generics... by gowld on Tuesday June 12, 2018 @03:03PM (#17296762)
That's reflection not generics. It's mostly the same denotational semantics, but much less efficient performance.
Re:Show HN: Fo: An experimental language which adds generics... by mirkoadari on Tuesday June 12, 2018 @04:24PM (#17297634)
I think it's more than that. You wouldn't commit code that doesn't compile. Your entire organization, however, will troubleshoot the code that fails on runtime in production.
Re:Show HN: Fo: An experimental language which adds generics... by tree_of_item on Wednesday June 13, 2018 @01:43PM (#17305360)
It's not the same semantics at all. Using the top type is not even close to using a type parameter.
Re:Show HN: Fo: An experimental language which adds generics... by oweiler on Wednesday June 13, 2018 @04:15PM (#17306558)
Code wins arguments.