Live data from Hacker News

Gotk3: GTK3 the Go way

blog.conformal.com

31–40 of 58 posts

Re: Gotk3: GTK3 the Go way

#31
post #10

Hmm, does the name "GTK" mean "Gnu Tk"? I thought this was "Go Tk" for a moment when I read the title.

if you look on github, you'll notice that all the obvious names were taken, e.g. go-gtk, go-gtk3. that was what really drove the project name to be gotk3.

Re: Gotk3: GTK3 the Go way

#32

Are channels and CSP failing as the favored design approach? I keep seeing frameworks that just seem to use Go as if it were C with closures.

You are not considering that most Go UI frameworks are twenty years of C/C++ and a couple months of Go. Naturally anything trying to do significant reinvention is not going to be as far along.

Re: Gotk3: GTK3 the Go way

#33

Are channels and CSP failing as the favored design approach? I keep seeing frameworks that just seem to use Go as if it were C with closures.

There is probably a large set of developers coming to go for whom that is a lot more natural from familiarity.

Re: Gotk3: GTK3 the Go way

#34
post #10

Hmm, does the name "GTK" mean "Gnu Tk"? I thought this was "Go Tk" for a moment when I read the title.

gnome tool kit. Note that gnome is pronounced gi'nome just like gnu is pronounced gi'new.

gimp toolkit. gtk is older than gnome and was made by the gimp devs.

Re: Gotk3: GTK3 the Go way

#35
post #21

How is this different than this? https://github.com/norisatir/go-gtk3 They also set finalizers.

In short, we weren't aware of the project.

I just gave it a try now, but the code will not compile on my dev box (OpenBSD, go tip). Even after making some minor fixes (I fixed an #include directive, removed a call to a deprecated function, etc.) there appear to be some serious issues (one error I got mentioned the size of an array being negative).

It appears this code has not been updated in a year, and we wished to target a recent GTK version (3.8, to be precise) with our bindings. Had we known about the project, we probably would have considered submitted patches to fix its issue and bring it up to date with newer dependencies, but even then, I feel that it would be almost as much or perhaps even more to fix and verify an unfamiliar and broken code base than rolling our own.

But I'm glad to see this project seems to be doing memory management in a Go-like manner.

Re: Gotk3: GTK3 the Go way

#36

Are channels and CSP failing as the favored design approach? I keep seeing frameworks that just seem to use Go as if it were C with closures.

That approach isn't too surprising when the Go framework is, like this one, a Go wrapper on top of existing C code. And quite a lot of Go frameworks are that.

However, even ignoring the CGO-based frameworks, there's nothing wrong with mostly using Go as if it were C with closures (and garbage collection, and interfaces, and optional implicit typing and reflection), that's how most Go code looks, even in the standard library. Channels/CSP are great if you need to easily pass data among concurrent goroutines, but not all code neatly fits into that model nor benefits from concurrent execution.

One of the early mistakes most newbie Go programmers make (and I did this myself as well) is overusing channels, just because "hey, channels are super cool"!

Re: Gotk3: GTK3 the Go way

#37

Are channels and CSP failing as the favored design approach? I keep seeing frameworks that just seem to use Go as if it were C with closures.

I use channels all the time in actual code using gotk3. Unfortunately, it means using glib.IdleAdd() a lot (because GTK is not thread safe), but it works.

Re: Gotk3: GTK3 the Go way

#38
post #35
post #21

How is this different than this? https://github.com/norisatir/go-gtk3 They also set finalizers.

In short, we weren't aware of the project. I just gave it a try now, but the code will not compile on my dev box (OpenBSD, go tip). Even after making some minor fixes (I fixed an #include directive, removed a call to a deprecated function, etc.) there appear to be some serious issues (one error I got mentioned the size of an array being negative). It appears this code has not been updated in a year, and we wished to…

Just to be clear, this isn't my project, but it has been working fine for me for awhile now, but I am probably not exercising the same pathways as you. Anyway, I have written additional bindings for the Gtk Docking Library and the Syntax Highlighter against this project. Everything compiles, runs, and works well.

It is a little frustrating as it is one of the first projects that comes up when searching for "go" and "gtk3" on Google. So, it is is an alternative to what you are doing I guess.

Re: Gotk3: GTK3 the Go way

#39
post #13

Slightly off topic, but something I've been curious about. Go decided on garbage collection to manage memory. Why do so few languages offer something like C++'s RAII?[1] In C++, when you define a class, you define the constructor(s) and the destructor. Then the destructor is called whenever the object goes out of scope. Easy. This is the gist of RAII. Furthermore, in C++, a default destructor is automatically generat…

Preferring RAII over garbage collection is the decision that Rust made. Probably the reason that more languages don't use RAII for memory management is safety. C++, even with RAII, is not safe—you can violate memory safety with certain uses of references and iterators. Rust has to go to great lengths (lifetimes and the borrow check—things that have only been in the research landscape) to make this safe.

I'm actually a huge fan of Rust's memory model and wished Go had something similar, since it's faster to use smart pointers, and less calls to the garbage collector are required. I also love how rust uses three different kinds of pointers depending on how the memory is managed, and although it adds some complexity, it gives more semantic value to the data you are working with.

Unfortunately for me, the rust compiler is written in rust, so I would have to adventure to grab a Linux and try my hand at a cross compile before I can play with it on my OpenBSD box.

Re: Gotk3: GTK3 the Go way

#40
post #17
post #13

Slightly off topic, but something I've been curious about. Go decided on garbage collection to manage memory. Why do so few languages offer something like C++'s RAII?[1] In C++, when you define a class, you define the constructor(s) and the destructor. Then the destructor is called whenever the object goes out of scope. Easy. This is the gist of RAII. Furthermore, in C++, a default destructor is automatically generat…

This approach starts getting brittle when you get into objects that aren't procedure-scoped; for instance, a global session table in a web application, or a request token tracker in an RPC system. These are also the kinds of object lifecycles that tend to be behind leaks and corruption in programs that don't use RAII. People use shared pointers to mitigate that problem, but shared pointers are (a) a reference countin…

I think the biggest fans of RAII are those who use it more academically -- in real life it is brittle and scopes are tricky. It is also just an idiom as compared to a compiler feature. And, IMHO, RAII tends to play poorly with others.
Post reply on HN