Skip to main content

Posts

Showing posts with the label tdd

Go, bots, go!

Earlier this year I started experimenting with the  Xmpp   protocol , and implemented bots in Python to communicate with an Xmpp server. I've now revisited those bots and reimplemented them in  Go . I've been meaning to learn Go for quite a while, and this seemed like a reasonable first project to tackle. The source code lives on GitHub:  https://github.com/snorristurluson/xmpp-chatbot If you are an experienced Go developer, I would appreciate any feedback and suggestions on how to improve the code - if you are just starting out with Go like myself, I hope this blog and the code is useful to you. As  before , I'm using  Prosody  to communicate with. Just like I did in Python, my first experiment is to simply open up a socket and poke the server to see where that takes us: func main () { conn , err := net. Dial ( " tcp " , " localhost:5222 " ) if err != nil { fmt. Errorf ( " Couldn't connect " ) } messa...

More on JSON in Erlang

I've been digging deeper into my experiments with Erlang and have improved the JSON parser I discussed in a  previous blog . The code lives at  https://github.com/snorristurluson/erl-simple-json  in case you want to take a look. The project is now set up to take advantage of  rebar3 , the Erlang build system, and tests are run automatically on  Travis CI . Thanks,  Lou Xun ! The parser now does proper tokenizing, rather than the simple string split operations I did in my first pass. The parser itself is surprisingly simple when it's working with tokens - here it is in its entirety: parse_json ( Input ) -> { Value , <<>>} = parse_json_value ( Input ), Value . parse_json_value ( Input ) -> { Token , Rest } = tokens : tokenize ( Input ), case Token of open_brace -> populate_object ( dict : new (), Rest ); open_square_bracket -> populate_list ([], Rest ); { ...