474 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
The Zen of Go β€” 10 good ideas from Dave Cheney on how to write better Go code. Short and useful.

#golang
mtproto β€” full pure Go implementation of MTProto protocol. That means, you can automate anything in Telegram for your account (not bots).

We need more pure Go libraries because Go is amazing. Using wrappers around C libs means much heavier introspection, benchmarking, and cross-compilation and slower interoperation.

I nominate this repository for "most insane README of the year".

#golang
The Go compiler needs to be smarter β€” a short article why Go compiler sucks. Well, things not so bad, don't listen to me. Go is fast and cool, every release brings a lot of performance improvements, especially for garbage collector. However, there are still many things to do, especially if compare to old big compilers like gcc or clang. For instance, PGO and JIT are hard to implement but can give an amazing speed improvement, and there are no such things in Go yet. Well, there is gccgo compiler for go but it is slower than gc.

#golang
Simple techniques to optimise Go programs β€” a few tricks on how to allocate less memory. Good stuff.

#golang
High Performance Go β€” materials from Dave Cheney's workshop on how to measure performance in Go and write a faster code. So hardcore.

#golang
πŸ”§ esbuild is a fast JS/TS bundler and minifier, kind of webpack alternative. No, it's really fast, like 10-100 times faster than webpack. It is a new project and supports not all JS (frontenders name it ECMAScript) features, so it can be used not for all projects. But give it a try! Oh, and it is written on our lovely golang.

#js #golang
ITGram
The Zen of Go β€” 10 good ideas from Dave Cheney on how to write better Go code. Short and useful. #golang
Go Proverbs is another collection of cool ideas on how to Go better. This time, from Rob Pike and more Go-specific.

#golang
# Learning Go

There are resources that I find helpful for learning #golang, from easy to hard:

+ An Introduction to Programming in Go is a great start, especially if this is your first language. I learned Go by this book and it was enough to make my first projects.

+ An intro to Go for non-Go developers provides a good motivation on learning Go with a lot of links and examples. However, it assumes that you already have a programming experience.

+ Go by Example is a great thing for "just show me the code" type of people (who you, most probably, are). Google often leads me on this resource when I search something practical like "golang read json". So, maybe not perfect for learning but helpful as a cheat sheet for basics.

+ Learn Go with Tests will make you familiar not only with Go but with TDD as well. it's a great way to get started with immediate result. Nothing is so motivating as immediately seeing that your first code works and does the magic.

Your best guide for more resources is gopher-reading-list. It is a collection of links on learning materials, grouped by topic and experience level.

#golang
πŸƒ gofakeit is a fake data generator for Go. Looks cool, it can generate a lot of things, like names, emails, emojis, quotes etc.

#golang
πŸ“Š JetBrains has published The state of Go survey results. A few highlights:

+ China πŸ‡¨πŸ‡³ has the biggest ratio of Go devs, 16%. Then Japan πŸ‡―πŸ‡΅, Russia πŸ‡·πŸ‡Ί, Ukraine πŸ‡ΊπŸ‡¦.

+ Still isn't the most popular language but already in top 10.

+ Used mostly for web apps and CLI tools.

+ 82% of devs on go modules πŸŽ‰

+ most popular routers are gorilla/mux and stdlib

+ gin web framework is pretty popular, 46%. BTW, that means, more people use httprouter than the survey says (16%). Probably, they just don't know that it is in gin under the hood.

+ testify is used only by 13% of devs. IDK how others survive.

#golang
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