I´ve been writing a bot for a while now, with the purpose of learning proper Smalltalk and OOP idioms/techniques (I´ve been using C-ish languages for a long time now, and I´m trying to cure myself :D). I must say that the process has been quite enlightening so far, I never really understood OOP until now. So far I have a bot that works fine for my needs, but I´d like to contribute back, so I´ll just list some thoughts and you can comment on them. All constructive criticism and pointers on how to do them are welcome! I´m writing in on Pharo 3. I want to split the code I currently have in 3 parts: - part 1: a couple of classes IRCClient/ZdcSecureIRCClient mirroring POP3Client/ZdcSecurePOP3Client, with the intention of contributing them back to Pharo - part 2: an IRCBot framework, which I´ll likely name 'Chromia', to be released under MIT license too - part 3: my own bot using that framework, which would add all the extras like games Does that sound reasonable? At this point my code is quite messy, so I´m deciding whether to put it on SThub or not yet. I´m depending on http://smalltalkhub.com/#!/~PharoExtras/JSON for reading some JSON file from a website. Though it´s not high on my priority list, I wouldn´t mind making it as portable to other dialects as possible, too. Cheers, Sergi
Im my opinion... messy or not, all code should be shared! :) 2013/12/18 Sergi Reyner <sergi.reyner@gmail.com>
I´ve been writing a bot for a while now, with the purpose of learning proper Smalltalk and OOP idioms/techniques (I´ve been using C-ish languages for a long time now, and I´m trying to cure myself :D). I must say that the process has been quite enlightening so far, I never really understood OOP until now.
So far I have a bot that works fine for my needs, but I´d like to contribute back, so I´ll just list some thoughts and you can comment on them. All constructive criticism and pointers on how to do them are welcome!
I´m writing in on Pharo 3.
I want to split the code I currently have in 3 parts: - part 1: a couple of classes IRCClient/ZdcSecureIRCClient mirroring POP3Client/ZdcSecurePOP3Client, with the intention of contributing them back to Pharo - part 2: an IRCBot framework, which I´ll likely name 'Chromia', to be released under MIT license too - part 3: my own bot using that framework, which would add all the extras like games Does that sound reasonable?
At this point my code is quite messy, so I´m deciding whether to put it on SThub or not yet.
I´m depending on http://smalltalkhub.com/#!/~PharoExtras/JSON for reading some JSON file from a website.
Though it´s not high on my priority list, I wouldn´t mind making it as portable to other dialects as possible, too.
Cheers, Sergi
-- Bernat Romagosa.
2013/12/18 Bernat Romagosa <tibabenfortlapalanca@gmail.com>
Im my opinion... messy or not, all code should be shared! :)
http://smalltalkhub.com/#!/~SergiReyner/Chromia There it goes! Cheers, Sergi
An IRC bot is basically an REPL interface over a socket. It's a fun project to implement with Smalltalk. I made a couple of bots circa 2000 (IRC was still a thing) with Perl. If you implement the IRC bot that doesn't integrate as an extension to an existing IRC client, you'll end up implementing an IRC client itself, which you will be able to use by your bot or yourself. :) Regards! Esteban A. Maringolo
I created also a IRC bot with python. I was surpised how simple the irc protocol really is. But my robot was very basic. I agree with Bernat, messy code is much more preferable than no code at all. Sergi your plan sounds fine to me. I think it would be a good idea to announce new pharo builds via a bot to #pharo. This is a common practice for all channels. #emacs has an excellent bot that even allow you to search through documentation. So much potential :)
Sergi, you're too harsh on your code, I'm looking at it and it's nice! :) 2013/12/18 Sergi Reyner <sergi.reyner@gmail.com>
2013/12/18 <btc@openinworld.com>
I would say just ensure that it is packaged to load cleanly on a fresh
image.
Yes, as I mention on the description, I´m wrapping my head around Metacello trying to put together a decent ConfigurationOfChromia.
Cheers, Sergi
-- Bernat Romagosa.
what would be fun is to see if we can build a little tutorial that show to newbies how to write a simple IRC bot. Would you be interested to work on that? Because I would love that my son is able to build one with Pharo. Stef
Sergi, you're too harsh on your code, I'm looking at it and it's nice! :)
Yeah, I do that sometimes... but I can feel that it´s not as clean as it could be. More small pieces!! :)
2013/12/19 Stéphane Ducasse <stephane.ducasse@inria.fr> what would be fun is to see if we can build a little tutorial that show to
newbies how to write a simple IRC bot.
You mean how to write a bot with Chromia?
Would you be interested to work on that? Because I would love that my son is able to build one with Pharo.
I would like to at least make the code a bit more modular/less network-centric first. That said, I will see if I can find time to write something that resembles a tutorial these holidays. Cheers, Sergi
On Thu, Dec 19, 2013 at 10:37 AM, Sergi Reyner <sergi.reyner@gmail.com>wrote:
You mean how to write a bot with Chromia?
If you do it with Chromia, many details (such as network stuffs I guess) won't be shown. But this gives you the possibility to implement a great bot. If you do it without Chromia, you can show all the details so that the reader learns a lot of Pharo. Both are fine I would say. If you decide to write a tutorial, we could integrate it in the next book: https://ci.inria.fr/pharo-contribution/job/PharoForTheEnterprise/lastSuccess... -- Damien Cassou http://damiencassou.seasidehosting.st "Success is the ability to go from one failure to another without losing enthusiasm." Winston Churchill
2013/12/19 Damien Cassou <damien.cassou@gmail.com>
On Thu, Dec 19, 2013 at 10:37 AM, Sergi Reyner <sergi.reyner@gmail.com>wrote:
You mean how to write a bot with Chromia?
If you do it with Chromia, many details (such as network stuffs I guess) won't be shown. But this gives you the possibility to implement a great bot.
If you do it without Chromia, you can show all the details so that the reader learns a lot of Pharo.
That´s precisely why I asked, and why I said that first I´d like to modularise it as I mentioned in my original mail. That way I can first explain how the framework is built, so I can transmit the benefits of building it this way instead of mashing it up all together (which is how I began :D). Then I can explain how to use that framework to write your own bot, which again makes the benefits stand out. At the moment I´m going over some decisions that I feel can be improved.
From the top of my head:
- Class names are awfully chosen. Besides almost every one of them having IRC as a "namespace" prefix, some like IRCUser don´t convey enough meaning. - IRCConfiguration could be replaced by a dictionary since it´s nothing more than a bunch of data. But the, on the other hand, it could encapsulate validation on the settings to say something. - Is PetitParser overkill for the time of parsing required? Are regular expressions a better fit for this task? - Do I keep the Glamour browsers? I´m rather partial to them :D Both are fine I would say. If you decide to write a tutorial, we could
integrate it in the next book:
https://ci.inria.fr/pharo-contribution/job/PharoForTheEnterprise/lastSuccess...
Oh. Wow. Cheers, Sergi
On Thu, Dec 19, 2013 at 11:07 AM, Sergi Reyner <sergi.reyner@gmail.com> wrote:
- Class names are awfully chosen. Besides almost every one of them having IRC as a "namespace" prefix, some like IRCUser don´t convey enough meaning.
having a prefix is a common pattern. I don't see the problem of IRCUser as a name.
- IRCConfiguration could be replaced by a dictionary since it´s nothing more than a bunch of data. But the, on the other hand, it could encapsulate validation on the settings to say something.
I'm not sure what would be the gain of transforming a proper class into a dictionary. We usually do the opposite : creating classes out of collection usage. I would keep the class and give it a responsibility.
- Is PetitParser overkill for the time of parsing required? Are regular expressions a better fit for this task?
I don't know what parsing is required. But if it works, I would keep it the way it is.
- Do I keep the Glamour browsers? I´m rather partial to them :D
Glamour is really great to write interfaces and I really like it. Now, if you develop a browser on top of glamour, you also need the moldable glamour debugger. -- Damien Cassou http://damiencassou.seasidehosting.st "Success is the ability to go from one failure to another without losing enthusiasm." Winston Churchill
2013/12/19 Damien Cassou <damien.cassou@gmail.com>
On Thu, Dec 19, 2013 at 11:07 AM, Sergi Reyner <sergi.reyner@gmail.com> wrote:
- Class names are awfully chosen. Besides almost every one of them having IRC as a "namespace" prefix, some like IRCUser don´t convey enough meaning.
having a prefix is a common pattern. I don't see the problem of IRCUser as a name.
I was considering using ChromiaXXX as a prefix instead. The problem with xxxUser is that right now I manage two "User" concepts: what NickServ understands as a user, and what Chromia understands as a User, both of them different from an "IRC User" understood as someone or something who is connected to IRC. That´s what I meant by not enough meaning
- IRCConfiguration could be replaced by a dictionary since it´s nothing more
than a bunch of data. But the, on the other hand, it could encapsulate validation on the settings to say something.
I'm not sure what would be the gain of transforming a proper class into a dictionary. We usually do the opposite : creating classes out of collection usage. I would keep the class and give it a responsibility.
I see. I was thinking about how less classes make a system simpler and that I should remove it because the functionality is identical to that of a Dictionary. But as you point out, the dilemma can also be solved by adding new behaviour :)
- Is PetitParser overkill for the time of parsing required? Are regular expressions a better fit for this task?
I don't know what parsing is required. But if it works, I would keep it the way it is.
There are two scenarios, one is parsing incoming messages from the server (I haven't considered DCC yet), which are in "IRC message format", documented in RFCs. I built the parser for it by translating parts of the BNF grammar into PetitParser. The other one is parsing the message that a user types in the client as a command to to the bot, for example "!sayto #pharo Hello, my name is Chromia". Right now, I do that using regular expressions.
- Do I keep the Glamour browsers? I´m rather partial to them :D
Glamour is really great to write interfaces and I really like it. Now, if you develop a browser on top of glamour, you also need the moldable glamour debugger.
More stuff to learn! \o/ Cheers, Sergi
*" I was considering using ChromiaXXX as a prefix instead.* *The problem with xxxUser is that right now I manage two "User" concepts: what NickServ understands as a user, and what Chromia understands as a User, both of them different from an "IRC User" understood as someone or something who is connected to IRC. That´s what I meant by not enough meaning"* Make a User master class, subclass for IRC and Chromia. Dont use long names for what you can subclass, dont use long names for what you can document or add a class comment about. *" I see. I was thinking about how less classes make a system simpler and that I should remove it because the functionality is identical to that of a Dictionary. But as you point out, the dilemma can also be solved by adding new behaviour :) "* Less classes mean more methods. Nope definitely not good. Protocols tend to fix the mess of having too many methods in a class (see Morph class and scream in horror) but I prefer more classes and less methods. This way its more clear what you trying to do with the code. Of course still you need class comments but of course you already know that ;)
- IRCConfiguration could be replaced by a dictionary since it´s nothing more
than a bunch of data. But the, on the other hand, it could encapsulate validation on the settings to say something.
I'm not sure what would be the gain of transforming a proper class into a dictionary. We usually do the opposite : creating classes out of collection usage. I would keep the class and give it a responsibility.
- Is PetitParser overkill for the time of parsing required? Are regular expressions a better fit for this task?
I don't know what parsing is required. But if it works, I would keep it the way it is.
There are two scenarios, one is parsing incoming messages from the server (I haven't considered DCC yet), which are in "IRC message format", documented in RFCs. I built the parser for it by translating parts of the BNF grammar into PetitParser.
The other one is parsing the message that a user types in the client as a command to to the bot, for example "!sayto #pharo Hello, my name is Chromia". Right now, I do that using regular expressions.
- Do I keep the Glamour browsers? I´m rather partial to them :D
Glamour is really great to write interfaces and I really like it. Now, if you develop a browser on top of glamour, you also need the moldable glamour debugger.
More stuff to learn! \o/
Cheers, Sergi
On 19 Dec 2013, at 10:37, Sergi Reyner <sergi.reyner@gmail.com> wrote:
2013/12/19 Stéphane Ducasse <stephane.ducasse@inria.fr>
what would be fun is to see if we can build a little tutorial that show to newbies how to write a simple IRC bot.
You mean how to write a bot with Chromia?
originally I thought how to write an irc bot ?
Would you be interested to work on that? Because I would love that my son is able to build one with Pharo.
I would like to at least make the code a bit more modular/less network-centric first. That said, I will see if I can find time to write something that resembles a tutorial these holidays.
I would love to review it.
Cheers, Sergi
2013/12/18 Sergi Reyner <sergi.reyner@gmail.com>
2013/12/18 <btc@openinworld.com>
I would say just ensure that it is packaged to load cleanly on a fresh
image.
Yes, as I mention on the description, I´m wrapping my head around Metacello trying to put together a decent ConfigurationOfChromia.
I´ve almost finished writing it. I just need some code to load the minimum amount of code required to use PPCompositeParser and GLMTabulator.
2013/12/18 Sergi Reyner <sergi.reyner@gmail.com> I´ve almost finished writing it. I just need some code to load the minimum
amount of code required to use PPCompositeParser and GLMTabulator.
Gofer it smalltalkhubUser: 'SergiReyner' project: 'Chromia'; package: 'ConfigurationOfChromia'; load. (Smalltalk at: #ConfigurationOfChromia) perform: #load. Loads "fast" and "cleanly". Cheers, Sergi
On 18 Dec 2013, at 18:11, Sergi Reyner <sergi.reyner@gmail.com> wrote:
2013/12/18 <btc@openinworld.com> I would say just ensure that it is packaged to load cleanly on a fresh image.
Yes, as I mention on the description, I´m wrapping my head around Metacello trying to put together a decent ConfigurationOfChromia.
indeed we are trying to build a tool to he;p people write them. Stef
Cheers, Sergi
Hi sergi publish you code! It sound exciting. Stef
I´ve been writing a bot for a while now, with the purpose of learning proper Smalltalk and OOP idioms/techniques (I´ve been using C-ish languages for a long time now, and I´m trying to cure myself :D). I must say that the process has been quite enlightening so far, I never really understood OOP until now.
Super! Keep going reading and coding. Did you read Smalltalk by example.
So far I have a bot that works fine for my needs, but I´d like to contribute back, so I´ll just list some thoughts and you can comment on them. All constructive criticism and pointers on how to do them are welcome!
I´m writing in on Pharo 3.
I want to split the code I currently have in 3 parts: - part 1: a couple of classes IRCClient/ZdcSecureIRCClient mirroring POP3Client/ZdcSecurePOP3Client, with the intention of contributing them back to Pharo - part 2: an IRCBot framework, which I´ll likely name 'Chromia', to be released under MIT license too - part 3: my own bot using that framework, which would add all the extras like games Does that sound reasonable?
At this point my code is quite messy, so I´m deciding whether to put it on SThub or not yet.
I´m depending on http://smalltalkhub.com/#!/~PharoExtras/JSON for reading some JSON file from a website.
Though it´s not high on my priority list, I wouldn´t mind making it as portable to other dialects as possible, too.
Cheers, Sergi
participants (7)
-
Bernat Romagosa -
btc@openinworld.com -
Damien Cassou -
Esteban A. Maringolo -
kilon alios -
Sergi Reyner -
Stéphane Ducasse