newb's questions about SmallTalk

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

newb's questions about SmallTalk

Pavel
Hi all!
Let me ask some questions. I'm new in ST.
if project have many shared procedures  (often repeating code )  - How it is
better to implement in ST project ?
What about constants (strings, numeric etc) ?

Tnx for attention.


Reply | Threaded
Open this post in threaded view
|

Re: newb's questions about SmallTalk

Günther Schmidt
Pavel,

everyone here will be happy to help you.

But could you be a bit more specific?

Also:

there is an IRC channel for Dolphin on:

        irc://irc.parcplace.net
        channel: #dolphin

where you can find more help.

Günther


Reply | Threaded
Open this post in threaded view
|

Re: newb's questions about SmallTalk

Schwab,Wilhelm K
In reply to this post by Pavel
Pavel,

> Let me ask some questions. I'm new in ST.
> if project have many shared procedures  (often repeating code )  - How it is
> better to implement in ST project ?
> What about constants (strings, numeric etc) ?

Welcome to Smalltalk.  You should find Ian Bartholomew's web site, get
the newsgroup archive and his newsreader or DSDN that you can use to
search them.

There are various tutorials you should read, and look for
AdviceForBeginners and other pages on the Dolphin wiki.  Feel free to
ask questions here.  We are a friendly group and make a point of not
chewing up our newbies.

How much programming experience do you have?  Smalltalk might seem
strange at first because you are learning a language, how to use a tool
set, and how to work inside a running system.  To some extent, you will
not so much write programs as you will turn Dolphin into what you want
it to be.  Start with the tutorials and keep in mind that the learning
curve is steep at first but it levels off fairly soon.

Happy Smalltalking!

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: newb's questions about SmallTalk

Chris Uppal-3
In reply to this post by Pavel
Pavel wrote:

> Let me ask some questions. I'm new in ST.
> if project have many shared procedures  (often repeating code )  - How it
> is better to implement in ST project ?

Just the same way as you would eliminate repetition in any other programming
language -- refactor the code so that it doesn't have any (unwanted)
repetition.

The only difference is that in Smalltalk there is less excuse for avoiding
repetition since

a) you have more and better features in the language (see below)
    to use to avoid it.

b) the Smalltalk programming culture expects to see code fully factored,
    so if you create a 1-line method to eliminate some repetition, other
    programmers won't think you've gone mad (or are wasting time)
    as they might if you were programming in (say) C.

Some of the tools you have available:

Lots of little methods -- it is normal in Smalltalk to break down programs so
that very few (or no) methods are more than a few lines long.  When you do
that, it becomes natural to factor out repetition into small shared methods.

Blocks -- if (say) you frequently find that you are iterating over the same
Array; so several methods have duplicated code like

    aMethod
        elements do: [:each | "... do something with each... "].

    anotherMethod
        elements do: [:each | "... do something else with each... "].

etc. then it is natural to factor that into another method:

    elementsDo: a1Block
        elements do: a1Block

That's a fairly exteme example, of course.  It would make more obvious sense if
the 'elements' structure was more complicated (an array of arrays, perhaps).
The point is that with blocks, it becomes easy to factor out the repetition
from repeating /patterns/ of code.

Loose methods -- ultimately when you are factoring out repetition, what you are
really doing is deciding which object's job it is to do <something> and then
making sure that /only/ that object does it -- other objects don't try to do
its job for it, and therefore don't duplicate its code. The problem comes when
you decide that the obvious object to do a particular job is a member of a
pre-existing class.  In some languages that would be a problem, but in
Smalltalk it is possible to add methods to existing classes.  (That has other
benefits than just elminating repetition, and is not without its dangers too,
but it's a technique that is very valuable if used wisely.)


> What about constants (strings, numeric etc) ?

Well, the /purest/ way to handle it is to use constant-valued methods.  You'll
find rather a lot of examples in the image (browse methods category 'constants'
for instance).

In many cases, that's not only the purest way to handle constants, it's also
the best.  However there are cases (IMO) where that's going too far.

A second technique (which I don't like much, though I admit I use it
occasionally) is to use class variables as constants.  If you look at class
View you'll see that it has a fairly large number of class variables; some are
actual variables but most of them are used as constants (all those with names
ending with 'Mask', for instance, CreateCenteredMask).  If you use this
technique then you should assign the constant values sometime as the class is
initialised -- normally in the class-side #initialize method.

A third technique is to use so-called 'pool' dictionaries.  The general
consensus seems to be that pool dictionaries are a Bad Thing and should be
avoided.  On the whole, I agree with that advice, so that's all I'll say for
now (ask again if you're curious).

The last technique is actually very similar to pool dictionaries but works a
lot better in practice.  In some cases you have to handle /lots/ of constants,
and using constant-values methods or class variables would quickly become
unwieldy.  The most typical reason for this (but not quite the only reason) is
when you are interfacing with externally defined systems.  For instance the
Win32 API defines thousands (probably more -- I haven't counted) of constants
which you have to use to program Windows.  For that reason Dolphin has
PoolConstantsDictionaries.  A PoolConstantsDictionary is a kind of Dictionary
with some extra logic (see the implementation if you are interested).  It
contains String->value mappings, typically the String is the name of some
externally-defined constant (from the API documentation, for example) and the
value is an Integer,  or perhaps a String or a Float (as far as I know you can
put anything in a PCD, but I've not tried it).  You create one of these things,
and assign it to the value of a global variable.  You add any constants you are
interested to it.  You then include its name in the list of names in any
class's 'poolDictionaries' in the class definition.  From then, if any method
in that class (or subclass) uses an identifier that matches one of the String
keys in the dictionary, the compiler will replace it with the corresponding
value and embed that value in the compiled method.   For instance the
PoolConstantsDictionary 'Win32Constants' is used in many classes.  You can see
the contents of that dictionary by typing
    Win32Constants
in any workspace and doing an 'inspect-it'.  You'll see that many classes use
that dictionary, for instance View does, and so does File.  If you look at the
source for File>>isReadable then you'll see an example of the use of the
'GENERIC_READ' constant.

There's more to say about PCDs, but that'll do for a start...

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: newb's questions about SmallTalk

Kirk Fraser
In reply to this post by Pavel
As a newB you should be instructed in Newsgroup Ettiquette.

---/FUD on
Kirk Fraser
What is "FUD"?

Andy Bower
"Fear, Uncertainty And Doubt". People who engage in FUD cast aspersions
on (usually) software indicating that it is deficient in some way
without having hard proof that this is the case.

Kirk Fraser
Based on lessons learned on other forums, I think FUD is fine.
It creates attention for a problem that others who can help may not
answer without it.

Andy Bower
That is true.
---/FUD off

--/Reason on
Kirk Fraser
It would be more reasoned and constructive to help you overcome your
laziness in making the
 software easy to comprehend so fewer help requests are needed than to
blame the software which cannot improve itself.

Andy Bower
Ah, now I Have Seen The Light. Henceforth, I resolve to improve myself
by refraining from troll baiting and return to the job in hand which
(as it happens) is finishing off the documentatiopn for D6.
--/Reason off

--/Customer Boxing on
,,, you will not be receiving any more replies from me on this
newsgroup. Is that a win for FUD tactics or not? You tell me.
--/Customer Boxing off

--/Customer correction on
Kirk Fraser
Ok, don't expect me to buy D6.
--/Customer correction off

--/Vendor's Question answered on
Kirk Fraser
It is a win!

1) Andy admits FUD is a way to get answered when a simple clear
question fails.
2) Andy demonstrates the light of clear reason inspires improvement in
personal performance but fails to appreciate the ligh or inspiration
adequately, choosing to damage customer relations which he never did as
a result of indirect FUD speculating on possible software defects.

I personally would love to dispense with glut-suck psycho FUD aimed at
getting a vendor to provide help and just simply ask first and tell
second.  I think it likely the poor reaction to the light of reason may
be due to a sheltered life where such light was rare in contrast to a
true Christian environment where wise men love correction.

The way things work in this fallen society where bosses think more
highly of themselves than the customer, the person who wants to be a
customer HAS to use FUD if the help request receives an inadequate
response..
--/Vendor's Question answered off

--/Common sense on
Sean M:
> It's time for you to find a new alias fella.
--/Common sense off


Reply | Threaded
Open this post in threaded view
|

Re: newb's questions about SmallTalk

Sean M-6
--/Modus Operandi on
"You are sounding like Kirk Fraser here, and I don't mean that as a
compliment!"
"smells of the grandiosity and pompousness of Kirk Fraser."
"I have never found Kirk to be in any way reasonable."
"Kirk is rather deathly serious about true church"
(In response to Kirk) "In other words, this is a troll."
And from this very newsgroup:
"Kirk W. Fraser is a LOON!"
"It sure is easy to get Kirk W. Fraser's panties in a wad!"
--/Modus Operandi off


Hold on, a pattern is forming

Name: InternetFuckwad

Problem: When combined with semi-anonymity people become turd steaming
fuckwads. Defending the indefensible, perpetuating their shit across various
forums, newsgroups, and any other form of internet communication.

Context: Many actors contribute to the problem, both by responding, and/or
otherwise antagonising the recognised InternetFuckwad

Forces: You want the InternetFuckwads to DieDieDie. You have no physical
means to remove it. The InternetFuckwad is usually nicknamed Scott by people
who have met him in real life. Scott for "Scott no friends". He alienates
all of those he comes in contact with, and he also has a small penis. He
tortures small animals, and is most probably asexual, except in rare cases
where he may insert foreign objects in orifices as he sees fit.

Solution: Add the InternetFuckwad to your kill file, or otherwise ignore
said InternetFuckwad, or make fun of InternetFuckwad at your own peril..

Resulting Context: The InternetFuckwad will move in one of two directions:
SuperInternetFuckwad, sort of like pissing on a hive of bees and giving it a
kick and hoping that the result won't be a swarm. Or theinternet fuckwad,
after repeated teasing, will move on to another group to continue with his
AnonymousWankStaining.



However I am quit happy to continue making childish playground jibes. Even
at the expense of my own dignity!


Reply | Threaded
Open this post in threaded view
|

Re: newb's questions about SmallTalk

Sean M-6
Now kiss my ass and forgive me.


Reply | Threaded
Open this post in threaded view
|

Re: newb's questions about SmallTalk

Sean M-6
In reply to this post by Kirk Fraser
> I personally would love to dispense with glut-suck psycho FUD aimed at
> getting a vendor to provide help and just simply ask first and tell
> second.  I think it likely the poor reaction to the light of reason may
> be due to a sheltered life where such light was rare in contrast to a
> true Christian environment where wise men love correction.

I just wanted to finish with a comment on this prose.

"A true Christian environment where wise men love correction."

I love it. It is GeniusAtWork(TM). In a single sentence you manage to convey
so many different ideas:

a) That unlike your learned brethren, Andy is not wise
b) You are representive of a group of open minded people willing to
entertain the thoughts, ideas, and opinions of others.
c) Like to be told you're wrong on occassion.
d) Love to be corrected! Sort of a repeat of Item C.
e) That the reaction to repeated baiting is a poor one.

I'm thinking of a word to describe you. It starts with H and ends with
ypocrite.

I repeat my earlier position:

Your proposal that Dolphin should be re-written in VB is the stupidest idea
I have ever heard. If VB is so good then go fuck off to comp.lang.vb. Hows
that for a correction to jam in your ass right along with your Gideon
Edition of Visual Basic in 21 Days.


Reply | Threaded
Open this post in threaded view
|

Re: newb's questions about SmallTalk

Schwab,Wilhelm K
In reply to this post by Pavel
Pavel,

> Hi all!
> Let me ask some questions. I'm new in ST.
> if project have many shared procedures  (often repeating code )  - How it is
> better to implement in ST project ?
> What about constants (strings, numeric etc) ?
>
> Tnx for attention.

I hope that some recent comments will not distract you from learning
Smalltalk, and doing so in Dolphin.  Keep reading, coding, debugging and
asking questions.  It will be worth the effort.

Sincerely,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: newb's questions about SmallTalk

Pavel
In reply to this post by Chris Uppal-3
Tnx a lot Chris!
I like Smalltalk more and more!!!

Hmmm... I dont understand - why Smaltalk have so little distribution?

And another questions:
Can I make applications by means of  Dolphin includes parts of IDE? For
example, many my customers (registration systems in business ) want to have
the potentialities of wide customizing application.
It would be nice to have such parts of IDE as "debug" and potentialities to
write code for their specificity. A-la VBA in MS Office.
May be exist special license for it or opportunity to agree with the
manufacturer ? I don't found such license in http://www.object-arts.com/

Tnx for attention.
Pavel.

PS : Sorry for my english


Reply | Threaded
Open this post in threaded view
|

Re: newb's questions about SmallTalk

Sean Malloy-12
> It would be nice to have such parts of IDE as "debug" and potentialities
> to
> write code for their specificity. A-la VBA in MS Office.
> May be exist special license for it or opportunity to agree with the
> manufacturer ? I don't found such license in http://www.object-arts.com/



You can include the compiler into your tool. And you could develop some way
for the user to edit some code and compile it. But it's a fine line. You
would need to talk to Object arts about this sort of usage.

There is a redist.txt file which outlines which classes are not to be
distributed with a deployed executable, and I believe this document
specifies _all_ of the development classes. As in: None of the development
classes may be distributed.

Object Arts would probably be ok with this sort of stuff, they just don't
want you going off and building a competiting smalltalk environment :) ...
You just need to discuss it with them and explain your intentions clearly


Reply | Threaded
Open this post in threaded view
|

Re: newb's questions about SmallTalk

Christopher J. Demers
In reply to this post by Pavel
"Pavel" <[hidden email]> wrote in message
news:[hidden email]...
...
> Can I make applications by means of  Dolphin includes parts of IDE? For
> example, many my customers (registration systems in business ) want to
> have
> the potentialities of wide customizing application.
> It would be nice to have such parts of IDE as "debug" and potentialities
> to
> write code for their specificity. A-la VBA in MS Office.
> May be exist special license for it or opportunity to agree with the
> manufacturer ? I don't found such license in http://www.object-arts.com/
...

As Sean suggests you can include the Dolphin Smalltalk compiler (but not
development tools) in your application.  Another option is to support
VBScript and/or JScript from Dolphin for end user scripting.  Take a look at
the 'ActiveX Scripting' package comment for an example.

Chris


Reply | Threaded
Open this post in threaded view
|

Re: newb's questions about SmallTalk

Schwab,Wilhelm K
In reply to this post by Pavel
Pavel,

> Tnx a lot Chris!
> I like Smalltalk more and more!!!
>
> Hmmm... I dont understand - why Smaltalk have so little distribution?

Neither do we :)


> And another questions:
> Can I make applications by means of  Dolphin includes parts of IDE? For
> example, many my customers (registration systems in business ) want to have
> the potentialities of wide customizing application.
> It would be nice to have such parts of IDE as "debug" and potentialities to
> write code for their specificity. A-la VBA in MS Office.
> May be exist special license for it or opportunity to agree with the
> manufacturer ? I don't found such license in http://www.object-arts.com/

One arrangement you could make is to buy Dolphin licenses for your
"users" who would then be developers.  I do not recall whether OA
forbids sharing images in that situation; they probably do because of
the unlock keys if nothing else.  However, you could always provide a
load script or sentinel package that kicks off the real work.

The other suggestions re scripting are probably more likely to work for
you and your users.


> PS : Sorry for my english

No need to apologize.

Happy Smalltalking!

Bill


--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: newb's questions about SmallTalk

Chris Uppal-3
In reply to this post by Pavel
Pavel wrote:

> Can I make applications by means of  Dolphin includes parts of IDE? For
> example, many my customers (registration systems in business ) want to
> have the potentialities of wide customizing application.

Maybe you could turn it around.  Instead of selling an "application", what you
sell is a kit for /building/ applications -- i.e. a library of classes.  What
you sell would include some examples.  Some might be very simple and just
intended to help the users see how things fit together.  But there would be one
/very/ compete and polished example -- the code that you used to think of as
"the" application...

Users would buy Dolphin development licenses in the normal way, and then
install your kit, and then write whatever applications they like.

I'm not recommending that approach, and it's certainly not the only way to go
about it, but it might make sense for your situation.

    -- chris