472 subscribers
6 photos
1 video
2 files
550 links
python, go, code quality, security, magic

Website and RSS:
https://itgram.orsinium.dev

Source:
https://github.com/orsinium/itgram

Author:
@orsinium
https://orsinium.dev/
Download Telegram
For a long time, I was looking for a good REPL for Go. I tried gore, gomacro, and a few similar solutions, but it all so clumsy. And so I found it.

gophernotes is a Go core for Jupyter Notebooks (I use it with Jupyter Lab, it's all the same). It misses documentation and type signature discovery (#173) but still better than everything else I tried so far.

#golang
I have raspberry pi where I store movies, podcasts, audiobooks, other media. How to stream all this media to other devices? FTP won't do because it requires to download the whole file first. So, there are 2 protocols: proprietary AirDrop used by Apple devices and DLNA used by everyone else. Apparently, we'll go with DLNA.

If you google how to set up a DLNA server, you'll find tons of articles on using MiniDLNA. It was hard as hell to set up: create a user, make a cache dir, write a config, write a server, troubleshoot why it doesn't work, troubleshoot why it doesn't see new files and so on. And after all that, at some point it just stopped working. Ugh...

And then I stumbled across dms. I've built a binary, sent it onto raspberry, run, and it just works! So, use dms.

git clone https://github.com/anacrolix/dms.git
cd dms
GOOS=linux GOARCH=arm GOARM=5 go build
scp ./dms root@raspberry:/usr/local/bin/

I noticed that when I have too many troubles with something, I search for an alternative written on Go because it just works. Partially, because of amazing tooling, amazing backward compatibility (I just compile everything I find with the latest Go release and never had any issues), and cross-compilation (like above we've built a binary for raspberry in one command). Partially, because of the language simplicity and the gophers' mindset. So, doesn't matter how the language itself is controversial and in some places immature, the tooling (first of all, CLI tools) is definitely benefits from it. See also: Why GitHub's CLI team switched from Ruby to Go.

#golang
🏃📄 Increasing http.Server boilerplate is a guide on how to configure the default golang http server with good timeouts, secure ssl/tls, and systemd socket.

#golang
A few years ago, I made a Go library genesis with some generic functions, mostly inspired by Elixir. And now, Go 1.18 beta is available, and it has proper generics! The 1.18 release is already in a few months. I used this opportunity to try the generics and migrate the project. And it's pretty cool (except one stack overflow but it will be fixed in the release). If you want to read more about the project history, I've made a short reddit post. So, give genesis a try, it's pretty cool now.

#golang
fasterthanli.me is a relatively popular blog dedicated to comparing how better Rust is than Go. Well, it's a personal blog of a guy, so it's not dedicated to anything in particular, but feels like this is the main theme for most of the posts. Even if it's about just Rust, comparison with Go will pop up. For example:

+ Lies we tell ourselves to keep using Golang
+ Some mistakes Rust doesn't catch
+ I want off Mr. Golang's Wild Ride
+ Aiming for correctness with types

And you know what? Being an engineer who loves Go and avoids Rust, I agree with most of the things (if not all of them, I don't keep the score). The type system in Go sometimes is too forgiving and even the existing type system could've been used better in stdlib.

A good example (that is also covered in the blog) is having string as the type for filesystem paths. It prompts so many bugs, from messing the argument order to concatenating paths as they were just, well, regular strings. And all of it could've been solved just by having type Path string declaration. What's interesting, there is a time.Duration type which does exactly this. Instead of passing time in seconds (Python, C) or microseconds (Erlang, Elixir) and messing with it each time, you explicitly specify the units when building the type. For example, 5 * time.Second. Just beautiful and much safer.

So, when you write anything on a language with a type checker (in the modern world, it's almost every language), I urge you to create subtypes for things and don't just use strings and integers. It's not so hard and it makes the code so much safer and more readable.

Oh, and I recommend reading this blog, even if you don't care about Rust or code correctness.

#golang #rust
verifier is a package that makes your Go code a bit nicer when you need to validate multiple things before running a block of code.

verify := verifier.New()
verify.That(transfer != nil, "transfer can't be nil")
verify.That(person != nil, "person can't be nil")
if verify.GetError() != nil {
return nil, verify.GetError()
}

They don't say it, but this is, basically, a monad. The package exists because Go doesn't have exceptions or powerful enough type system 👀 Anyway, the library is pretty helpful, remember it when you next time need to validate a lot of things.

#golang
🏃 go-recipes is a collection of Go snippets and tools to make different cool little things in Go: draw a dependency graph, prettify test coverage report, parallelize tests, show Go assembly, etc.

#golang
Go 1.20 has been released! I'm most excited about the addition of profile-guided optimization (PGO). Now you can run on production a copy of your service with the profiler enabled, redirect there a small percent of users, export the collected profile, and recompile the service with -pgo=/path/to/profile. The compiler will use the information from the profile about which lines of code are executed more often and optimize the binary for them. More specifically, Go 1.20 compiler will do more aggressive inline for the hot parts, which adds 2-4% of performance on average. That's not much but it might be much more in the future versions of the compiler.

I always liked the idea of PGO. There were many blog posts about people moving around parts of code (and also many PRs into Go itself doing the same for stdlib) to get a better performance for the most often executed path. And it always bothered me as one of the things that the compiler should do instead of humans. Well, now it can!

More in the Go documentation: Profile-guided optimization.

#golang
📝 Type embedding: Golang's fake inheritance is a great beginner-friendly blog post about inheritance in Go. It shows how it's different from OOP, what's good and bad about it, how it plays with interfaces, and how (not) to shoot yourself in a foot.

#golang
Go 1.21rc1 is released! It's not a final release yet, but we already can see what new features will be there, and that's huge:

1. Built-in function min, max, and clear. You know, like in all other normal programming languages.
2. Experimental fix for the loop variable capture, one of the most common Go mistakes.
3. Profile-guided optimization is now stable. The Go compiler itself now uses it to make its code 10% faster.
4. Structured logging, with both human-readable and JSON output. For me personally it 100% replaces any third-party logging libraries.
5. Generic functions for slices and maps.
6. WASI support. WASI is the standard of defining system calls in WebAssembly.

The release notes draft:
https://tip.golang.org/doc/go1.21

That's a short list but every item on it is amazing. I hope they'll pick enums (or union types, about the same thing, as Rust shows) next, the most requested Go feature at the moment.

#golang