13 ms·
Goodbye Python, Hello Go
- slezyr 8y ago> I like having a single binary. I usually run code on EC2 machines to give my scripts closer network proximity to S3 and to our database. With Python, I have to ensure all the packages I need are installed on the remote machine, and that one of my coworkers hasn’t installed anything conflicting. pipenv
- gsibble 8y agoI've written in Python for ~13 years and I'm really enjoying Go. It's fast and its libraries (the few there are) seem to make a lot of sense. I don't think I would use it for daily scripting like the author, but for a large new project I would definitely pick Go over Python now.
- lmm 8y agoTry an ML-family language (e.g. OCaml, F#, or Rust) if you haven't already. You get the best of all worlds: expressiveness, safety and speed.
- doteka 8y agoI like the expressiveness of Rust in theory, but for the programs I write I don't feel like I get sufficient payoff for fighting the borrow checker, as compared to writing in Go. Would I be correct in saying OCaml is pretty much Rust without the borrow checker? I have no prior experience with the language.
- lmm 8y ago> Would I be correct in saying OCaml is pretty much Rust without the borrow checker? Yeah, it's very much on those lines, though the syntax is a bit more ML-style (Rust pushes a bit towards a C-like syntax). (I actually mostly use Scala myself these days, but I know the JVM is a dealbreaker for some people, and the design compromises for the sake of Java compatibility mean Scala is probably not the best choice for a first ML)
- a0 8y agoIf you want something closer to Rust, consider looking into Reason. It’s essentially OCaml with braces and semicolons.
- petre 8y agoDlang is also very nice if you like Algol style languages. You can get productive in it pretty fast, just like in Go, but it's expressive, it's garbage collected by default and you don't waste time fighting the compiler. Also the code compiles as fast as Go with DMD and LDC. I havent tried GDC. https://tour.dlang.org/ https://tour.dlang.org/
- ben-schaaf 8y agoPlus you get templates and CTFE, which are both awesome. Though if you're doing web stuff I've found D compile times to not be so great anymore, especially when diet templates get into the mix.
- steveklabnik 8y agoRust was originally described to me as "OCaml + C", so there's some truth to that. The language has strayed a bit farther from OCaml in many ways. I really like OCaml, and you should learn it, but you should also know that concurrency is not a strength of it. It's being worked on...
- a0 8y agoSingle-process concurrency is great in OCaml. It’s flexible and composable with libraries like Lwt and Async. On the other hand true multicore backend is where the most work is moment. For the latest update on that see: https://discuss.ocaml.org/t/ocaml-multicore-report-on-a-june-2018-development-meeting-in-paris/2202 https://discuss.ocaml.org/t/ocaml-multicore-report-on-a-june... (Tl;dr: It will be officially merged in 2019.)
- steveklabnik 8y agoYes, I should have said parallelism, my bad. I hope that it does get merged soon, people have been waiting quite a while, in my understanding. It’s a tough problem.
- claydavisss 8y agoWhy can't he just be happy using Go?
- lmm 8y agoIf he(?) wouldn't use it for daily scripting then it isn't meeting all his needs. IME being able to use a single language for both scripting and "real" code is an underrated advantage, since it lets you reuse all your helper functions etc. in your scripts.
- claydavisss 8y agoWhat you are describing (one language to rule them all) is a non-goal to 98% of HN readers.
- lmm 8y agoOnly because they assume it's impossible.
- ecnahc515 8y agoOr, because like most professionals, we understand certain tools are better than others at specific tasks, even when there's specific tools that do both things equally well. There can be an option that's preferred even when it's "only" good at one of the things you need.
- Alir3z4 8y agoXAR lets you package many files into a single self-contained executable file. This makes it easy to distribute and install. https://github.com/facebookincubator/xar/ https://github.com/facebookincubator/xar/ Then just build your XAR executable with: $ python setup.py bdist_xar
- nhanhi 8y agoArchive URL: http://archive.is/smcWh http://archive.is/smcWh
- KaiserPro 8y agoFirst let me state that a language is just a brush with which to paint your logic. I really don't subscribe to the X is better than Y. I might concede that x is better than y for certain tasks, but not a sweeping generalisation. The first point about inconsistent spelling mistakes, I 100% sympathise. I suffer from this terribly. Pylint and syntastic are a silver bullet for me. I have been tempted by a more fancy IDE, but I'm so used to vim, I'm reluctant/scared to change. Parallelism: I do look over the wall at Go and wish that python 3.x had spent more time on removing the GIL, but that is old news now. However I enjoy threading with python(not its limitations), because its so trivially easy. The Queues primitive saves 90% of the headache. as for ctrl-c not doing anything set all your threads to daemon (<threadObj>.setDaemon(True)) When the main thread exits, so does everything else. Go shines by having built in true parallelism If I need horsepower, then I have to run multiple processes (not multiprocessing, that has drawbacks.) which has the annoyance of serializing and message passing. (but that does mean scaling horizontally less painful further on). Again, Go really shines here. Statically compiling thing: YES. This means that I can 90% of the faff with docker (xyz version not working any more, the build fails) and use a real scheduling system that runs on real steel(or AWS) and not the omnifaff that is kubernetes.
- earenndil 8y agoI think the pypy people were able to get a trivial program running with the gil unlocked. I'd watch them for further updates.
- JanisL 8y agoI think when you really need performance it's a great example of a time to start looking at alternative Python implementations, CPython just isn't the best choice for a lot of tasks that actually have processing speed requirements.
- BerislavLopac 8y agoFor starters, just adding Cython and/or Numba to the code should introduce great improvements. https://rushter.com/blog/numba-cython-python-optimization/ https://rushter.com/blog/numba-cython-python-optimization/
- SjuulJanssen 8y agoSome issues: - I make stupid mistakes in Python constantly. I misname a variable or a function or I pass in the wrong arguments: Try mypy - If the task is IO bound: Threads are the wrong the answer to that. You're going async by using Golang, why not in python? - With Python, I have to ensure all the packages I need are installed on the remote machine: pipenv Like slezyr mentions - Consistent Styling: Try autopep8 or black - Intellisense: I would say "use Pycharm" but vscode is getting better I heard
- StavrosK 8y agoI had a very good experience using PyInstaller for a few of my Python programs, it made "binaries" out of them really easily.
- raverbashing 8y agoPylint is a bit hard to configure, use Prospector Prospector does a better job and it prevents you from wasting time with what essentially are stylistic choices and BS like a hard 80 chars limit per line (remember, A Foolish Consistency is the Hobgoblin of Little Minds) And yes, yes, automated stilling tools are better Intelisense is needed but even the standard vim autocompletion plugin does an ok job
- cakoose 8y ago> You're going async by using Golang, why not in python? In Golang, you're still using a thread-based abstraction. In Python, "going async" involves switching to a slightly different style of programming and using different I/O libraries. While that has advantages, using threads lets you stick with the standard style.
- finnmagic 8y ago“Python is much more flexible.”
- tanilama 8y agoRevenge Post.
- crdoconnor 8y agoRe: gofmt - python has black now. It's excellent. Pylint solves the undefined variable issue, but it is annoying as hell and always requires configuration. I wish there was a linter for python that didn't care about 80 character limit and was careful not to drown important errors with unimportant stylistic tics.
- fermigier 8y agoBlack is excellent ideed, and solves the problem of having code compatible with PEP8 once and for all. flake8 is a linter that doesn't need much config, and you can config it to give you only "serious" errors and not stylistic issues. I gave a talk on these subjects last year at the Paris Open Source Summit: https://speakerdeck.com/sfermigier/python-quality-engineering-a-tour-of-best-practices https://speakerdeck.com/sfermigier/python-quality-engineerin... (NB: Black didn't exist yet at the time).
- crdoconnor 8y agoflake8, like black, shouldn't really require any config on most projects yet annoyingly it always requires at least a little. I really would switch to another tool in a heartbeat if they could just fix that. Ideally instead of needing to be told whether to only show "serious" errors, for instance, it should just give you a project "score" (sum of the errors x their severity) and show the top 20 or so errors in order of importance and by default it should never exit with error code 1 with just stylistic errors unless explicitly configured to do so.
- shloub 8y agoHave you tried pyflakes?
- crdoconnor 8y agoNo, and I think you just made my day. Thanks! Or rather, I'd vaguely heard the name but I erroneously thought it was just another flake8 type thing.
- arendtio 8y agoDoes someone know a ressource where I can easily learn how to switch from Bash to Go? To give some context: When it comes to serious programs I use Go already, but often I just want to code a little script to watch a website for changes for example: #!/usr/bin/env bash url="https://example.com" mem="memory.txt" oldsum="$(cat "$mem")" newsum="$(curl -sL "$url" | sha512sum)" if [ "$oldsum" != "$newsum" ]; then xmpp_notify "$url changed" echo "$newsum" > "$mem" fi I haven't tried it yet, but in my mind it feels like writing such a program would be more time consuming/complex in Go than writing it in bash. Neverthelss, I feel like Go is overall a much better language than Bash (with all those quotes), so I would like to transition to writing more short programs in Go and for that I would like to learn how to do things like reading/writing/grepping files as easily in Go as I do it in Bash. Any idea if someone wrote some hints together already?
- chomp 8y agoThe benefit of bash is that it has system binaries as first class citizens; you can leverage the hundreds of thousands of lines of GNU projects with a single keyword. It's hard to beat that expressiveness. Saying "Go is overall a much better language" is like saying a wrench is a better tool than a screwdriver. You should keep both in your toolbelt and switch out when the need arises. For your question, start with the regexp and os package, learn how to open a file, read in the contents, and then while iterating over the contents, apply a regex to the text. That should get you to the point that you can search plaintext for character strings. Good luck.
- rezeroed 8y agoGo is the wrong tool for that. I'm no fan of bash, but it's often the the quick, clear (enough) solution for small tasks. I'm not a python dev - maybe that would be a suitable compromise?
- baq 8y agoi'd say bash is the perfect tool for the problem that you demonstrated. go may be a better language but it's just another tool.
- 8y ago
- xc2221 8y agoDoes the unreachable web page use Go or Python?
- vortico 8y agoThis is like saying "Goodbye car, hello airports!" If your needs change, then of course your favorite solution may change.
- therealmarv 8y agoGoodbye plenty, matured, well tested libraries and frameworks and big community. Hello go. (Nothing against golang, just wanted to point out it's not that easy for every usecase).
- deleted 8y ago[deleted]
- djstein 8y agoSo much this. No one is writing large production applications without some sort of imported library. Go simply has not been around long enough or had enough users to mature. For all of the pros Go has (not even mentioning the cons) they seem miniscule compared to what we give up switching to it. It has always sounded like the hot new fad and not a stable thing. Especially with daily articles like coaxing people into using it.
- majewsky 8y agoExactly! It will be many more years before big mature projects like Kubernetes, Docker or CockroachDB would consider switching to Go.
- therealmarv 8y agoThis are all sort of very close to system frameworks itself. I would never write something like that in Python. This is a good example for golang.
- greyman 8y ago> I’m not a fan of full blown IDEs that require their own configuration. Hmm, but those IDEs actually do solve most of the problems author has had with Python. If one regularly code in Python, spending a few hours configuring the IDE is justifiable. I for example never write scripts outside the IDE, because why?
- heavenlyblue 8y agoIt seems the author is one of those employees who think if he works hard he does a good job.
- IshKebab 8y agoNo they don't. No IDE can detect all typos in Python and do accurate code completion like they can for statically typed languages because the problem is unsolvable in general. They can use heuristics to get fairly okish. Pycharm is not bad and VSCode's new Python extension seems to work fairly well. But it's never going to be as rock solid as Java code completion for example.
- kungtotte 8y agoNote: I like Python, so this is me playing devil's advocate here. If you need an IDE to solve common pain points of a language, isn't it fair to say that another language which lacks those pain points is a better fit for you? Using an IDE to aid you, to smooth things out and allow for more rapid development and better workflow is one thing. Being forced to use one because the language is lacking is a bad look on the language!
- jacobush 8y agoYou could also say that this attitude holds us back. What if Smalltalk had only been accessible from vi back in the day, would Smalltalk have been as appreciated? I think not.
- paulie_a 8y ago> I make stupid mistakes in Python constantly. I misname a variable or a function or I pass in the wrong arguments. > Unit tests would catch most of these, but it’s hard to get 100% code coverage, and I don’t want to spend time writing unit tests for a one-off script. Sorry, I actually do like golang but this is telling of a bigger issue. Someone else is going to have to delete/fix it
- tomohawk 8y agoOne of the biggest benefits of go vs python is that you only manage your dependencies during build. You end up with a single executable that is easy to deploy and mostly immune to the deployment of other things. In python, you have to also worry about deployment. To be safe, you need to carry the vm and other dependencies with you. This means you can't just give any python program to someone and have it just work, unless it's pretty trivial.
- shaan7 8y agoDepends on your usecase, really. Static linking has been there for a long time and it has its disadvantages. I have more than a dozen programs on my system that share the same Python runtime and libraries. Compare that to every Go program shipping its own copy of the same things.
- mrweasel 8y ago>every Go program shipping its own copy of the same things. Is that really an issue? It takes up a bit more space, but nothing that's really any concern on a modern system. People often resort to using Docker to manage dependencies in other programming languages and end up shipping an entire copy of an operating system. I honestly don't see many downside to shipping a static binary. At least in that case you can chroot the entire thing, something I really wish Python (and most other languages) would make a whole lot easier. Security fixes require a recompilation, that perhaps the largest downside, but if you use Docker, then you need to rebuild that image as well.
- kazen44 8y agoAlso, deploying to production is as easy as writing a small shell script to simply copy the new binary and restart your service definition. (or using ansible/puppet/chef/saltstack et al)
- e12e 8y agoYes, if you can keep things simple. If you've fixed a ux bug and your binary depends on a certain new version of an image/icon etc - it may or may not be that easy.
- RickJWagner 8y agoWow, that seems like a pretty big jump. Good for the author.
- hellofunk 8y ago> I make stupid mistakes in Python constantly. I misname a variable or a function or I pass in the wrong arguments. Devtools can catch some of these, but they usually require special setup. I’ve never been able to configure pylint easily, and I’m not a fan of full blown IDEs that require their own configuration. The worst is if you mistype a variable that’s hidden behind conditional logic. Your script might run for hours before triggering the error, and then everything blows up, and you have to restart it. This this this, a million times this. I work mostly in Clojure where such problems are equally as bad, maybe even more so. Dynamic, elegant languages can feel liberating in so many ways, but there are significant workflow drawbacks that get me nearly every day.
- vikeri 8y agoI program mostly in ClojureScript which will "throw" a compiler warning if I misspell a variable. But to get that in an editor is a bit more setup than to just fire up vanilla vim.
- hellofunk 8y agoDoesn’t stop you from passing in wrong arguments, your function requires an int and you give it a string because you typed the wrong variable name there, or you mistype a keyword, which is never caught by the compiler, and you end up with nil floating through your app.
- mvid 8y agoCan’t you just use type hints (in both clojure or python 3)?
- hellofunk 8y agoThey don't take care of this issue most of the time, and in Clojurescript they are meaningless. In Clojure, only hints on primitive Java types (integer, etc) do something meaningful, so any custom Clojure types or your own "types" have no such checking, and in particular keywords are always valid if they are mistyped which results in a running program with no errors that creates nil and null pointer exceptions and undefined and other things all over the place. It's a tradeoff for using an expressive dynamic language, I guess.
- k_bx 8y agoFor those who lack the generics, I just wanted to remind that you can "script" in Haskell by adding this to your header: #!/usr/bin/env stack -- stack script --resolver=lts-12.2 and run it as an executable if your machine has stack installed. If not -- compile it with a `stack ghc --resolver=lts-12.2 ./file.hs` and you'll have a `./file` executable. No project creation, no need to list the dependencies.
- exceptione 8y agoGood trick! Do you also know the Turtle library? I just got across it, and it looks like a neat shell library from the outside.
- ivan_ah 8y agoThis makes me want to try Go, though I wonder how long it would take to develop the same "fluency" and knowledge of which library to use. It would be exiting to have things run fast though... One minor plug `pyflakes` is very good for basic checks for mistyped variable and missing imports, etc. It's not "smart" and doesn't check type consistency, but very useful to catch stupid mistakes.
- dilap 8y agoI went from Python to Go; Go is an amazingly simple and quick to learn language and ecosystem. Give it a try -- you'll probably start to feel proficient a lot faster than you'd think.
- ausjke 8y agoPython is regularly ranked to top 4 programming language for a reason, Go has a long way to catch up I think, if it ever happens. I recently started using python as the primary language, the more I use, the more I like it. Go's put everything in a static binary has its pros and cons.
- JoJoJoboop 8y agoI've been using Go over python for a couple months now and so far it has been incredibly effective. I never really liked Python's syntax so it's nice to go back to something c-ish.
- littlestymaar 8y agoRelated: [From Python to Go and Back Again(2015)](https://docs.google.com/presentation/d/1LO_WI3N-3p2Wp9PDWyv5B6EGFZ8XTOTNJ7Hd40WOUHo/mobilepresent?pli=1#slide=id.g70b0035b2_1_168 https://docs.google.com/presentation/d/1LO_WI3N-3p2Wp9PDWyv5...) And the HN discussion https://news.ycombinator.com/item?id=10402307 https://news.ycombinator.com/item?id=10402307
- rajangdavis 8y agoAre there numpy/pandas/matplotlib equivalents in golang?
- rajangdavis 8y agoLooks like the following are equivalents: numpy - https://github.com/gonum/gonum https://github.com/gonum/gonum matplotlib - https://github.com/gonum/plot https://github.com/gonum/plot pandas - https://github.com/kniren/gota https://github.com/kniren/gota (API not finalized)
- deleted 8y ago[deleted]
- f00_ 8y agoWhat do Go users think of Scala? Seems like the alpha language
- luord 8y agoI'm pretty sure I've read this same article, give or take a few words, many, many times before, only replacing the two languages being compared. This bores me, probably because I find everything to be the exact opposite (except for parallelism, I'd be foolish to pretend Go isn't better in that area) but specially because I find Go to be an ugly language to write. The error handling is only the top of the can of worms. Python, in comparison, is a delight to write and specially to read (when it's well written). In short: Oh, terrific, another one.
- iamleppert 8y agoIf most of your use case is copying s3 files to and fro, maybe doing a bit of transformation what does it matter what language you use? You could deploy some python or even JavaScript code to lambda and get the job done faster than you could with Go. From a performance perspective compiled languages only win in some very niche cases these days (mostly cpu bound tasks that can’t be distributed and require low latency).