Question: How to do it in Smalltalk 
Author Message
 Question: How to do it in Smalltalk

I'm trying to find the right tool that enables me to try new ideas.
So far, python seems to be the most flexible.

In Python, the following actions are legal and very easy to accomplish:

- persist almost anything
- add new members to objects at runtime
- add new methods to objects at runtime
- methods can return methods

I'd like to know whether these can be done in Smalltalk.

Thanks for any help.

Cheers,

Kroly

______________________________________________________________________________
Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.*-*-*.com/



Wed, 21 Apr 2004 02:53:19 GMT  
 Question: How to do it in Smalltalk

Quote:

> I'm trying to find the right tool that enables me to try new ideas.
> So far, Python seems to be the most flexible.

> In Python, the following actions are legal and very easy to accomplish:

> - persist almost anything
> - add new members to objects at runtime
> - add new methods to objects at runtime
> - methods can return methods

> I'd like to know whether these can be done in Smalltalk.

Yes to all.  The thing to keep in mind here is that there really is no difference
between runtime in Smalltalk and developement.
Quote:

> Thanks for any help.

> Cheers,

> Kroly

> ______________________________________________________________________________
> Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net



Wed, 21 Apr 2004 02:40:52 GMT  
 Question: How to do it in Smalltalk
Thanks for your very quick and encouraging answer.
As I'm very new to Smalltalk, I'd be very thankful for a few short examples
on how to persist objects and how to modify their structure at runtime.



Quote:


> > I'm trying to find the right tool that enables me to try new ideas.
> > So far, Python seems to be the most flexible.

> > In Python, the following actions are legal and very easy to accomplish:

> > - persist almost anything
> > - add new members to objects at runtime
> > - add new methods to objects at runtime
> > - methods can return methods

> > I'd like to know whether these can be done in Smalltalk.

> Yes to all.  The thing to keep in mind here is that there really is no
difference
> between runtime in Smalltalk and developement.

> > Thanks for any help.

> > Cheers,

> > Kroly

____________________________________________________________________________
__
Quote:
> > Posted Via Binaries.net = SPEED+RETENTION+COMPLETION =

http://www.binaries.net

______________________________________________________________________________
Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net



Wed, 21 Apr 2004 03:09:15 GMT  
 Question: How to do it in Smalltalk

Quote:

> I'm trying to find the right tool that enables me to try new ideas.
> So far, Python seems to be the most flexible.

> In Python, the following actions are legal and very easy to accomplish:

> - persist almost anything

yes

Quote:
> - add new members to objects at runtime

yes

Quote:
> - add new methods to objects at runtime

yes

Quote:
> - methods can return methods

yes
Quote:

> I'd like to know whether these can be done in Smalltalk.

> Thanks for any help.

> Cheers,

> Kroly

> ______________________________________________________________________________
> Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net



Wed, 21 Apr 2004 06:46:08 GMT  
 Question: How to do it in Smalltalk
Pasting from other posts

Quote:

> Hi people!
> Can anybody advise how can I add instance variable

along with get and set

Quote:
> selectors to the class?
> Regards.

Look at the UIPainter package's Tools.UIDefiner class for
examples.
e.g. UIDefiner>>#writeClassDefiningMessageForIVs:on: &
UIDefiner>>#addAccessing

This class adds inst vars that hold value models for the
GUI builder.
Its probably more than you want but is a complete
example.  There's a UI
to this provided by Tools.CodingAssistant; see
Launcher->Tools->Advanced->CodingAssistant

--
_______________,,,^..^,,,____________________________
Eliot Miranda              Smalltalk - Scene not herd

Here is a concrete example. Assume that you have a class
called Test and
want to add a method called #hello to print 'hello' in
the Transcript,
and put it in instance protocol called printing. Here is
what you can
do:

Test  compile: 'hello Transcript show: ''hello'''
classified: 'printing'

You can execute this with Do it in a Workspace or any
other place, or
include it in some other method so that this is executed
at run time and
the new method created at that point. You can create
class methods
similarly, just add the message class as in

Test class compile: 'hello Transcript show: ''hello'''
classified:
'printing'

Ivan

Quote:

> Thanks for your very quick and encouraging answer.
> As I'm very new to Smalltalk, I'd be very thankful for a few short examples
> on how to persist objects and how to modify their structure at runtime.




> > > I'm trying to find the right tool that enables me to try new ideas.
> > > So far, Python seems to be the most flexible.

> > > In Python, the following actions are legal and very easy to accomplish:

> > > - persist almost anything
> > > - add new members to objects at runtime
> > > - add new methods to objects at runtime
> > > - methods can return methods

> > > I'd like to know whether these can be done in Smalltalk.

> > Yes to all.  The thing to keep in mind here is that there really is no
> difference
> > between runtime in Smalltalk and developement.

> > > Thanks for any help.

> > > Cheers,

> > > Kroly

> ____________________________________________________________________________
> __
> > > Posted Via Binaries.net = SPEED+RETENTION+COMPLETION =
> http://www.binaries.net

> ______________________________________________________________________________
> Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net



Wed, 21 Apr 2004 06:44:53 GMT  
 Question: How to do it in Smalltalk


Quote:

> I'm trying to find the right tool that enables me to try new ideas.
> So far, Python seems to be the most flexible.

> In Python, the following actions are legal and very easy to accomplish:

> - persist almost anything
> - add new members to objects at runtime
> - add new methods to objects at runtime
> - methods can return methods

Yes to all.

But, there is a proviso on adding methods and members to [some ad-hoc set
of] objects.

In classic Smalltalk, you may dynamically add/remove methods and members
from a formal "class" of objects but not an individual object [or an
ad-hoc/proto group of objects].

Thus if you have a "array" object and you want to add a new variable to that
particular object you cannot do so in classic smalltalk. Similarly you
cannot add a method to just that object. You can add a method to the <Array>
class and thus make the behavior/method available to all instances of
<Array>.

Some Smalltalk dialects allow you to add per/instance (per/object) behavior
and variables/fields/members to objects. This style of language is known as
a prototype language and is best epitomized in the "self" language by David
Ungar, et al. Classic Smalltalk is a "class" based language (no pun
intended).

The work I've done in developing the SmallScript language (an extended
superset of Smalltalk) does provide the ability to do all the above
features.

  I.e.,
  a) Modify a class of objects
  b) Modify an individual object (or some grouped proto-set)

-- Dave S. [www.smallscript.org]

Quote:

> I'd like to know whether these can be done in Smalltalk.

> Thanks for any help.

> Cheers,

> Kroly

____________________________________________________________________________
__
Quote:
> Posted Via Binaries.net = SPEED+RETENTION+COMPLETION =

http://www.binaries.net


Wed, 21 Apr 2004 08:47:26 GMT  
 Question: How to do it in Smalltalk

Quote:

> ...
> In classic Smalltalk, you may dynamically add/remove methods and members
> from a formal "class" of objects but not an individual object [or an
> ad-hoc/proto group of objects].

A. Instance Specific Methods (ISM)
==================================
Even in classic Smalltalk you can create a class whose instances accept new
methods at runtime. The exact code to create such a class has been presented in
the Smalltalk Report for instance.

I experimented with this coding style years ago, and found it made the code hard
to understand and maintain. If you need to 'configure' the behavior of an object
at runtime, I suggest using Blocks for this purpose. This makes your code better
reflect this design decision, by having explicit setter methods for installing
the behavior modifying blocks for instance.

B. Instance Specific Variables  (ISV)
=====================================
Regarding the addition of instance variables at runtime, the idiom is to have a
Dictionary hold on to the 'ad hoc' attributes of an object (including executable
blocks if [A.] is desired). As with instance specific methods, the code would
become confusing and hard to maintain if the class declaration states a  set of
instance variables, but in fact at execution time more are stealthily added.

In summary: If you expect the instances of a class to be dynamically modifiable
either in behavior or structure, it is best to reflect this decision already in
the static definition of the class. You don't need these features always. But it
makes it easier to understand the program when you know where such 'non
conformant' behavior is potentially in effect and where not.

ISM and ISV might seem to add power to a language, but this power is destructive
when used in an uncontrolled fashion.

-Panu Viljamaa



Wed, 21 Apr 2004 18:31:19 GMT  
 Question: How to do it in Smalltalk


Wed, 18 Jun 1902 08:00:00 GMT  
 Question: How to do it in Smalltalk
Panu,

I think you are making some broad assertions that might hold true in a
classic Smalltalk System using Smalltalk tools, Smalltalk practices, and a
class based MOP implementation model.

However, as a counterpoint to Smalltalk idioms, I believe that prototype
languages like the "self" language system do not suffer from the problems
you assert. A point which should be distinguished from whether it may be the
case that they would suffer from such issues if classic Smalltalk tools and
techniques were used to implement them and author in them.

It is also not clear that the concerns/points you raise are issues for
typical/current usage patterns in languages like Ruby, Python, etc [which is
the usage context from which the original question was drawn].

I.e., The original poster was, by implication, asking if Smalltalk was
capable of supporting their Python mechanisms and style of development.

Quote:
>> In Python, the following actions are legal and very easy to accomplish:

>>- persist almost anything
>>- add new members to objects at runtime
>>- add new methods to objects at runtime
>>- methods can return methods

>>I'd like to know whether these can be done in Smalltalk.

---

I've forwarded this post to David Ungar [the principal author of "self"],
who is almost certainly in a much better position than I am to make cogent
comments regarding your assertions. [this thread was posted to:
comp.lang.smalltalk, comp.lang.smallscript.advocacy,
comp.lang.smalltalk.advocacy, comp.software.patterns,comp.lang.ruby].

-- Dave S. [www.smallscript.org]


Quote:

> > ...
> > In classic Smalltalk, you may dynamically add/remove methods and members
> > from a formal "class" of objects but not an individual object [or an
> > ad-hoc/proto group of objects].

> A. Instance Specific Methods (ISM)
> ==================================
> Even in classic Smalltalk you can create a class whose instances accept
new
> methods at runtime. The exact code to create such a class has been
presented in
> the Smalltalk Report for instance.

> I experimented with this coding style years ago, and found it made the
code hard
> to understand and maintain. If you need to 'configure' the behavior of an
object
> at runtime, I suggest using Blocks for this purpose. This makes your code
better
> reflect this design decision, by having explicit setter methods for
installing
> the behavior modifying blocks for instance.

> B. Instance Specific Variables  (ISV)
> =====================================
> Regarding the addition of instance variables at runtime, the idiom is to
have a
> Dictionary hold on to the 'ad hoc' attributes of an object (including
executable
> blocks if [A.] is desired). As with instance specific methods, the code
would
> become confusing and hard to maintain if the class declaration states a
set of
> instance variables, but in fact at execution time more are stealthily
added.

> In summary: If you expect the instances of a class to be dynamically
modifiable
> either in behavior or structure, it is best to reflect this decision
already in
> the static definition of the class. You don't need these features always.
But it
> makes it easier to understand the program when you know where such 'non
> conformant' behavior is potentially in effect and where not.

> ISM and ISV might seem to add power to a language, but this power is
destructive
> when used in an uncontrolled fashion.

> -Panu Viljamaa



Thu, 22 Apr 2004 05:37:09 GMT  
 Question: How to do it in Smalltalk
Thanks for your reply, David,

I must note that I'm not sure if my argument is correct. It is just an argument.

Interestingly the closest thing I've seen to Self in terms of prototype
inheritance & instance specific  methods is the ubiquitous JavaScript. In
JavaScript the only way to associate methods to classes is to assign them to a
prototype at runtime.  But I'm not sure if I'd be happy using it for a medium
sized application.

I know that SmallScript is explicitly meant to be a 'scripting language'.
Scripting languages typical use is to 'glue' together more basic functionality.
In such a case more flexibility the language offers the better.

There's value in being able to understand exactly the initial state of the
system before the program starts running,  and only after that have  to go on
reasoning how it changes due to procedural semantics. Such 'invariants' of the
program allow us to understand it more easily, produce it more quickly, and
avoid errors more efficiently. Such is the rationale also behind preconditions,
postconditions and class invariants in Eiffel and other languages.

_Panu

Quote:

> Panu,

> I think you are making some broad assertions that might hold true in a
> classic Smalltalk System using Smalltalk tools, Smalltalk practices, and a
> class based MOP implementation model.

> However, as a counterpoint to Smalltalk idioms, I believe that prototype
> languages like the "self" language system do not suffer from the problems
> you assert. A point which should be distinguished from whether it may be the
> case that they would suffer from such issues if classic Smalltalk tools and
> techniques were used to implement them and author in them.

> It is also not clear that the concerns/points you raise are issues for
> typical/current usage patterns in languages like Ruby, Python, etc [which is
> the usage context from which the original question was drawn].

> I.e., The original poster was, by implication, asking if Smalltalk was
> capable of supporting their Python mechanisms and style of development.

> >> In Python, the following actions are legal and very easy to accomplish:

> >>- persist almost anything
> >>- add new members to objects at runtime
> >>- add new methods to objects at runtime
> >>- methods can return methods

> >>I'd like to know whether these can be done in Smalltalk.

> ---

> I've forwarded this post to David Ungar [the principal author of "self"],
> who is almost certainly in a much better position than I am to make cogent
> comments regarding your assertions. [this thread was posted to:
> comp.lang.smalltalk, comp.lang.smallscript.advocacy,
> comp.lang.smalltalk.advocacy, comp.software.patterns,comp.lang.ruby].

> -- Dave S. [www.smallscript.org]




> > > ...
> > > In classic Smalltalk, you may dynamically add/remove methods and members
> > > from a formal "class" of objects but not an individual object [or an
> > > ad-hoc/proto group of objects].

> > A. Instance Specific Methods (ISM)
> > ==================================
> > Even in classic Smalltalk you can create a class whose instances accept
> new
> > methods at runtime. The exact code to create such a class has been
> presented in
> > the Smalltalk Report for instance.

> > I experimented with this coding style years ago, and found it made the
> code hard
> > to understand and maintain. If you need to 'configure' the behavior of an
> object
> > at runtime, I suggest using Blocks for this purpose. This makes your code
> better
> > reflect this design decision, by having explicit setter methods for
> installing
> > the behavior modifying blocks for instance.

> > B. Instance Specific Variables  (ISV)
> > =====================================
> > Regarding the addition of instance variables at runtime, the idiom is to
> have a
> > Dictionary hold on to the 'ad hoc' attributes of an object (including
> executable
> > blocks if [A.] is desired). As with instance specific methods, the code
> would
> > become confusing and hard to maintain if the class declaration states a
> set of
> > instance variables, but in fact at execution time more are stealthily
> added.

> > In summary: If you expect the instances of a class to be dynamically
> modifiable
> > either in behavior or structure, it is best to reflect this decision
> already in
> > the static definition of the class. You don't need these features always.
> But it
> > makes it easier to understand the program when you know where such 'non
> > conformant' behavior is potentially in effect and where not.

> > ISM and ISV might seem to add power to a language, but this power is
> destructive
> > when used in an uncontrolled fashion.

> > -Panu Viljamaa



Fri, 23 Apr 2004 02:40:44 GMT  
 Question: How to do it in Smalltalk


Wed, 18 Jun 1902 08:00:00 GMT  
 Question: How to do it in Smalltalk


Quote:
>I'm trying to find the right tool that enables me to try new ideas.
>So far, Python seems to be the most flexible.

>In Python, the following actions are legal and very easy to accomplish:

>- persist almost anything

Everything is persistant in Smalltalk if you save the image. You can
also export stuff.

Quote:
>- add new members to objects at runtime
>- add new methods to objects at runtime

The usual way to do this in Smalltalk is to modify the class itself.
Then all instances of the class update. (In the past, some dialects
would leave existing objects alone, but I suspect most or all can handle
the automatic updating now.)

There are undoubtedly tricks for modifying individual instances, but
typically the need to do that suggests that you should consider a
different design (i.e. it's not really "the Smalltalk way").

This is, in my opinion, usually more useful than changing individual
instances. The fact that it cannot be done in Python is a misfeature.

Python has a rather weak object model. It has no class methods or class
variables (and it has that insane requirement to list "self" as an
argument). The one thing it offers that Smalltalk does not is multiple
inheritance. I don't necessarily consider this a problem, but some
people might. I personally feel MI is more trouble than its worth.

Quote:
>- methods can return methods

Yes, absolutely. It just works.

Smalltalk also offers:
- Blocks, which are somewhat like Python's lambda functions, but with
much more sensible scoping rules. They're also better integrated into
the language.

- You have to declare variables. You might not like this initially, but
the number of bugs it saves is well worth the minor cost. Between this
and the fact that myObj.misspelledVarName = 1 is an error in Smalltalk,
instead of silently adding a new instance variable to myObj in Python,
means that, in my opinion, it is significantly easier to write robust
code in Smalltalk.

- Superior collection classes, including several useful types that
Python doesn't have. Also, Smalltalk doesn't inflict the stupid "tuple"
type on you ("it's just like a list except, well, not quite").

- No type/class dichotomy; *every* object is an instance of a class

- Better class organization; if you want to find out if an object acts
like a collection, it's easy to find out.

- An integrated development environment that is superior to any other
language I've seen. Easy browser. Your code is managed as code, not an
insane collectin of zillions of tiny files. You can debug on the
fly--come to a point that has an error? You can stop, fix it and move on
instead of restarting from scratch.

- Integrated GUI!

The language is simpler and much more regular than Python. Can you
remember when something is a function call in Python or a class method?
I often can't and have to look in the manuals. None of that nonsense in
Smalltalk.

This is not to say Python doesn't have its advantages. Some of those
include:
- It's easy to write short throwaway scripts. In Smalltalk, everything
you write becomes part of the system, in essence. You can throw stuff
away, but you have to do it explicitly, not just ignore files.

- Hence Python is much more suitable for simple drag-and-drop file
conversion utilities (of which I write a lot).

- You may find the syntax a bit easier. Personally I prefer Python's
syntax for if/then/else and try/except.

- Python offers default values for methods, and keywords can be in any
order. Smalltalk methods are defined by their list of keywords, in
order, which is much more limited.

I use Python these days because I can't get permission to use Smalltalk.
I vastly prefer Smalltalk, but Python is a reasonable second best. (You
might also want to check out Ruby). If Python offered Smalltalk's
development environment, I'd call it a much closer race between the two
languages (but I still prefer Smalltalk's cleaner design).

-- Russell



Sat, 24 Apr 2004 04:43:44 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. How is Smalltalk doing these days?

2. Anyone done OPC with any of the Smalltalks?

3. doing a paper on smalltalk

4. Doing assembly and really doing assembly

5. Doing assembly and really doing assembly

6. who is doing smalltalk/sql development?

7. Anyone done Sun RPC/XDR in Smalltalk?

8. Stupid newb question: What am I doing wrong?

9. Newbie Question - Usual ways of doing th

10. Newbie Question - Usual ways of doing things.

11. Newbee Template question - Can this be done?

12. what am i doing wrong? HLA question

 

 
Powered by phpBB® Forum Software