this post was submitted on 23 Jul 2024
30 points (100.0% liked)

Today I Learned

1 readers
1 users here now

Today I Learned (TIL). You learn something new every day; what did you learn today?

founded 1 year ago
MODERATORS
 

I am able to use different programming languages. I know most of the well-known languages ​​without any problems: C, C++, Java, Python, JavaScript, Typescript, PHP...

However, I wanted to expand my horizon. Zig didn't do much for me neither did Rust, but now that I've written some Golang. I admit, I'm intrigued by the language.

I love the fact it's compiled to native machine language. There is still one caveat: despite Go being a GC language, you often still need to manage your memory. Sound strange right? But I needed to use io.Copy instead of io.ReadAll to avoid memory issues. But also you need to explicitly call defer res.Body.Close() to avoid Go not cleaning-up the HTTP response.. Ow well, so you learn it the hard way. Overall, I'm still very optimistic with Go. And looking forward to use it more often in some of my open-source projects.

See my first project in Go: https://gitlab.melroy.org/melroy/gitlab-artifact-deployer-go. Which I wrote in 3 days.

Did you try Go? What are your thoughts?

top 32 comments
sorted by: hot top controversial new old
[–] chrash0@lemmy.world 5 points 3 months ago (1 children)

yeah Go’s pretty good, especially for web services. i don’t have much of a space in my toolbox for it personally, though that’s not a fault of the language.

there’s a difference between managing memory and managing resources more generally. a GC doesn’t know when you’re done dealing with a file or a database connection or some other collection of data structures that has some semantically non-deterministic lifetime.

Rust however can close resources automatically with its lifetime mechanism ;)

[–] melroy@kbin.melroy.org 2 points 3 months ago (1 children)

True true, Rust can indeed automatically close resources with its lifetime mechanisms. However, I found Rust very painful to program in. Totally skill issue! However, I didn't like Rust yet. Maybe when you really need Rust, I can imagine you want to do that route.

[–] sazey@lemmy.world 2 points 3 months ago

I love Rust but hate how it is typed, gives me RSI.

[–] Thcdenton@lemmy.world 4 points 3 months ago (1 children)

Yup! I had a great time with go.

[–] melroy@kbin.melroy.org 2 points 3 months ago

Nice!.. I don't know who down voted you, but glad to hear.

[–] cornshark@lemmy.world 4 points 3 months ago (1 children)
[–] melroy@kbin.melroy.org 1 points 3 months ago

Thanks, I will read it today!

[–] BentiGorlich@gehirneimer.de 3 points 3 months ago (2 children)
[–] melroy@kbin.melroy.org 2 points 3 months ago (1 children)

Why don't you like go? Or?

[–] BentiGorlich@gehirneimer.de 2 points 3 months ago (1 children)
[–] melroy@kbin.melroy.org 3 points 3 months ago (1 children)
[–] BentiGorlich@gehirneimer.de 1 points 3 months ago

nor worries 😁

[–] melroy@kbin.melroy.org 1 points 3 months ago (1 children)
[–] BentiGorlich@gehirneimer.de 2 points 3 months ago (1 children)

I got a notification as well. On my PC and my Phone. I missed this so much :D

[–] melroy@kbin.melroy.org 1 points 3 months ago (1 children)

Hmm Not on the phone. I believe I need to keep the site open or the app in order to get the notification in my case.

[–] BentiGorlich@gehirneimer.de 1 points 3 months ago (1 children)

Which browser are you using on your phone?

[–] melroy@kbin.melroy.org 1 points 3 months ago (2 children)

Brave... (I was using Opera /Opera mini, but that drove me crazy recently)

[–] melroy@kbin.melroy.org 1 points 3 months ago

Uhm.. I can't enable this slider.

[–] BentiGorlich@gehirneimer.de 1 points 3 months ago (2 children)

Brave? O.o "Please, do not use Brave" - https://lemmy.dbzer0.com/post/5933715

But anyways, it's Chromium based and I didn't try out chromium based android browsers, so maybe that is a caveat. Do you have the PWA installed or just the regular site open?

But now that I think of it, it should honestly still work. It doesn't communicate through our site, but through their push service, so it would be odd if it would only work if the site is open imo

[–] melroy@kbin.melroy.org 1 points 3 months ago

Yea I know.. I might move to floorp as well or something else Firefox based.

[–] melroy@kbin.melroy.org 1 points 3 months ago (1 children)

Currently opened the site on regular browser mode. No pwa atm.

[–] BentiGorlich@gehirneimer.de 2 points 3 months ago

Maybe that is the problem. Didn't test it without the PWA...

[–] laund@hachyderm.io 2 points 3 months ago (3 children)

@melroy@kbin.melroy.org i recently tried Go for the first time. just trying to parse some nested json from a file was quite painful as there seems to be no easy way to parse arbitrary json. it always needed a struct, which for complex json is quite awful to write out.

safe to say, since i have absolutely no need to the language, i won't be using it

[–] SomeKindaName@lemmy.world 2 points 3 months ago (1 children)
[–] melroy@kbin.melroy.org 1 points 3 months ago

Thanks for mentioning this. So it is possible without defining the whole struct. Great!

[–] SwordInStone@lemmy.world 1 points 3 months ago (1 children)

this is an example of task easier achieved in dynamically typed languages e. g. Ruby, python, elixir

[–] melroy@kbin.melroy.org 1 points 3 months ago

No.. In production you don't want dynamically typed languages. Frankly, even TypeScript is still not good enough (since it still compiles to JS and the value can become any kind of type during runtime), it can cause catastrophic failures and errors in production. When you write a back-end server, I learned my lesson the hard way, I believe you want a statically typed language for better safety, security and mainly predictability at runtime.

Python is fine for some simple scripts here and there, but please do not use it for critical production software. Please ..

[–] melroy@kbin.melroy.org 1 points 3 months ago (1 children)

I understand your situation, apparently there are workarounds for with as listed in this comment thread. Statically typed languages catch errors at compile time, ensuring robust code and safer refactoring, while also allowing for better performance optimizations. Their explicit type annotations enhance code clarity and maintainability, making it easier to understand and manage large codebases. This leads to more reliable and efficient backend systems.

[–] laund@hachyderm.io 1 points 3 months ago

@melroy@kbin.melroy.org i mean, you can have a statically typed language and safely handle arbitrayry json. you just need Tagged Union types in the language, which make it easy to type hierarchical structures where each level is one of a set of types

[–] Pronell@lemmy.world 1 points 3 months ago (1 children)

I've tried to learn Go, but I just couldn't wrap my head around it, how to see the field and where to go.

Yes, I suck at the board game.

[–] melroy@kbin.melroy.org 2 points 3 months ago (1 children)

That is another kind of Go. You are talking about the board game Go. I'm talking about the programming language Go. hehe!

[–] Pronell@lemmy.world 2 points 3 months ago

Yeah, well aware, it just amused me at the time.