TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

What Python developers need to know before migrating to Go

120 pointsby Nogwateralmost 12 years ago

20 comments

beeringalmost 12 years ago
Some of the things they listed are dubious...<p><i></i>Writing to a file, there’s File.Write([]byte) and File.WriteString(string) – a bit of a departure for Python developers who are used to the Python zen of having one way to do something<i></i><p>Simply because it&#x27;s not currently feasible to write a function that can have multiple type signatures (via overloading, generics, etc.).<p><i></i>Going between []byte and string. regexp uses []byte (they’re mutable). It makes sense, but it’s annoying all the same having to cast &amp; re-cast some variables.<i></i><p>There are actually two different versions of each regexp function: one for strings, one for []byte. Maybe they&#x27;re using a different version?<p><i></i>No tuples, have to write your own structs or use slices (arrays)<i></i><p>Actually, you can declare a fixed-length array as a type. So if you need to return a triple of ints, you can declare the return type to be [3]int and have the type system check that you&#x27;re actually returning an array of ints of length 3.<p>Similarly, a lot of the other bullet points are natural results of having a static type system.<p>I was expecting more points like:<p>* you can&#x27;t monkey-patch functions into external libraries like you can with Python modules * no generics, so you can&#x27;t write a generic &quot;map&quot; function, for example * no preemptive multitasking, so one goroutine can wedge the entire program * passing around arrays and structs is by value, leading to unexpected allocation and memory usage * pointers
评论 #6009407 未加载
评论 #6009781 未加载
n1ghtm4nalmost 12 years ago
Some thoughts after spending ~100 hours with Go.<p>- Function overloading is a major convenience that you will miss. There are differently named versions of every function and you will call the wrong version with the wrong arguments <i>all the time</i>. The number of functions in the standard library could be reduced by at least 1&#x2F;4 if they&#x27;d got this right. The official FAQ (<a href="http://golang.org/doc/faq#overloading" rel="nofollow">http:&#x2F;&#x2F;golang.org&#x2F;doc&#x2F;faq#overloading</a>) explains that leaving out overloading is &quot;simpler&quot;, meaning <i>simpler for them</i>.<p>- Default parameters are a major convenience that you will miss. Using strings.Replace() to remove some chars from a string? Don&#x27;t forget to pass the -1 at the end, asshole! The -1 says don&#x27;t put a limit on the number of replacements. In Python there would be a max=None default parameter and this would never bite anyone.<p>- No named arguments, because fuck readability.<p>- Forcing me to handle errors is great. Having 20 different ways to do it is not great. Examples: fmt.Errorf(), fmt.Fprintf(os.Stderr), errors.New(), log.Fatal(), log.Fatalf(), log.Fatalln(), panic&#x2F;recover...<p>- Using &amp;&amp; and || for logical operators in this day and age is just ridiculous. Why do people keep inventing programming languages as if Python doesn&#x27;t exist?<p>- Don&#x27;t think that just because the Unicode guys invented Go that Unicode is going to be easy. Their solution is not to create an airtight abstraction layer between chars (or &quot;runes&quot; WTF?) and integers. Their solution is to provide almost no abstraction and force you to deal with the inherent integer-ness of all characters. Example:<p>In Python:<p><pre><code> len(&quot;нєℓℓσ&quot;) # 5, because there are 5 chars</code></pre> In Go:<p><pre><code> len(&quot;нєℓℓσ&quot;) &#x2F;&#x2F; 12, because there are 12 bytes utf8.RuneCountInString(&quot;нєℓℓσ&quot;) &#x2F;&#x2F; 5, plz kill me i am an abomination </code></pre> tl;dr If you&#x27;re inventing a programming language for human beings (not UNIX gods), try it out on a group of smart high school students first. It will be a humbling experience.
评论 #6010694 未加载
评论 #6010231 未加载
评论 #6010395 未加载
评论 #6014037 未加载
评论 #6011202 未加载
alok-galmost 12 years ago
&gt;&gt; No built-in type for sets (have to use maps and test for existence)<p>Is there any particular reason for this? Sets are so fundamental to mathematics and beyond that I am concerned right away about this. Sure you could use a map as a replacement, but what happens to &quot;user experience&quot;?<p>I do not get this for other languages as well. Data structures that are present in nearly all computer science books are often not built into the language or standard libraries, like trees, graphs. Reasoning given is that some other data structure could serve as a replacement (never mind that the programmer&#x27;s intentions are not directly reflected in the code anymore), or because it is considered too removed from practical usage, or because some third-party library includes it. I do not buy any of these arguments.
评论 #6008696 未加载
评论 #6008700 未加载
评论 #6008692 未加载
评论 #6013746 未加载
评论 #6009432 未加载
评论 #6008987 未加载
phren0logyalmost 12 years ago
I can&#x27;t help but feel like criticisms along the lines of &quot;you have to be more precise with what you want, because unlike python it won&#x27;t let you get away with blah&quot; and praise like &quot;it seems to run correctly as soon as it compiles&quot; are two sides of the same coin.
评论 #6008548 未加载
mratzloffalmost 12 years ago
Previous discussions:<p>- <a href="https://news.ycombinator.com/item?id=5600883" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=5600883</a><p>- <a href="https://news.ycombinator.com/item?id=5596422" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=5596422</a>
stcredzeroalmost 12 years ago
Many of the things he says he misses from Python, I would rather not have in production code. Heterogenous dictionaries are often objects that should have been, with no encapsulation and a high degree of implicitness that makes them hard to refactor later.
pallinderalmost 12 years ago
&quot;If you’re using JSON and your JSON is a mix of types, goooooood luck. You’ll have to create a custom struct that matches the format of your JSON blob, and then Unmarshall the raw json into an instance of your custom struct. Much more work than just obj = json.loads(json_blob) like we’re used to in Python land.&quot;<p>Could just load it into a map[string]interface{} and then just make sure he does type assertion on the value before using it.
hvsalmost 12 years ago
This is purely anecdotal on my part, but I&#x27;ve been working on a project for a few months and I&#x27;ve been developing it in Go and it has just been a pleasure to use. It&#x27;s like C with the edges smoothed out using Python sandpaper.
Osmiumalmost 12 years ago
Is there a decent numpy&#x2F;scipy equivalent for Go yet? By which I mean an easy way to manipulate matrices, complex numbers perform discrete Fourier transforms and the like.
评论 #6009004 未加载
16salmost 12 years ago
<i>&quot;No built-in type for sets (have to use maps and test for existence)... In absence of sets, have to write your own intersection, union etc. methods&quot;</i><p>In my mind, a map is a set. They are both Associative containers. It&#x27;s just that the key and value can be different things in a map while in a set, the key and value are the same thing.<p>Edit: I speak from a strong C++ viewpoint, but maybe Go is not like that (I&#x27;m not sure why it would not be): <a href="https://en.wikipedia.org/wiki/Associative_containers_%28C%2B%2B%29" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Associative_containers_%28C%2B...</a>
评论 #6011101 未加载
rlpbalmost 12 years ago
Has anyone tried to integrate Go with Python?<p>Right now, optimizing Python code by replacing critical sections with C works really well and isn&#x27;t too hard to write or distribute.<p>How well would tooling around doing the same thing with Go work?
评论 #6008973 未加载
评论 #6008847 未加载
评论 #6010468 未加载
robdoherty2almost 12 years ago
Any HN readers of this post have any similar experience?<p>I know the bright team over at bit.ly made a successful switch from python to go-- anyone else?<p>The more I hear about go, the more I like it.
评论 #6008518 未加载
评论 #6008284 未加载
评论 #6008567 未加载
评论 #6009324 未加载
Arnoralmost 12 years ago
Some of the items mentioned in that list are the reason why:<p>&quot;The code you write with Go just seems to be correct.&quot;<p>e.g.<p>- Having to always check errors (or at least explicitly ignore them) * By the way, do this anyway. It&#x27;s really nice when every error in your app is handled. Since I&#x27;ve started with Go for a personal project, I&#x27;ve used a similar approach in my <i>sigh</i> PHP project so every error now has an explanation and suggestion.<p>-Can’t have variables&#x2F;packages that aren’t used so to test simple things requires sometimes commenting out lines<p>-Python is more forgiving. You can take slices of strings using indexes that are out of range and it won’t complain. You can take negative slices – not Go.
mjschultzalmost 12 years ago
Here&#x27;s a previous discussion of this post as well: <a href="https://news.ycombinator.com/item?id=5600883" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=5600883</a>
pekkalmost 12 years ago
&#x27;migrating to Go&#x27; implies that Go has the same advantages as Python, which is not really true.
smegelalmost 12 years ago
&gt; The map&#x2F;reduce idiom stinks in Python.<p>Actually multi processing has a reasonable implementation.
DannoHungalmost 12 years ago
I thought Go had union types? Do those not work... normally?
评论 #6008559 未加载
callesggalmost 12 years ago
basicly most of the difrences that is mentioned comes down to that one of the languages is compiled.
rwedf67almost 12 years ago
so you still trust the google compiler for your business critical apps do you? haha
评论 #6011151 未加载
评论 #6010810 未加载
13b9f227ecf0almost 12 years ago
I keep seeing articles about Go where Python developers seem to be shocked to discover that interpreted dynamically typed languages are very slow. This wasn&#x27;t obvious from the get-go? Practically anything not disk bound will be many, many times faster in C++ or whatever.