I'm just starting out in Squeak and having a hard time of it. For one thing, I have a little experience with other programming languages, but I can't make the connection to squeak. I don't know where to start and most book I have seen are not for the absolute Squeak beginner. I have the "bots" book, but that seem more like a version of LOGO. How do you write program in this environment?? Help
Jeff
Hi Jeffrey,
on Wed, 10 May 2006 19:53:45 +0200, you haunj@yahoo.com wrote:
I'm just starting out in Squeak and having a hard time of it. For one thing, I have a little experience with other programming languages, but I can't make the connection to squeak. I don't know where to start and most book I have seen are not for the absolute Squeak beginner. I have the "bots" book, but that seem more like a version of LOGO. How do you write program in this environment??
Have a look at http://minnow.cc.gatech.edu/squeak/377 Introductions to Squeak (and much more).
Help
The page I mentioned has lots of links, tutorials etc.
Jeff
/Klaus
The easiest way to get stuff to work in squeak is to write your code, then select it and hit Alt-D (or Cmd-D).
At least that's where I've gotten to so far. :)
-Kyle H
On 5/10/06, Jeffrey Haun haunj@yahoo.com wrote:
I'm just starting out in Squeak and having a hard time of it. For one thing, I have a little experience with other programming languages, but I can't make the connection to squeak. I don't know where to start and most book I have seen are not for the absolute Squeak beginner. I have the "bots" book, but that seem more like a version of LOGO. How do you write program in this environment?? Help
Jeff _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Hi Jeff,
So you thought you would start with an easy question! Ok let me try to help. Forget about everything you know, forget about the interfaces you see and all the cool pictures. Forget about the class library and all the cool things it can do for you and think about objects.
What's an object? An object is like something in the real world. With objects when we build stuff we are building things. Real things. Some of our things are coordinators or models or composites but forget about those too and think about real things you see in your programming challenges.
If you can get to the ah-ha! point in object oriented programming you are all set because in Smalltalk everything is objects. In Smalltalk you get to make up most of what you write, it's the ultimate creative language.
So let's start with some basics.
An object as we said is a real thing. A class is a definition of that thing; what it is, what it can do. An instance is a living thing it's what happens when you take a class and use it to create something.
So
If you subclass Object which is the class that everything inherits from. We will get to that in a second with an object say Person then you get a definition of what a person should look like.
What does a person look like?
Well how about this?
Object subclass: #Person instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'People'
What is all this you say? Well and instance variable is somewhere where you can store information it's the data that a person knows. Let's just leave the rest for now. What things does a person know? How about name, birthdate, marital status, sex.
So now we have:
Object subclass: #Person instanceVariableNames: 'name birthdate maritalStatus sex' classVariableNames: '' poolDictionaries: '' category: 'People'
That is our definition of the object Person and we call this a class. Now let's make an instance.
In a workspace type in: Person new Highlight it and inspect it.
There you go what you see is an instance.
Right now your instance doesn't know how to do anything so we need to teach it some tricks.
On the instance side when you are browsing your person class add in a few methods under a new category called accessing (you will need to create the category).
Person>>birthdate "return the birthdate of this person" ^birthdate
Person>>birthdate: aDate "set the birthdate of this person to aDate" birthdate := aDate
Person>>age "return the age of this person" | yearsOld | self birthdate ifNil: [^'I don''t know'] yearsOld := ((Date today - self birthdate) days / 365.25) floor. ^yearsOld asString, 'Years Old'
Ok now we can do something. If you ask your person it's age by typing in the inspector on the left side: self age. Highlight it and print it. It can now respond to you. If you don't set the birthdate then it says "I don't know". If you do set the birthdate by typing in the inspector of your instance the following: self birthdate: '5/10/200' asDate.
Highlight it and do_it! Now ask age again.
Ok so what's inheritance? Well if we subclassed Person we get to keep the definition of person the way we defined it but we get to either change what it does (polymorphism) or add new behavior.
So let's try it,
First make a subclass of Person.
Person subclass: #Child instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'People'
Now if you make a Child (Child new) it looks and acts just like a person except it's called a Child that is because it inherited everything from the superclass Person (kinda like real life). Let's make it do something new.
First we will have to decide what class should be made when the object is created; this is called a factory method. http://www.google.com/search?hl=en&q=patterns+smalltalk+factory
So on the class side we create a new method on Person. (make sure you change the browser to move to the class side)
Person class>>newForBirthdate: aBirthDate "Factory method for creating person objects" | anAge anInstance | anAge := ((Date today - aBbirthdate) days / 365.25) floor. anInstance := anAge < 18 ifTrue: [Child new] ifFalse: [Person new]. ^anInstance birthdate: aBirthdate; yourself.
Ok so now if we make a new instance of someone that is under 18 we get a child instance. Notice that we used the same code again to calculate an age. So let's create a utility method to get the age from a date.
On the class side of Person add
Person class>ageFromDate: aDate "return an integer representing the age as of today"
^((Date today - aDate) days / 365.25) floor.
This method is on the class side because it's a utility method and notice that it doesn't have the word self in it. If there is no self in your method it should be either a class method or you are using to many passed in parameters or you are writing the method on the wrong class. Always try to solve the methods identity crisis (who am I, where do I belong)
Now you can replace where this code was used before in both places with either:
self class ageFromDate: self birthdate
or
self ageFromDate: aBirthDate.
I'll let you decide which goes where.
So now that we have two possible objects we can start putting in some real code.
Person>>doYouWantToBuyBeer "Respond to beer solicitation" self askBartenderForImportedBeer.
Child>>doYouWantToBuyBeer "Respond to beer solicitation" self goodChild ifTrue: [ self notifyAthoritiesOfSomoneTryingToCoruptTheYouth. ] ifFalse: [ self offerUpFakeIdAndSayYes ].
Ok well now you have some other methods to put in, but I hope you can see the creativity that is possible with objects. If this was no help at all please let me know, and I didn't actually do any of this coding so if I made a mistake or a typo my apologies up front! If this was helpful and you have more question, feel free to ask.
There are a number of little intricacies that I purposely put in but didn't talk about and there are some great books http://www.google.com/search?hl=en&lr=&safe=off&q=smalltalk+book... and don't' forget Stef's site http://www.iam.unibe.ch/~ducasse/FreeBooks.html to get you started with Smalltalk. Once you get to ah-ha!, it's all down hill. Since Smalltalk is written in Smalltalk once you understand what you are looking at, reading the class library is much easier.
Think objects, and Happy Coding!!
Ron Teitelbaum President / Principal Software Engineer US Medical Record Specialists Ron@USMedRec.com
-----Original Message----- From: beginners-bounces@lists.squeakfoundation.org [mailto:beginners- bounces@lists.squeakfoundation.org] On Behalf Of Jeffrey Haun Sent: Wednesday, May 10, 2006 1:54 PM To: beginners@lists.squeakfoundation.org Subject: [Newbies] Raw beginner asks.....
I'm just starting out in Squeak and having a hard time of it. For one thing, I have a little experience with other programming languages, but I can't make the connection to squeak. I don't know where to start and most book I have seen are not for the absolute Squeak beginner. I have the "bots" book, but that seem more like a version of LOGO. How do you write program in this environment?? Help
Jeff _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Jeffrey Haun wrote:
I'm just starting out in Squeak and having a hard time of it. For one thing, I have a little experience with other programming languages, but I can't make the connection to squeak. I don't know where to start and most book I have seen are not for the absolute Squeak beginner. I have the "bots" book, but that seem more like a version of LOGO. How do you write program in this environment?? Help
Jeff
Warning: This *is* a reply from a raw beginner. I've looked at all the books on the free-books page (most were in my library from several years ago). So far I've only found 3 that were, to me, useful. 1) On To Smalltalk by Patrick Henry Winston This is a very primitive book on Smalltalk, but it does cover necessary material. It lead to my being able to figure out files. 2) Smalltalk Best Practice Patterns by Kent Beck I just used this to figure out how to initialize a class. 3) The Design Patterns Smalltalk Companion by Alpert, Brown, and Woolf To be honest, I haven't really dug into this one yet, but only skimmed it. It looks like it's very good, though. N.B.: This book is keyed against the Gang of Four book, Design Patterns. If you didn't like that book, you may well not like this one.
The "tutorials" seem to be directed at the wrong level of person. They are too complicated for someone who's never programmed before, but they are to simplistic for someone who has another language or two under their belt. That said, I found the first few chapters of http://www.dmu.com/croquet/ to be quite useful in getting started. True, this is a Croquet tutorial, but the basic programming is Squeak (and, of course, below that Smalltalk). N.B.: This is an "unofficial" tutorial. I haven't really checked out the official one yet, since it's all in one huge pdf. Besides, I want the places where they overlap, not where they differ.
If you don't have much experience with other programming languages, and are very interested in graphic, you might look at the two Squeak books by Guzdial. As is common they are a bit elderly, but they do offer the basics and graphic programming works better now than it did when the books were first written. Unfortunately, graphic programming isn't "round-trip", i.e., if you make any changes in text mode, you can't ever go back to graphic without losing them. So I find it unsatisfactory even as a place to start.
It would be helpful to know what sort of app you want to write. Web app? GUI? Scripts? For scripts, just open a workspace,write code, select it, and then choose do it from the middle click menu.
On Wednesday, May 10, 2006, at 10:53AM, Jeffrey Haun haunj@yahoo.com wrote:
I'm just starting out in Squeak and having a hard time of it. For one thing, I have a little experience with other programming languages, but I can't make the connection to squeak. I don't know where to start and most book I have seen are not for the absolute Squeak beginner. I have the "bots" book, but that seem more like a version of LOGO. How do you write program in this environment?? Help
Jeff _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Have a look at my videos: http://www.iam.unibe.ch/~ducasse/Videos/
On 10 mai 06, at 19:53, Jeffrey Haun wrote:
I'm just starting out in Squeak and having a hard time of it. For one thing, I have a little experience with other programming languages, but I can't make the connection to squeak. I don't know where to start and most book I have seen are not for the absolute Squeak beginner. I have the "bots" book, but that seem more like a version of LOGO. How do you write program in this environment??
In Squeak you write methods and classes. Pay attention that botsInc is not equal to Squeak. In BotsInc you cannot define classes.
Stef
Help
Jeff _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
beginners@lists.squeakfoundation.org