smalltalk - java side by side 
Author Message
 smalltalk - java side by side

Can anyone point me to a www site comparing Smalltalk and java,
things like j ->'this' strongly resembles st->'self',
       a j -> 'static' procedure resembles a st->'class' method',
       etc.

Thanx.

----

  http://www.*-*-*.com/



Sat, 02 Oct 1999 03:00:00 GMT  
 smalltalk - java side by side


Quote:

>Can anyone point me to a www site comparing smalltalk and java,
>things like j ->'this' strongly resembles st->'self',
>       a j -> 'static' procedure resembles a st->'class' method',
>       etc.

or:

        j -> types   resembles  st -> nil

Dave

_____________________________________________
David N. Smith
IBM T J Watson Research Center, Hawthorne, NY

Home Page: http://www.dnsmith.com/
_____________________________________________
Any opinions or recommendations are those
of the author and not of his employer.



Sat, 02 Oct 1999 03:00:00 GMT  
 smalltalk - java side by side

Well, I couldn't think of where on line I have seen what you asked for,
so I threw this together (please be kind about errors).  Also, apologies
for the formatting, I really need to move this to HTML to make it
acceptable on most people's screens (i.e. it will have wierd wrapping
on your news-reader).

A while back I began writing up a comparison of Java and Smalltalk
(showing
the differences if you ignore the static typing in Java), but I haven't
yet had the time to turn seven pages of notes into anything clean enough
to show.

For the list:
If a column is blank it means that the other column entry goes with the
line
above (usually as an example alternative with close semantics).

Java syntax is 1.1.  I picked Smalltalk-80 syntax (some other current
Smalltalk's have some features ST-80 doesn't have).  Also, this is not
meant to be exaustive of either language, but it has enough to get a
feel of each (although I think it is easier if you see a translated
piece of code).  Some of the following use my own naming convention
and libraries.

    Java                  Smalltalk
--------------------------------------------
This and that
    null                  nil
    this                  self
    super                 super
    <null>                self class                 // Java has no
class object for each class
    this.getClass()                                  // but it does have
a meta object (basically the protocol of 'Class' itself)

General statement structure
    ;                     .
    /*Comment*/           "Comment"
    //Comment             <nil>

Message Sends
    anObject.foo()        anObject foo
    foo()                 self foo                  //Although the java
message could be a static function
    anObject.foo(a,b)     anObject foo: a with: b
    aDict.atKey_put(key,value)                      //My Java method
naming convention
                          aDict atKey: key put: value

Instance Variables
    x                     x
    this.x                x                         //The 'this' allows
you to get to a shadowed iv
    anObject.x            <nil>                     //No public access
to another object's ivs

Control structures
    if (isTrue)           (isTrue) ifTrue:
    if (...) else         (isTrue) ifTrue: [...] ifFalse: [...].
    switch (...)          <nil>                     // in most
Smalltalk's but see SmalltalkAgents for example
    while (isTrue)        [] whileTrue: []
    do {} while ()
    for (...;...;...)     <nil>                     // No direct
equivalence is ST, but many alternatives
                          aCollection do:, collect:, etc.
                          anInterval do:
                          (number) timesRepeat: []
    try {} catch (Exception e) {}
                          Exception handle: [:e | ...]
                                    do: [...]
    <null>                anObject a; b             // No cascades in
Java

Declaring Classes
    class Foo {           Object subclass: #Foo     // Pseudo Smalltalk
for the rest, and also see Alan Kay's OOPSLA'96 presentation on
declarative Smalltalk
    class Bar extends Foo {
                          Bar subclass: #Foo
    interface Foo         <nil>                     // Smalltalk does
not have explicit interfaces, but implicit ones by what messages a class
responds to
    class Bar implements Foo
                          <nil>

Type Declarations
    Object anObject;      | anObject |
    String aString;       <nil>
    Object aString;       | aString |
    int anInt;            <nil>                     // no non-object
types in Smalltalk, so no int,long,boolean primitive types
    Object foo()          foo()
    String foo()          <nil>
    void foo()            <nil>
                          foo()                     // Just ignore the
return value in Smalltalk

Type casts
    (Bar) x               <nil>                     // but sort of
equivalent to x isKindOf: Bar
                          x isKindOf: Bar
                          x respondsTo: #messageForABar
                          (...DoesNotUnderstand...) handle: [:e | ...]
                                                        do: [x
messageForABar]

Access Visibility
    public ... foo()      foo                       // Smalltalk methods
are public
    protected foo()       <nil>                     // by convention
this would be in a 'private' protocol
    public x              <nil>                     // Smalltalk does
not have exposed instance variables
    protected x           x                         // 'protected' is
approximately equivalent to standard Smalltalk private
    private x             <nil>                     // not visible to
subclasses

Closures/Blocks
    new Function2Arg() {public Object valueWith_with(Object a, Object b)
{
        return (String) a + (String) b
    }}
                          [:a :b | a,b]             // Ignoring the
typing differences
    <null>                [ | ^'This breaks out of everything']
    new Function2Arg() {public Object valueWith_with(Object a, Object b)
{
        return c + (String) a + (String) b
    }}                                              // Note that c must
be "final": the variable must only be allow to reference one object in a
given context execution
                          [:a :b | c,a,b]

Other Stuff
    "\""                  '"'
    "'"                   ''''
    "Hi\tthe\u0032re\n"   <nil>                     // Some because of
unicode, some are available as characters but not in literal strings
                          "hi/there" withCrs

--------------------------------------------

Note that I didn't include the static or package stuff at all.
Partially
I didn't get to it, and partially it would all map to <nil> and <null>
between Smalltalk and Java.  Java's static methods are not even close to
a Class object's methods (static methods aren't even methods, they are
functions or procedures bound at compile time) and there is no real
reason
to map between the two.  Most Smalltalk's don't have any modular
structure
for the name space, so there is no package equivalence.

Note that I also have a Java preprocessor that converts:
    [String a, String b | return a + b;]
into the highly noisy
    new Function2Arg() {public Object valueWith_with(Object a, Object b)
{
        return (String) a + (String) b
    }};
so there is hope for Java having something close to (and actually in
many
ways better than) blocks.

What is Java?
Java is a lightly-statically-typed, simple version of Smalltalk with the
syntax of the 'C' family.

--Mark

http://www.chimu.com/



Sun, 03 Oct 1999 03:00:00 GMT  
 smalltalk - java side by side

Quote:

> Can anyone point me to a www site comparing smalltalk and java,
> things like j ->'this' strongly resembles st->'self',
>        a j -> 'static' procedure resembles a st->'class' method',
>        etc.

[This is just a reformat to < 80 columns of my previous post]

Well, I couldn't think of where on line I have seen what you asked for,
so I threw this together (please be kind about errors).  Also, apologies
for the formatting, I really need to move this to HTML to make it
acceptable on most people's screens (i.e. it will have wierd wrapping
on your news-reader).

A while back I began writing up a comparison of Java and Smalltalk
(showing
the differences if you ignore the static typing in Java), but I haven't
yet had the time to turn seven pages of notes into anything clean enough
to show.

For the list:
If a column is blank it means that the other column entry goes with the
line
above (usually as an example alternative with close semantics).

Java syntax is 1.1.  I picked Smalltalk-80 syntax (some other current
Smalltalk's have some features ST-80 doesn't have).  Also, this is not
meant to be exaustive of either language, but it has enough to get a
feel of each (although I think it is easier if you see a translated
piece of code).  Some of the following use my own naming convention
and libraries.

    Java                  Smalltalk
--------------------------------------------
This and that
    null                  nil
    this                  self
    super                 super
    <null>                self class                 // [1]
    this.getClass()                                  // [2]

General statement structure
    ;                     .
    /*Comment*/           "Comment"
    //Comment             <nil>

Message Sends
    anObject.foo()        anObject foo
    foo()                 self foo                  // [3]
    anObject.foo(a,b)     anObject foo: a with: b
    aDict.atKey_put(key,value)                      // [4]
                          aDict atKey: key put: value

Instance Variables
    x                     x
    this.x                x                         // [5]
    anObject.x            <nil>                     // [6]

Control structures
    if (isTrue)           (isTrue) ifTrue:
    if (...) else         (isTrue) ifTrue: [...] ifFalse: [...].
    switch (...)          <nil>                     // [7]
    while (isTrue)        [] whileTrue: []
    do {} while ()
    for (...;...;...)     <nil>                     // [8]
                          aCollection do:, collect:, etc.
                          anInterval do:
                          (number) timesRepeat: []
    try {} catch (Exception e) {}
    ^                     Exception handle: [:e | ...]
                                    do: [...]
    <null>                anObject a; b             // [9]

Declaring Classes
    class Foo {           Object subclass: #Foo     // [10]
    class Bar extends Foo {
                          Bar subclass: #Foo
    interface Foo         <nil>                     // [11]
    class Bar implements Foo
                          <nil>

Type Declarations
    Object anObject;      | anObject |
    String aString;       <nil>
    Object aString;       | aString |
    int anInt;            <nil>                     // [12]
    Object foo()          foo()
    String foo()          <nil>
    void foo()            <nil>
                          foo()                     // [13]

Type casts
    (Bar) x               <nil>                     // [14]
                          x isKindOf: Bar
                          x respondsTo: #messageForABar
                          (...DoesNotUnderstand...) handle: [:e | ...]
                                                        do: [x
messageForABar]

Access Visibility
    public ... foo()      foo                       // [15]
    protected foo()       <nil>                     // [16]
    public x              <nil>                     // [17]
    protected x           x                         // [18]
    private x             <nil>                     // [19]

Closures/Blocks
    new Function2Arg() {public Object valueWith_with(Object a, Object b)
{
        return (String) a + (String) b
    }}
                          [:a :b | a,b]             // [20]
    <null>                [ | ^'This breaks out of everything']
    new Function2Arg() {public Object valueWith_with(Object a, Object b)
{
        return c + (String) a + (String) b
    }}                                              // [21]
                          [:a :b | c,a,b]

Other Stuff
    "\""                  '"'
    "'"                   ''''
    "Hi\tthe\u0032re\n"   <nil>                     // [22]
                          "hi/there" withCrs

--------------------------------------------
// [1] Java has no class object for each class (Class has no subclasses)
// [2] but it does have a meta object (basically the protocol of 'Class'
itself)
// [3] Although the java message could be a static function
// [4] My Java method naming convention
// [5] The 'this' allows you to get to a shadowed iv
// [6] No public access to another object's ivs
// [7] in most Smalltalk's but see SmalltalkAgents for example
// [8] No direct equivalence is ST, but many alternatives
// [9] No cascades in Java
// [10] Pseudo Smalltalk for the rest, and also
//      see Alan Kay's OOPSLA'96 presentation on declarative Smalltalk
// [11] Smalltalk does not have explicit interfaces, but implicit ones
//      by what messages a class responds to
// [12] no non-object types in Smalltalk, so no int,long,boolean
primitive
//      types
// [13] Just ignore the return value in Smalltalk
// [14] but sort of equivalent to x isKindOf: Bar or the other
alternatives
// [15] Smalltalk methods are public
// [16] by convention this would be in a 'private' protocol
// [17] Smalltalk does not have exposed instance variables
// [18] 'protected' is approximately equivalent to standard Smalltalk
private
// [19] not visible to subclasses
// [20] Ignoring the typing differences
// [21] Note that c must be "final": the variable must only be allow to
//      reference one object in a given context execution
// [22] Some because of unicode, some are available as characters but
not in
//      literal strings

Note that I didn't include the static or package stuff at all.
Partially
I didn't get to it, and partially it would all map to <nil> and <null>
between Smalltalk and Java.  Java's static methods are not even close to
a Class object's methods (static methods aren't even methods, they are
functions or procedures bound at compile time) and there is no real
reason
to map between the two.  Most Smalltalk's don't have any modular
structure
for the name space, so there is no package equivalence.

Note that I also have a Java preprocessor that converts:
    [String a, String b | return a + b;]
into the highly noisy
    new Function2Arg() {public Object valueWith_with(Object a, Object b)
{
        return (String) a + (String) b
    }};
so there is hope for Java having something close to (and actually in
many
ways better than) blocks.

What is Java?
Java is a lightly-statically-typed, simple version of Smalltalk with the
syntax of the 'C' family.

--Mark

http://www.chimu.com/



Sun, 03 Oct 1999 03:00:00 GMT  
 smalltalk - java side by side



Quote:
> // [10] Pseudo Smalltalk for the rest, and also
> //      see Alan Kay's OOPSLA'96 presentation on declarative Smalltalk

I suspect you mean "Allen Wirfs-Brock's OOPSLA'96 presentation"

Allen Wirfs-Brock



Mon, 04 Oct 1999 03:00:00 GMT  
 smalltalk - java side by side

Quote:

> ...
> Well, I couldn't think of where on line I have seen what you asked for,
> so I threw this together (please be kind about errors).
> ...  
> // [10] Pseudo Smalltalk for the rest, and also
> //      see Alan Kay's OOPSLA'96 presentation on declarative Smalltalk

              ^^^^^^^^
Well, that was a MUCH BIGGER error than I was expecting, and my
sincerest apologies to Allen Wirfs-Brock who gave the OOPSLA'96
presentation.  All I can say is I also went flying by my train-stop
today (a much more minor error, but caused by the same malady).  And I
tend to transpose Allens (as my friend Larry Allen well knows)... And
the comet was really pretty last night... sigh... well, just sorry.

In an attempt to give more detailed as well as more accurate
information, here is the OOPSLA URL:
   http://www.bell-labs.com/people/cope/oopsla/#AllenWirfsBrock

and an abstract of the presentation:
------------------------------------------------
A Declarative Model for Defining Smalltalk Programs

Allen Wirfs-Brock, Juanita Ewing, Harold Williams and Brian Wilkerson,
ParcPlace-Digitalk.

Most programming languages have used declarative descriptions for
describing programs Smalltalk has
traditionally used an imperative description. In this paper we describe
Smalltalk's usage of the imperative model, and identify program
maintenance and delivery issues that arise from it. We then present a
declarative alternative for describing Smalltalk programs and show how
the use of such a model addresses maintenance, delivery, and portability
problems encountered by Smalltalk programmers. This model of Smalltalk
programs has been used in the implementation of a commercial Smalltalk
development environment and is an integral part of the Smalltalk
standard which is currently under development by the X3J20 committee.
------------------------------------------------
There was also a related workshop:
    http://www.parcplace.com/oopsla/stwrkshp.html

I thought this presentation material was available online, but I can not
find it right now.  You might want to ask Allen Wirfs-Brock for it: I
suspect we will be provided with his current email address when he
responds to my error (it hasn't hit my server yet).

Thanks again for the presentation and sorry for the brain-slip.

--Mark



Mon, 04 Oct 1999 03:00:00 GMT  
 smalltalk - java side by side

Mark -
I put an html version (with the Allen correction) on my www site
under 'Smalltalk Theory' topics
If you ever get a www page up with this, let me know, and
I will replace my file with a link.

doug edmunds
----

  http://home.paclink.com/users/dae/www/se_main.htm



Tue, 05 Oct 1999 03:00:00 GMT  
 smalltalk - java side by side

Quote:

> Closures/Blocks
>     new Function2Arg() {public Object valueWith_with(Object a, Object b)
> {
>         return (String) a + (String) b
>     }}
>                           [:a :b | a,b]             // [20]
>     <null>                [ | ^'This breaks out of everything']
>     new Function2Arg() {public Object valueWith_with(Object a, Object b)
> {
>         return c + (String) a + (String) b
>     }}                                              // [21]
>                           [:a :b | c,a,b]
> // [20] Ignoring the typing differences
> // [21] Note that c must be "final": the variable must only be allow to
> //      reference one object in a given context execution
> Note that I also have a Java preprocessor that converts:
>     [String a, String b | return a + b;]
> into the highly noisy
>     new Function2Arg() {public Object valueWith_with(Object a, Object b)
> {
>         return (String) a + (String) b
>     }};
> so there is hope for Java having something close to (and actually in
> many
> ways better than) blocks.
> --Mark

> http://www.chimu.com/

This sounds interesting.  Is the pre-processor publicly availiable?
In what ways are they better than Smalltalk blocks?

-- Mike Klein
--

http://www.alumni.caltech.edu/~mklein



Tue, 05 Oct 1999 03:00:00 GMT  
 smalltalk - java side by side



Quote:
> A Declarative Model for Defining Smalltalk Programs

> Allen Wirfs-Brock, Juanita Ewing, Harold Williams and Brian Wilkerson,
> ParcPlace-Digitalk.
...>
> I thought this presentation material was available online, but I can not
> find it right now.  You might want to ask Allen Wirfs-Brock for it: I
> suspect we will be provided with his current email address when he
> responds to my error (it hasn't hit my server yet).

A paper covering this material will appear in the forthcoming OOPSLA'97
Addendum (in SIGPLAN Notices). A slightly shorter version of this paper
can be found at:
http://www.smalltalksystems.com/publications/awss97/SSDCL1.HTM

The slides I used for a presentation on this topic at the Smalltalk
Solutions conference can be found at:
http://www.smalltalksystems.com/publications/awss97/INDEX.HTM

Allen Wirfs-Brock



Fri, 08 Oct 1999 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. smalltalk - java side by side

2. Lines Side by Side?

3. Class side vs Instance Side??

4. Printing group footers side-by-side

5. Report details side by side

6. New MVS REXX Utility: Compare partitioned datasets side-by-side - pdsmatch.zip (1/1)

7. client side or server side scripting- new web user

8. Two text widgets side by side?

9. Java script server side

10. Server-Side Active Content - Smalltalk in HTML?

11. Is it possible to concatenate two text files side by side?

12. How to put columns of two files into one file (side by side)?

 

 
Powered by phpBB® Forum Software