r/Python • • May 26 '14

Python 3 is killing Python

https://medium.com/@deliciousrobots/5d2ad703365d/
0 Upvotes

147 comments sorted by

View all comments

Show parent comments

1

u/ggtsu_00 May 26 '14

I keep hearing so many complaints about generics in go, but interface{} types serve that need pretty well for most cases.

For a tree you could have:

type Node struct {
    Left *Node
    Right *Node
    Data interface{}
}

4

u/flying-sheep May 26 '14

Type safety.

0

u/ggtsu_00 May 26 '14 edited May 26 '14

What is unsafe about it? You you still need to have type assertions before you can actually use interface{} object as an actual data type and the type assertions give you the type safety. It is not any less safe than a python equivalent if that is where you are coming from.

8

u/Categoria May 27 '14

Why have static types in a language where you need runtime checks to replace all but the simplest uses for a type system. Even java learned this lesson.

0

u/ggtsu_00 May 27 '14

That is also why handling unstructured Json objects with in languages like Java is a huge pain.

2

u/Categoria May 27 '14

Java is more verbose than necessary. For example in Scala there's https://github.com/mandubian/play-json-zipper this for example. But how is it more painful than Go? Json is a very simple type to represent, after all. Whatever Go has can be emulated by pre generics java. After all, their type systems would be equivalent modulo structural typing.