DEV Community

Albert
Albert

Posted on

Go or Python and why?

So a friend of mine was considering either learning python òr go. What would be your advice to him?

Top comments (36)

Collapse
 
davidjfelix profile image
David J. Felix 🔮

I used to present at Python conferences and now use a mix of go and other languages to fill what used to be my all-python workflow. Here's my opinion:

I really like Python for fast scaffolding for low-use items. Django REST framework is really easy to get working and maintain. The language is pretty simple and you could break out into async/await based workflows if you really wanted to -- the last framework I used for that was tornado. But increasingly I'm not seeing Python as a strong enough candidate for scaffolding. Rails has been very dominant in the fast to scaffold web app space and now some really clever solutions like Elixir/Phoenix have come along and DRF just isn't as special. I think right now, Python's position among other languages is highest in data science because you can break into ML and really high ceiling use cases. However, besides that, I wouldn't recommend it. Not for DevOps scripts, not for web services, not for general purpose apps. Here's why:

Python has some really old cruft around the way things used to be. It wasn't async from the get go like node, so it's single-threadedness feels more detrimental than node. It has a few neat syntactic sugars, but lambdas and functional based code is still kinda clunky. But the real pain point for me has been deploys. Python was the itch that Docker first scratched for me because python deployment and package management is such a pain. Getting coworkers to reliably build packages for you is even harder than the initial pain of getting a package to install correctly for yourself every time. The way python dumps package sources globally necessitates tools like Docker,pyenv,virtualenv on top of tools just to run multiple python versions since many systems rely on it for OS tooling. The versioning model of requirements.txt is simply not sufficient nor enforceable enough. I would say Docker is a requirement of modern production Python. Another oddity is that many modern languages have moved over to hosting web services with a reverse proxy in front of a fully capable HTTP server. Python has libraries like tornado, but you're essentially writing nodey python. The strong libraries like Django DRF want a WSGI based setup, which just feels like a lot of effort compared to other languages. gunicorn can help abstract that... but the idea of running uWSGI+nginx just feels very 2008, not 2018, it's hard to express -- but from DevOps side, I despise the idea of the AppServer/WebServer pair up where the web server forks app servers off. It's a bad model; Async won; Reverse proxies + suspended app+web server makes more sense and ends up being easier to host and manage.

Now onto Go; Go is my favorite language while simultaneously being one of the ugliest most utilitarian languages. Nothing in Go will ever feel elegant, but it will feel sturdy. It won't feel state of the art, but it feels fast and efficient. It's a strange dichotomy that it gets a lot of flak for. Understanding the origin of Go really helps with learning to love Go for it's weirdness, and I encourage people to do that -- because from the start it can seem awkward and weird.

Go, to me, isn't the C++ replacement that a lot of people herald it at. Go is a language which is absolutely built on the web, for the web, but more importantly, by back-end engineers at Google, where Java, Python and C++ have been king. At a very high level, each accomplishes a slightly different but partially overlapping task. Java has good speed and stability and is great for long running business logic; Python is great for quick mockups and fast turnaround times and ad-hoc tooling; C++ is blazing fast and can be deployed with few (if any) dependencies. Go is somewhere right in the middle of all that. It is very fast -- only marginally slower than well tuned C++; it is somewhat simple to write like Python or Java; It uses source based importing like Python and C++; It has moderate typing -- better than Python, worse than C++ or Java, but way faster compile times than even Java.

Because of these ties, you have some weirdness. Go has a strange import structure that resembles a monorepo, something common at Google. Go has a somewhat ugly exception handling strategy, like C (not C++). Go doesn't have strongly typed Generics (this again, is like C).

Go does have an insanely good stdlib with coroutines endemic throughout it, Blazing fast HTTP, a very quick compiler, a runtime that is GC'd so you don't have to worry (as much) about memory and some of the niceties that C and Python miss out on by not being Java/C++. That being said, there's something nice about it not being Java or C++. It's great that threading is handled and it's also not using all of the RAM on my box. It's great that binaries take seconds to build but don't depend on the deploy system having a VM installed. Go made a lot of sacrifices to get where it is in the ecosystem and I personally love it, but you might not. I'd recommend Go over Python, but I hope you can appreciate the oddities that make it good and see past some of its hideous features that make people blog about how it's not good.

Cheers!

Collapse
 
nqthqn profile image
nqthqn

I really appreciate this comment!

fast scaffolding for low-use items

I did a lot of this. But now I'm tired of writing low-use applications :P

Collapse
 
vbordo profile image
Victor Bordo

Based on the info, "Yes he is planning on building an app", I'll assume we're talking about full-stack options for an MVP web app. We could also be discussing a language for a general backend that may support web + mobile apps. I like Python for MVPs. It's an approachable language with solid, opinionated frameworks like Django and Flask you can become productive in relatively quickly.

As some have already mentioned, Go is faster than Python because Go compiles "like a bat outta hell" from what I understand. That said, it's rare to run into performance issues until you achieve significant scale. Even then, the likes of companies such as Youtube and Google demonstrate it's possible to maintain efficient production services at scale using Python.

Even though I lean towards Python, Go is a fantastic language too from what I've seen. Your friend can't go wrong either way. These conversations about which language to pick always boil down to the bias and experience of the responders. Every language has technical tradeoffs. Most of those tradeoffs can be dealt with and won't make or break the performance of the app.

Collapse
 
20zinnm profile image
Meyer Zinn

It should be noted that Go was created essentially by Google to solve some performance issues they encountered with Python at scale. That said, for most applications that aren't Google scale, it comes down to the other factors, such as developer productivity.

Collapse
 
thomasjunkos profile image
Thomas Junkツ

AFAIK one of the main driving factors was the pain, they felt with C++.

Collapse
 
vbordo profile image
Victor Bordo

Good point!

Collapse
 
quii profile image
Chris James

To provide more details!

Is he a new developer? Seasoned? What motivated him to pick between those two? What does he want to accomplish?

Collapse
 
ben profile image
Ben Halpern • Edited

Yeah, more details will help. Without knowing more, here are some thoughts:

  • Python might be more “practical”, all else equal.
  • Go probably looks better on a resumé, all else equal.
  • Python has the big academic/data community, and has a ton of supporting libraries for this kind of work.
  • Go has features built more specifically for scaling and was developed with some “modern” problems in mind. But nothing’s a silver bullet.

Those are some thoughts from what I know of each language/community. I may have oversimplified some of the points but I think that’s a decent gist.

Collapse
 
albertdugba profile image
Albert • Edited

Yes he is planning on building an app that will high performance, security and a one that will scale as it grows. He is actually considering a dating app . He is from a perl background

Collapse
 
quii profile image
Chris James

If he is considering building something "proper" he should probably try both languages to see what he likes.

9/10 Go will be a lot more performant than python. But quite often it's not the programming language which really limits your performance.

Collapse
 
nektro profile image
Meghan (she/her)

Is he planning on making this as a desktop app? Because unless the answer is yes, neither of those languages are possible options.

Thread Thread
 
albertdugba profile image
Albert

No web app

Collapse
 
antonrich profile image
Anton

Go with Go.

Collapse
 
adeelhuss94 profile image
A.

I have been dabbling in both like just as a beginner. I would suggest python if your friend is more towards data analysis and data science stuff and go if you are looking to build apps related to cloud.

Collapse
 
luispa profile image
LuisPa

Everywhere I used to use Python, and I have a choice, I now use Go.

The primary reasons I can see for sticking with Python:

Shell scripting - when you want to run a script from a shell, rather than an executable. Go has a few limitations that get in the way of making this easy.

Python might have libraries not yet available with Go.

You’re working with an existing Python code base, and not planning on making many changes.

Go gives you:

Powerful concurrency tools

Static type checking, and duck-typing form of interface support

Powerful developer tooling

Fast execution, with low memory footprints

Fantastic compatibility guarantees

A simple, concise language

Essentially the same line-count (I’ve tested this by rewriting code in Go that I previously wrote in Python, and it ended up effectively the same.)

If you have the chance to choose, I recommend to choose go.

Collapse
 
cathodion profile image
Dustin King • Edited

I would choose Python for web development, but then I don't know Go. There are Web frameworks for Go as well. However, if you use Python with Django or Flask, you will probably have an easier time hiring developers who are familiar with those frameworks if your app takes off.

I don't think the speed of the language is going to be a limiting factor (in webdev it's usually download size or database queries that slow you down). If it ends up being an issue, there are things like Cython for that.

Python lets you work at a high level of abstraction, letting you get more done faster, which wouldn't usually be the main focus of a systems language like Go, but again I don't know Go, so it could be great at that as well for all I know.

Where I would start looking at Go would be if I wanted a lot of low level control, e.g. of system calls, memory, drivers, threading. I would also look at Rust in this case, as it's another newish systems language that has a great community.

Collapse
 
ilgityildirim profile image
Ilgıt Yıldırım

Just for clarification, Go doesn't need a framework to run as a web app. In most cases, you will find built-in functionalities of Go is more than enough to achieve what you want / need.

Speed (as well as resource usage) is a limiting factor in more than once case. You might be building a serverless app and the amount of time your app takes to execute & finish, it will effect how much you will pay for each request (among other things such as resource usage). In some cases, if your app is slow enough to hit the limits, it might be a problem.

Even if your app is not a serverless app, you will pay more to server the same amount of users if your app is slow / uses more resources.

Collapse
 
albertdugba profile image
Albert

Okay. Thank you

Collapse
 
20zinnm profile image
Meyer Zinn

Python for math or science, Go for almost anything else. Python has massive support for scientific programming, and its quirky language tricks (read: dynamic typing) make it quite concise for that purpose. Go is much better for maintaining large codebases and forcing you to make clear and good decisions regarding code structure.

Collapse
 
bgadrian profile image
Adrian B.G.

I would advice to leave this decision to the bitter end, first layout the architecture (monolith, services or serverless..), choose technologies and then the languages.

For example if he does the front end too he will have to learn JS too, so he could minimize the time to product by choosing JS (nodeJS) instead of Go or Python just because he doesn't need to learn another language.

There are also different styles of programming, communities sizes, tools and environments to be considered on a specific level (his personality, knowledge, preferences and the app requirements) for Go vs Python.

But most likely he doesn't want to hear and consider all that, so I'll comply and just respond Go.

Collapse
 
jamesray1 profile image
James Ray • Edited

I would say learn Rust, because it has the advantages of speed, concurrency and safety.

Speaking from personal experience

However I have also almost finished learning Go as
I need to read code in Go (gossipsub as part of libp2p) for developing a sharding network as part of Drops of Diamond for Ethereum, and before learning Rust I learnt VBA, C++, Solidity, Python, and Vyper, in that order. I also use Python for reading Ethereum research code and implementations (e.g. of EVM and Casper).

Collapse
 
shaijut profile image
Shaiju T

😄, I used to have questions like which language is better ? After discussing with my friends and listening to people online, I realized that Its better to stop asking these questions. Instead start asking which tool is better for current Job and Trend.

Choose the right tool for the Job.

  • Based on your experience, you can use C# or Java for building enterprise and large applications.
  • Instead JSF you can think of using Anuglar orReactorVueetc. for Front End.
  • Python for Machine Learning.
  • Go for Micro Services based performant applications.

In future maybe today's Languages and Framework may be outdated, so to survive you will be forced to learn new language of that time.

Conclusion:

  • Developer Happiness, stick to the language which make your life easier, like easy to read syntax, maintainable, has Good IDE. I like C# for current work, and its up-to you to decide what you like.

  • Its always good to be Open to learn any language as required and Choose the right tool for the Job.

Hope this helps.

Collapse
 
dean profile image
dean

If your friend just wants to write a few programs, I'd say Python. If they really want to get into programming as a whole, I'd say Go.

Python is great for getting what you need done, but it's not good for teaching people the fundamentals of programming, so I wouldn't recommend it as a first language.

Go is an extremely simple language with very few features, so it's great for teaching programming fundamentals. I'd recommend it over Python if they actually plan on getting into programming more

Collapse
 
rhymes profile image
rhymes

Hi Dean!

Python is great for getting what you need done, but it's not good for teaching people the fundamentals of programming, so I wouldn't recommend it as a first language.

why do you think so?

Collapse
 
dean profile image
dean • Edited

Mainly because it's just so simple. How do you figure out if an element is in an array in Python? if elem in arr:

I see Python like a big, soft cushion. It's REALLY comfortable, but you wouldn't want to build your foundation on it. I'm not ripping on Python or anything, I just think it's a bad fit for a first language.

EDIT: Think about it this way. If you learn Python as a first language, why would you ever want to learn a language where you need to use a for to see if an element is in an array?

Thread Thread
 
rhymes profile image
rhymes

I dunno, I'm conflicted on this. I don't think one necessarily needs to learn pointers and linked lists to learn how to program. I do think Python is a good first language exactly because you don't get lost into implementation details.

Would you make the same argument for a purely functional programming language?

You can still use a for on an array if you want to, Python doesn't prevent it, you can do it for learning purposes.

Collapse
 
nqthqn profile image
nqthqn

I wrote Django applications for 5 years and recently started learning Go (writing command line applications, web servers and going through the Go Programming language book)

Learn Go first. It's fast and type safe and the conversation with the compiler is more clear. Python has more cute abstractions. No one should write a large application in a programming language that is not type safe. If you aren't writing a large application and just want to hack together some scripts — go with Python. As soon as you need more than ~100 lines, you probably should switch to Go.

Collapse
 
nqthqn profile image
nqthqn

Take all that with a grain of salt. EVERYTHING has tradeoffs — just make a list of them based on what you want to do and then make your selection.

Collapse
 
lissybelle profile image
Lisa lopez

Gran curso en desarrollar la habilidad de , para empezar a desarrollar programas en Python
.
Introducción a la programación con Python 3.6:   Encribase hoy aqui:
udemy.com/introduccion-a-la-progra...

Collapse
 
sethusenthil profile image
Sethu Senthil

Yooo! I had to write about this for the GCI (Google codeIn).
Here is a link to the article, idk if I should publish it.
docs.google.com/document/d/1HeUiJ-...

Collapse
 
thomasjunkos profile image
Thomas Junkツ

I would go for a simple answer:

Your friend should have a look at a hand full tutorials on both languages.
The one he feels most comfortable with and which he picks up more quickly should be the language of his choice.

Languages are made for people to solve problems. If he could pick up one language faster than the other he is faster in solving his problem.

The point in time, when hard benchmark numbers count is far in his future.
Every popular language is for most of the jobs "good enough". Many disadvantages could be compensated otherwise.