It took me five days to learn Go to the point where I was able to create a project that was used in a massive content delivery production environment for five+ years.
@@himbary Of writing software in general? About 40 years. I'm finding the learning curve for Rust to be a lot steeper - more like C++ when I first started learning that back in 1989 or so.
@@davidgillies620 If you would recommend a programming language, for someone like me: chemical engineer, mostly wants to use programming to make life easier, like data cleanup, some loops for calculations. It's stuff that I now use VBA for, with the help of co-pilot. I'm a very much beginner in programming, again, I mainly use copilot and the record function in Excel at the moment, but I would add programming to my skill set.
@@robergroso yes, exactly. Try catch can lead to a lot of nesting in specific scenarios. Go eliminate that. There's many if statements because you are actually error handling in pretty much every scenario. I bet most Javascript, or Python devs don't handle errors even 25% of the time, purely because they don't even think about it.
@@chrikkeThat is a bit of because the error handling in go is very nice, cause that makes you think on handling possible errors, what in another langs probably you wouldn’t do
It's not between go's version vs exceptions. The Return type has existed for decades now and Go's version is just pretty terrible for a rather new language.
I code for 16 years, using PHP in the begining and Java most of time. So error handling and concurrency is part of my daily routine. However, I have to agree, error handling in Go is cons and pros at same time. I start thinking I was coding in 80s, then I understood we should never leaver 80s coding style on error handling aspects.
Lack of packages is a good thing in my book, since it encourages you to write your own implementations instead of gluing packages together, while still having the most important ones i.e. web frameworks, Markdown parsers, Raylib, etc.
@@yewo.m true, although it still feels largely the same. Although, in Rust the pattern matching still feels like a glorified if statement. I do like it though.
@@BigMonkeyKnowsthe magic of match and if let patterns is the ability to deconstruct structs and enums. Once you start doing that it feels less like a stand-in for a switch statement.
@@darkmastergraham you are correct I change my stance on this. Not from Rust, but from Zig. I do love the switch statements and pattern matching far more than Go’s error handling.
Man, go error handling thing is something I’m advocating so hard in js projects. People tend to throw errors on any occasion and then to have a master catch block which is a terrible idea from any side (well it’s good if you don’t want to handle any errors).
Go's error handling to me, as a non-Go programmer, is a lesson on how to make my code more readable in other languages In fact, i see a lot of this at my workplace, in our Python services.
Recently i started to code in go, wasn't as straightforward to learn as the popular langs but once you ge the hang of it there's no going back i love it
I actually prefer errors as values over try/catch. So much that I started using this paradigm in JS as well. When you throw, you sometimes forget to catch, and sometimes you don't know where it's caught and how it's handled... Maybe it just throws again and isn't cought at the top... I just prefer the safety of returning errors. Especially since TS lets you safeguard your actual return values so they stay undefined before you handle the returned error. Ever since I started doing this, I NEVER had a reference or an uncaught error... Think about that...
The only real issue I have with Go's error handling is Go's error type is basically just a string. If you get an error back from an API that can fail in many different ways (some of which may be recoverable from) you basically have to do string parsing to determine how it should be handled. This can create some flimsy code where you're basically just hoping the vendor doesn't change the error message on you
You can define error types on the Error interface, they're just string backed. That doesn't mean you can't use static typing to determine what kind of error was returned. LIke anything, if the vendor implementation is bad, the vendor implementation is bad. That's not the language's fault.
If Go's concurrency model is more intuitive to you then Python's, you either are doing it wrong or you're only half a layer deep. it's much more complicated depending on the pattern you pick (i.e. a pipeline is much more complicated than 'parrallel execution')
There are two things I dislike about Go. The no space between the opening curly brace, and that functions belonging to a struct cannot be declared inside the struct.
It makes you handle errors as you get it. All script kiddies spending hours to configure IDE. Even the most basic LSPs can give snippets one way or another. How is it verbose? Its readable and straightforward. Anything else is insanely worse. Go principle and most important aspect is keeping it simple. If you're gonna complain about verbosity you should also explain what you think would be better. It doesnt do anything complicated that other languages with error as values do like rust. Concurrency is so easy and it just works OOTB. Comes with toolchain for race analysis, prof, GC inspection. Good luck doing the same in java or any other GC. (GC languages cuz its clear we're talking about backend). Channels are amazing yet so simple. You can learn the whole language and necessary stuff in a day or two. Learning the Go way takes a bit of time but still way better than learning the intricacies of javascript. I urge Nodejs people to check it out. Its 100% worth it. Makes you better programmer.
I think it's fair to say that everyone who's used both exception-based and value-based error handling will prefer the latter for anything that is not a throwaway scratch project. It's one very important pillar to Rust's appeal, for example.
kotlin next would be amazing. Its java but better. And its *advertised as 100% java compatible BUT it really sucks so your standered and external libraries are not fun. But use it for general purpose not just android apps
Ironically, the Go error handling style is taking over Node/TypeScript now. People are ditching try/catch in favor of returning multiple values (including an optional error) within an object.
In C, which Go is a descendant of, you write your own packages. Even when they exist, C programmers will write their own version. It is a totally different mindset to Python and JS.
@@TJackson736 Literally every python package is made with C and C++, i really look up to C and C++ coders knowing I'll never be one of them (I know C# so maybe yes)
@@hamm8934 what does it help, when it does not bring us forward? They keep on writing operating systems and the computers are idle, because an OS alone does not help.
You should totally look into the D programming language. It's like C++ but easier, more readable and comes with automatic memory management by default (can be disabled/controlled).
why is everyone talking about the speed of Golang? I compared the basic example, 1000 Fibonacci numbers on js, python, go Result: Python: 88 ms Js: 90 ms GoRunCommand: 612ms GoBuild: 467 ms GoStartExe: 512 ms Where is the speed???
I love go, it’s by far my most favorite language of all languages I either really learned or just took a few days to tinker around with. I’m nowadays using it for everything I do, only using Java where I have to (like writing extensions to existing Java apps), or obliviously JavaScript for the web itself (although the GoT(T)H stack is my absolute favorite: Go, Tailwind, optionally Templ instead of the stdlib templates and HTMX. No more JavaScript for 95% of everything and the client decides the state. 1000x more performant than any React or even Svelte). The only downside imo really is error handling. I totally understand the why and I would prefer it every day over the way Java does it with try-catches/throws, or JavaScript that just doesn’t have built in errors, but it can get a bit repetitive at points. That’s why I’m so much for the error handler proposal, which basically makes it so that you can set, at any point in your code, a error handler that will handle all errors coming after it. A function returns a value and an error? You would only (unless you wanna handle this one yourself explicitly) do value := myFunc() instead of value, err := myFunc(). If an error is actually returned, the next error handler will be „searched“ and called, so it goes up the stack. If there is one a few lines up or at the beginning of the function, it’ll use that one, if there’s not, it’ll go into the function which has called this function and do the same search there, until it finds an error handler - until it’s at the main function which would then do a panic as no error handler has ever been set. It’s obviously a compile time feature, so it doesn’t actually search through anything, it would just when compiling find where the next one is and basically call that as a closure effectively. This way, I could just set a error handler inside my HTTP handler, then do a bunch of things such as requesting database, then another service, call some API, just many things that could error and if any of these does, the HTTP request couldn’t be completed anyways and therefore the error handler would just send a simple 500 internal server error status to the client. And, as I said, you could at any point just set a new handler, for example to handle your microservice errors differently when calling them, so that e.g. you could (re)connect to a different instance, retry the request and then successfully return what you wanted. And after that function returns, the microservice handler is no longer in scope and any further errors would be handled by the HTTP one. But, and that’s the whole point about go, if my only complain is that error handling is better than in any other language, but yet not perfect, then the language is doing something right. From my knowledge Go has the biggest std by far compared to every other language. For most of my projects I don’t really use external libraries, because you don’t have to. Dependency injection? Exists as per language spec, no library needed. Compressing files, modifying them and then uploading them via SFTP/SSH? Yeah all built it. Structured logging for my web server with a really nice router? Also in the std (the latter one since the last version). I could go on and on and on, but the std is sooooo extensive, it’s insane. Sometimes I’m searching for a package just for the first result being an stdlib package.. haha.
Error handling in Go was not designed for handling system errors like out of memory or keyboard interrupts. So that's a huge downside to give up on Go for me
I came from Python and learned Go recently and I definitely prefer Go. I think it's more beginner friendly in that you can learn a lot more by not using libraries
i never understand why it's so loved for backends because JSON parsing is hell 😂 Also it won't compile if there is an unused import. So often you can't just comment out code to test smth real quick if that is the only use of that import
Error handling is explicit, not overly verbose. It's avoid try/catch.. It lacks packages because the stdlib is that good. You don't need all the extra crap dependencies from others.
I feel being so called out when you say python and javascript and do the boom sound lmao. Didn't expect to be so called out, i usually use those and java. The moment i touch something like c++ already make me realize i am ultra spoiled
@@nithinsvarrier670 is quicker. Not more efficient. For example breakpoints can have conditions applied to them (i.e. "only break when x > 7 and y != null" or whatever). To do the same with print statements, you'd have to write that if statement
@@muyou0107and then you're dropping yourself out of half the community support Not to mention how bad PIP is, python is a badly designed language and JS is used in fields it should not be used in
Hi Lewis i have a question I have about 3 years of experience with Python and i started learning web development about 1.5 year . I began with frontend (HTML, CSS, and JavaScript) and then moved on to backend with Django and MySQL.I haven't learned API yet. I also hold a master's degree in urban planning (not related to IT). Can you help me to move forward and give some advice. And if you can tell me how/when i can begin starting applaying to jobs. I hope you read it and give me your thoughts.
@@osbourn5772Yes. For anyone who missed what was implied: Rust enums, like Result, are discriminated unions, meaning that the same memory space is used for either the success value or error value, while Go uses what is basically a tupple where space for both the success and error values are allocated even though only 1 is actually used.
@@emilnymann8723Yes, space on the stack is allocated for nil in Go. If you have an error, then it's allocated on the heap, and the pointer is on the stack. In Rust, on the stack in the area of the returned value there's a discriminate, and then space for either the value or the error inline on the stack.
Straight to the point with cons! I tried to make a simple roguelike engine to learn Go and this language felt fascinating. But in practice, when it comes to communicating outside of your program like querying redis or http or db it becomes garbage. 50% of your code is literally THE SAME THREE LINES of code. This is so cringe. At least they can provide some kind of error return operator (ahem throw ahem) to make it much more shorter right? Hell no, Go is designed to be simplistic. Even ternary operator does not exist in Go, so... I am thinking to learn Gleam or Zig
Go error handling is unreadable because the only readable error handling people are used to is NO error handling. It is way more readable then try {} catch () {}
I really tried. I made an array of size 5. Then I made a slice on the middle 3 elements. Adding an item on the slice mutates the last element of the parent array. Adding another one decouples the slice from the underlying array, so if you then alter the first item on the slice, the not-longer underlying array is unchanged. Wtf? Who designs a language like that? Why are even slices mutable?
My complaint about Go is that it’s not fancy 😂. It’s a fantastic language (I use it) and super fast, but I miss the syntactic sugar of Ruby or functional languages. I started learning F# (but hardly anyone uses it) and now OCaml because I want more magic haha. When I’m ready to give up if statements I’ll dive into Gleam 😁
Where do you guys learn languages? I wanna start c++ but I don't know where I can study it. I don't want to stick to just HTML and CSS ( my Junior Highschool Teacher taught me HTML and CSS )
@@arc8218if rust is his first language then he will have a hard time getting a grip on the language so in my humble opinion start with any other programming language like c to understand what is what and move to rust to develop a scalable application. That will be great.
Yes and no. Programming languages influence the way you think about problems. So if you know an OO language, learning another OO language should be easy. But when you start to learn eg. a functional language as a second language, knowing OO will be a burden.
Dude, readability is the last possible thing someone could say about Go error handling. If you can't read that, you can't program or read. It is a small set of three iconic lines. Skill issue!
Go error handling isn't as smart as that of Rust or Gleam, and that sucks because Go is a new language like Rust, but they only chose to simplify things, instead of also making them better.
if you really want to be a better programmer, then use C, not c#, not c++, standard C using standard C with a good debugger, you'll actually learn how to program 1000 times better, you'll get a deeper understanding of how computer works... Once you start reverse engineering your own work,(code) !
The lack of packages is a good thing. Otherwise we’ll end up like the js people who can’t figure out whether a number is even or odd without a library.