Hi All
I'd like to discuss on the way of creating a new class in smalltalk in general... I hope I'll be clear enough... :) When I first start, I found the way of creating classes not that straightforward... Probably because this implies a minimum understanding of smalltalk...
So, here is the template to create a class when having a browser opened on a selected category:
Object subclass: #NameOfSubclass instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Kernel-Objects'
so, the class Object (more precisely the class class) receives the message : Class>>subclass:instanceVariableNames:classVariableNams:poolDictionaries:category: and uses a ClassBuilder that will return the newly created class.
Some things bothers me:
******* if we want to create a class in a selected category, we change #NameOfSubclass in the symbol #NewNameClass using a symbol is not obvious (for me)... I'd prefer something like:
NewClass subclassOf: aClass ; --> (Superclass) instanceVariableNames: '' ; classVariableNames: '' ; poolDictionaries: '' ; category: 'KernelTests-Methods' ; yourself
But NewClass is not (yet) an object, and it's interesting to see how smalltalk consider it.. actually this is nothing, and smalltalk detect it while parsing the evaluated text selection ... it is varName (a string from the selection) in the following message to Parser:
Parser>> variable | varName varStart varEnd | varStart _ self startOfNextToken + requestorOffset. ***varName _ self advance.*** varEnd _ self endOfLastToken + requestorOffset. ^ encoder encodeVariable: varName sourceRange: (varStart to: varEnd) ifUnknown: [self correctVariable: varName interval: (varStart to: varEnd)]
What I'd like is to be able to create from an UnknowObject (that could be a subclass of UndefinedObject ? would it be problematic, interesting ?)
nb: There is actually a way to create a class from the execution of an unknown text selection. Excuting NewTerm (do-it) opens a menu that gives the possibility to create a new class (this only works if the selection start with an uppercase and it's done before excuting by the parser).
******** Also, if we want to subclass a given class (which is frequent) it's not direct as we need to change in the template the receiver into the given class and the first argument of #subclass:instanceVariableNames:.... in the symbol #NewNameClass.
Yet, It exists a more straight way to do that by right clicking on a selected class in the browser and then choosing 'new class'. And so it changes the template and wait for us to accept once proper parameters are entered...
nb: I think 'new subclass' should be more appropriate? - new class should only allow to create a subclass of object.
******** Last, I think that when created, the symbol with the name should be instead directly the class...Not so easy to figure out from what we see... Something like:
SequenceableCollection subclass: OrderedCollection --> (the class, not the symbol) instanceVariableNames: 'array firstIndex lastIndex' classVariableNames: '' poolDictionaries: '' category: 'Collections-Sequenceable'
or: OrderedCollection subclassOf: SequenceableCollection ...
An interesting (long) method for class creation is: ClassBuilder>>name:inEnvironment:subclassOf:type:instanceVariableNames: classVariableNames:poolDictionaries:category:unsafe:
********************************************************************************************** So I hope you understood what I've tried to say :)
If you have any comments or remarks concerning all that, I'll appreciate having others opinions.
To sum up: - using an UnknownObject (and especially UnknownObject>>subclassOf: aClass) - replacing symbols with appropriate classes when possible (when viewing a class definition)...
Thanks and see you ;)
Cédrick
Hi,
So I hope you understood what I've tried to say :)
If you have any comments or remarks concerning all that, I'll appreciate having others opinions.
To sum up:
- using an UnknownObject (and especially UnknownObject>>subclassOf:
aClass)
- replacing symbols with appropriate classes when possible (when
viewing a class definition)...
I think it would not be consistent because at one time your class is an UnknownObject and later is an "NameOfYourClass" /-: But who knows..
I think intuitively that is not possible unless you change all the system (-8.
Best regards,
On 5/20/06, cdrick cdrick65@gmail.com wrote:
I'd like to discuss on the way of creating a new class in smalltalk in general...
So, here is the template to create a class when having a browser opened on a selected category:
Object subclass: #NameOfSubclass instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Kernel-Objects'
so, the class Object (more precisely the class class) receives the message : Class>>subclass:instanceVariableNames:classVariableNams:poolDictionaries:category: and uses a ClassBuilder that will return the newly created class.
Don't think of this as a message send. Yes, this is legal Smalltalk code, and it is a bit of an amusing trick that Squeak uses Smalltalk code to declare a class. But it is better for new programmers to just think of this as a class definition. You should definitely NOT think of it as making a ClassBuilder; that is part of the current implementation but has not always been part of the implementation, and is certainly not part of the definition of class creation.
Yes, it is a little odd that the superclass comes first and that the class name is a symbol. As you said, the reasons are all due to the trick of implementing this as a message send. But it is easy define classes because you don't have to remember this syntax, all you ever have to do is to edit existing class definitions and put in new names. Like I said, it is better not to think about how this is implemented, and to just copy existing class definitions.
If the syntax bothers you so much, define a new syntax for class definitions and do NOT make it legal Smalltalk code. Just change the browser to display this syntax and to accept it. For example, it could be
class: 'NameOfSubclass' superclass: 'Object' instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Kernel-Objects'
You could implement this by making it be a class method for Compiler, or Class, or Browser, or even an instance method of Browser. If you leave fileouts alone, you can change the way class definitions are displayed in the browser and not bother anybody else. You can enter class definitions using your favorite syntax ,and nobody else will care. That is because you would be making a new presentation for class definitions but not changing the objects that you are editing.
-Ralph Johnson
Hello,
I'm newby by the newbies and red some tutorials across squeak www. I've heard about smalltalk for a long time but just decided to try it. I'd like to program a management software for table tennis tournament. Is it possible to build that with squeak ? Is it possible to load and run a smalltalk application by a dummy user without being faced to smalltalk environment ?
Thank you for your help
Pierre
On 5/21/06, Pierre Lebrun pierre@famillelebrun.net wrote:
I'd like to program a management software for table tennis tournament. Is it possible to build that with squeak ? Is it possible to load and run a smalltalk application by a dummy user without being faced to smalltalk environment ?
It is certainly possible to build it in Squeak, and it is probably a good project for learning Squeak. The best way to learn a new language is to use it to build something, but the worst way to build something is to do it in a language you don't know. So, if you want to build it quickly, pick a language you already know, but if you want to learn Squeak, go for it!
Yes, it is possible for a user to use an application written in Squeak and not know it. However, it is not trivial to make an application like this. Squeak experts will say "it is easy", and it is easy for them, but it is not easy for a newbie. My advice is to just build your application and don't worry about hiding Squeak from your users. Once your application is almost done, you will be an expert and will find it easy to learn to hide the environment from your users.
-Ralph
Pierre Lebrun a écrit :
Hello,
I'm newby by the newbies and red some tutorials across squeak www. I've heard about smalltalk for a long time but just decided to try it. I'd like to program a management software for table tennis tournament. Is it possible to build that with squeak ? Is it possible to load and run a smalltalk application by a dummy user without being faced to smalltalk environment ?
Hi Pierre, if you are french speaking guy, you can join the squeak-fr community here : http://community.ofset.org/wiki/Squeak We have french mailing list here : http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/squeak-fr
-- oooo Dr. Serge Stinckwich OOOOOOOO Université de Caen>CNRS UMR 6072>GREYC>MAD OOESUGOO http://purl.org/net/SergeStinckwich oooooo Smalltalkers do: [:it | All with: Class, (And love: it)] \ / ##
Hello,
I'm newby by the newbies and red some tutorials across squeak www. I've heard about smalltalk for a long time but just decided to try it. I'd like to program a management software for table tennis tournament. Is it possible to build that with squeak ? Is it possible to load and run a smalltalk application by a dummy user without being faced to smalltalk environment ?
Thank you for your help
Pierre
Am 22.05.2006 um 01:46 schrieb Pierre Lebrun:
Hello,
I'm newby by the newbies and red some tutorials across squeak www. I've heard about smalltalk for a long time but just decided to try it. I'd like to program a management software for table tennis tournament. Is it possible to build that with squeak ?
Squeak is a general-purpose programming environment, so sure, you could build something like that in Squeak.
Is it possible to load and run a smalltalk application by a dummy user without being faced to smalltalk environment ?
Yes. The way you do it is to actually open your application's main window inside Squeak and save the image with your app running. Also, add a "quit" action to your app that quits Squeak. To distribute your app, bundle a VM executable for the target platform with the image file, so that double-clicking the executable opens your image, et voilà, dummy user is happy :)
- Bert -
Hello Pierre,
PL> I'd like to program a management software for table tennis tournament. PL> Is it possible to build that with squeak ? PL> Is it possible to load and run a smalltalk application by a dummy user PL> without being faced to smalltalk environment ?
as Bert replied: both are definitely possible.
For the latter, on the swiki you will find some documentation on how to deploy an application. It doesn't work without hickups any more (I think you have to close a debugger once) but I attach what I used to deploy an application in 3.8.
The .bat (I'm on windows) just starts a renamed VM with a renamed image which is in the state I want it to start up and with a "script" (start.st) which disables the flaps and the programmer facilities. My application is added to Squeaks autostart and the changed image is saved.
Be sure to do this with a copy of your image!!! You will have a hard time if you try change that image.
The autostart isn't necessary, you can just leave the image in the state you want the user to see it come up.
I wanted to connect to a database and set the date of a calendar to the current date, that's why I used the autostart.
No need to think about deployment before the application is ready.
The second thing is the user interface.
You will be happy if you want to build a mainly graphic UI. Morpic is your friend here, especially if you are able to create a metaphor which fits more to the problem than to the computer.
Building a MS Office like UI you should consider WX Squeak (never tried myself).
Cheers,
Herbert mailto:herbertkoenig@gmx.net
beginners@lists.squeakfoundation.org