Stephen Woolerton's blog
Smalltalk problem for someone - extract firstname,lastnames
The issue is to extract the firstname and lastNames from a string called fullname.
e.g. fullname of "michael john horatio bassett" -> firstname "michael" and lastnames "john horatio bassett"
Below is the code that got the job done in the short time I had, but its not a Smalltalk solution. if anyone would like to post Smalltalkish solutions that would be great.
Observations on the development process
When using other scripting languages for server scripting, the result has been a file (sometimes large), but generally a single file.
I'm finding I now do things differently and I think better in GST. So here is the process now:-
- Break the task into pieces which seem like objects (an Object manages its own data. If in doubt I just pick a chunk of work which seems autonomous and start there)
- Make a class for the task, and then write at least one test method for the class. So in my FooBar class, there'll be a method something like:-
test [ | fooBar |
Figuring out a new library
One thing I've come across with open source Smalltalks is that there is often no formal documentation for a Library.
So, coming from Java and commercial programming, I'm like "where is the documentation and an example?".
Intro to Packages and NameSpaces
In GNU Smalltalk package loading and namespaces are separate.
If like me you've come from Java, it takes an example to see what this means in practice.
Here is a very simple example using sockets (found in TCP package up to 3.0.x, and Sockets package in 3.1). The example below is for 3.1 so the Sockets package is used. Sockets package documentation is at...
http://www.gnu.org/software/smalltalk/manual-libs/html_node/Sockets-pack...
What I tried to do first was this...
#!/usr/local/bin/gst -f
PackageLoader fileInPackage: 'Sockets'.Mail scripting
I recommend you browse the NetClients package to see methods to show POP mail attributes, e.g. sender, destination, content.
POP mail snippet
PackageLoader fileInPackage: 'NetClients'.
popHost := 'ourPOPHost.com'.
popUsername := 'popUser'.
popPassword := 'POPpassword'.
client := NetClients.POP.POPClient connectToHost: popHost.
[client
username: popUsername
password: popPassword.
client login.
client
getNewMailMessages: [:mimeEntity |
| subject from |