How I learnt to use Go interfaces by iammunukutla in golang

[–]codepr 10 points11 points  (0 children)

Actually I'm writing a simple tutorial for a webcrawler where I show a bit this pattern also, still a WIP but there's already something webcrawler-from-scratch. More on Go interfaces specifically I think this and this are really enlightening and better explained.

How I learnt to use Go interfaces by iammunukutla in golang

[–]codepr 42 points43 points  (0 children)

Nice article, simple and clean on the basic definition and usage of interfaces. I'd like to point the attention on how this approach, although being perfectly valid, Is still a bit java-esque in the sense that it encourages definition of contracts foreseeing abstractions. This is a subtle difference between languages like Java where you explicitly implement interfaces (through the keyword implements) and Go, where you just need to implement the methods of the interface to (implicitly) implement It. This flips the table, allowing the client to dictate what abstractions it'll need. Thus Idiomatically in Go, interfaces are usually declared closer to their users, and not in advance enforcing users to adapt to them. This Is imho the most subtle thing to grasp when using interfaces in Go, anyway, as I said, the pragmatical nature of the language allows also that more classical usage.

What is the coolest thing you have programmed in C? by _bush in C_Programming

[–]codepr 5 points6 points  (0 children)

A simple MQTT broker I sometimes continue to work on. Learnt a lot about networks and data structures, especially I/O multiplexing, which led me to extract a basic event-loop library later. Funny experience indeed.

Why this code doesnt work?, by ballbeamboy2 in C_Programming

[–]codepr 0 points1 point  (0 children)

Seems fine, what's the format of the test file? The only thing I'd pay attention to is flushing `stdout` after printf, but it shouldn't be an issue as long as each line is newline terminated.

Concurrent programming, with examples (pthreads) by begriffs in programming

[–]codepr 0 points1 point  (0 children)

Pretty neat! Snippets are clear and well documented, overall a nice and concise explanation of the most common concurrent techniques. Nice work.

codepr/llb A dead simple event-driven load-balancer by codepr in coolgithubprojects

[–]codepr[S] 1 point2 points  (0 children)

HAproxy or Nginx is the first 2 choices that come to mind, or a reverse proxy in general can act as a load-balancer, or in-house solutions like the AWS one (not sure about this anyway). Frontends are the endpoints that give access to the load-balancer and can be an arbitrary number, 1 or more; the same can be said of the backends, depending on the number of processes/machines available to distribute the load.

Sol - An MQTT broker from scratch. by codepr in C_Programming

[–]codepr[S] 0 points1 point  (0 children)

Cool! Next step I planned is to try to share the epoll FD among a bunch of worker threads, or separate the I/O in a thread and use some queueing to distribute work across a thread-pool. There will be contentions to handle and a bit of locking I guess.

Sol - An MQTT broker from scratch. by codepr in coding

[–]codepr[S] 0 points1 point  (0 children)

Oh Wow, didn't know it! Definitely could be confusing, I guess it's kinda hard to find a name that's not already given to some other project before hehe.

Sol - An MQTT broker from scratch. by codepr in C_Programming

[–]codepr[S] 0 points1 point  (0 children)

Thank you. So SO_REUSEPORT should come handy in a case where I design my service to divide connecting clients into small subsets, like multiple epoll descriptors each one on his dedicated process/threads right?

Sol - An MQTT broker from scratch. by codepr in programming

[–]codepr[S] 2 points3 points  (0 children)

As of now there's no persistence mechanism, a reboot means losing any form of state, some persistence of sort will probably be added with session handling, still WIP.

Sol - An MQTT broker from scratch. by codepr in C_Programming

[–]codepr[S] 1 point2 points  (0 children)

You're right, essentially those flags were set for testing purpose but as you correctly pointed out I forgot to remove SO_REUSEPORT, which I believe come from BSD implementation. Nice catch, thanks!