Notes on two topics: nakiircbot gem refactoring, CS:GO procedural map
nakiircbot gem socket refactoring
Today I was refactoring the socket part of my gem for the 100th time since... 2009? I didn't like that within the loop there were several interfaces to it: socket
itself, send
, log
and reading was just inline select
with conditions. First I thought to call a nested lambda to hide the socket object:
lambda do
socket = nil
lambda do
...
end
end.call
but I need to return two lambdas -- read
and write
, or even three with log
. C teaches us to make a struct but in Ruby for some reason (maybe I'm wrong) it looks ugly here because it would have no attributes we want to expose, because after we hide those methods we don't need to expose socket
anymore. Then maybe use Module? Okay, but I hate that encapsulation works here in both directions: once you hide things inside the module from the outside, the module internals also lose access to outside stuff, such as Logger object, so you have to do things like:
my_socket = Module.new do
@logger = logger
def self.write
@logger...
Also once I made it the first time, the need for new code lines of course led to a bug (try to find it here within 5 seconds):
socket = Module.new do
@s = nil
@logger = logger
@server = server
@port = server
In the end I have this commit. Having all socket-related actions in one place feels better.
Also TIL: Kernel#select
from EOF-ed socket does not return nil
.
CS:GO procedural map talk
After I shared my final code in #ruby IRC channel via GitHub gist a kind person pointed out I had spelling errors in GitHub Nakilon/README.md. Also he liked my procedural CS:GO map and after a brief talk now I know that there are like five procedural maps today. But it looks like mine was the first one. It's sad that youtubers don't give it credit.
P.S.: the CS:GO map was coded in Squirrel. Sometimes people say: "you don't have a job because you don't code in languages other than Ruby". It is a lie and stupidity. I don't work somewhere not because I don't write in that other language but because I don't do the shit they do in it. Like "you don't go work in that video game company because you don't want to code in C#" -- no, I don't go there because I don't want to code their Unity game, and the language they use there does not matter to me. Coding the CS:GO map in Squirrel was fun.