4 ms·
missing constructs like list comprehensions, dynamic typing, strong support for literal data, ability to treat user-defined types just like the built-ins, etc.
by stcredzero 13y ago
missing constructs like list comprehensions, dynamic typing, strong support for literal data, ability to treat user-defined types just like the built-ins, etc.
Of those, I only see comprehensions as something that's severely lacking, though I am not a Python guru by any measure. Dynamic typing: Go has duck typing, which gives some of the same benefits. Different refactoring strategies that take advantage of duck typing over other things you'd do with dynamic languages (like just substituting an object of a different type willy-nilly) will probably make up for the rest. I don't see strong support for literal data as a big productivity gain. Go also does a rather good job of treating user defined types like the built-ins and vice-versa, with a few exceptions like maps.
I didn't experience the claims of "Go is just as good as Python for prototyping", as someone with a fair amount of Python experience.
A lot of your competence with Python for prototyping probably has to do with your competence with Python. A lot of the advantage of Go is what it doesn't have. It's a much simpler system, so it's easier to design around, especially as one needs to get closer to the metal.
- nostrademons 13y agoThe use-case for dynamic typing was that I was decoding a large JSON data structure that could easily have thousands of different fields nested 10+ levels deep. Go's standard json library usually recommends that you define a struct type to hold the result of the decode, tagging field names with the `json` annotation. This obviously doesn't work when you only care about a few dozen of the several thousand possible fields. There is fortunately an escape hatch where you can declare a field as interface{} to say "Any type of data goes here; I'll downcast it later, and just trust me on the type", but then you have to litter your code with downcasts. Python just hands you back a dict of lists, and you pull out the information you want, no type declarations needed. The "user-defined types like built-ins" lets you build libraries where you can use the basic language structures on the data structure itself, without having to convert to an intermediate form. For example, the Python bindings to Amazon S3 let you access files through dictionary notation. BeautifulSoup lets you iterate over child nodes with a for loop, or access attributes as a dict. NumPy lets you use standard arithmetic operators on matrices. Judicious use of this in libraries makes the resulting code much briefer.
- agentS 13y agoNote on encoding/json: you only need to mention the fields you care about. If there are extra fields, the parser will just scan past them.
- sagichmal 13y ago> I was decoding a large JSON data structure that could > easily have thousands of different fields nested 10+ > levels deep. Go's standard json library usually > recommends that you define a struct type to hold the > result of the decode, tagging field names with the > `json` annotation. This obviously doesn't work when you > only care about a few dozen of the several thousand > possible fields. Sure it does! type Response struct { LevelOne map[string]struct{ LevelTwo map[int]struct{ Value string `json:"eventual_value"` } `json:"level_two"` } `json:"level_one"` } The response can have way more fields than just the ones you declare in your struct.
- nostrademons 13y agoCompared to the Python version of: response['level_one']['level_two']['eventual_value'] ? I did ignore fields that I wasn't interested in; however, you do at least have to declare all the intermediate structs in the tree. With 10-ish levels of nesting, that's a lot of boilerplate; even in your example with 3 levels, you've still got 6 lines of code for what's a one-liner in Python. It wouldn't be as much of a problem for a production system where you define your data structures once and then expect to amortize them over many, many changes. But I was prototyping, and the point of prototyping is to not spend time on boilerplate that isn't necessary to prove out your concept. A few hundred lines of type declarations just so I could decode JSON isn't exactly convenient.
- sagichmal 13y agoLines of code in type declarations isn't an interesting metric. Type safety, however, is.
- dscrd 13y ago>A lot of the advantage of Go is what it doesn't have. It's a much simpler system, so it's easier to design around, especially as one needs to get closer to the metal. Go doesn't have a REPL and that is objectively a serious dent on effective prototyping.