From: Xah Lee
Subject: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <1116843690.879540.252900@g14g2000cwa.googlegroups.com>
What are OOP's Jargons and Complexities
Xah Lee, 20050128

The Rise of Classes, Methods, Objects

In computer languages, often a function definition looks like this:
subroutine f (x1, x2, ...) {
  variables ...
  do this or that
}

In advanced languages such as LISP family, it is not uncommon to define
functions inside a function. For example:
subroutine f (x1, x2, ...) {
  variables...
  subroutine f1 (x1...) {...}
  subroutine f2 (x1...) {...}
}

Often these f1 f2 inner functions are used inside f, and are not
relevant outside of f. Such power of the language gradually developed
into a style of programing. For example:
subroutine a_surface () {
  coordinatesList = ...;
  subroutine translate (distance) {...}
  subroutine rotate (angle) {..}
}

Such a style is that the a_surface is no longer viewed as a function.
But instead, a boxed set of functions, centered around a piece of data.
And, all functions for manipulating this piece of data are all embodied
in this function. For example:
subroutine a_surface (arg) {
  coordinatesList = ...
  subroutine translate (distance) {set coordinatesList to translated
version}
  subroutine rotate (angle) {set coordinatesList to rotated version}
  subroutine return () {return coordinatesList}

  if (no arg) {return coordinatesList}
    else { apply arg to coordinatesList }
}

In this way, one uses a_surface as a data, which comes with its owe set
of functions:
mySurface = a_surface();
mySurface(rotate(angle));        // now the surface data has been
rotated
mySurface(translate(distance));  // now its translated
newSurface = mySurface(return())

So now, a_surface is no longer viewed as a subroutine, but a boxed set
of things centered around a piece of data. All functions that work on
the data are included in the boxed set. This paradigm possible in
functional languages has refined so much so that it spread to other
groups and became known as Object Oriented Programing, and complete
languages with new syntax catered to such scheme emerged.

In such languages, instead of writing them like this:
mySurface = a_surface();
mySurface(rotate(angle));

the syntax is changed to like this, for example:
mySurface = new a_surface();
mySurfaceRotated = mySurface.rotate(angle);

In such languages, the super subroutine a_surface is no longer called a
function or subroutine. It is now called a “Class”. And now the
variable holding the function "mySurface = a_surface()" is now called a
“Object”. Subroutines inside the function a_surface() are no longer
called inner-subroutines. They are called “Methods”. The act of
assigning a super-subroutine to a variable is called instantiation.

This style of programing and language have become so fanatical that in
such dedicated languages like Java, everything in the language are
“Classes”. One can no longer just define a variable or subroutine.
Instead, one creates these meta-subroutine “Classes”. Everything
one do are inside Classes. And one assign Classes inside these Classes
to create “Objects”. And one uses “Methods” to manipulate
Objects. In this fashion, even basic primitives like numbers, strings,
and lists are no longer atomic entities. They are now Classes.

For example, in Java, a string is a class String. And inside the class
String, there are Methods to manipulate strings, such as finding the
number of chars, or extracting parts of the string. This can get very
complicated. For example, in Java, there are actually two Classes of
strings: One is String, and the other is StringBuffer. Which one to use
depends on whether you intend to change the data.

So, a simple code like this in normal languages:
a = "a string";
b = "another one";
c = join(a,b);
print c;

or in lisp style
(set a "a string")
(set b "another one")
(set c (join a b))
(print c)

becomes in pure OOP languages:
public class test {
  public static void main(String[] args) {
    String a = new String("a string");
    String b = new String("another one");
    StringBuffer c = new StringBuffer(40);
    c.append(a); c.append(b);
    System.out.println(c.toString());
    }
}

Here, the "new String" creates a String object. The "new
StringBuffer(40)" creates the changeable string object StringBuffer,
with room for 40 chars. "append" is a method of StringBuffer. It is
used to join two Strings.

Notice the syntax "c.append(a)", which we can view it as calling a
inner subroutine "append", on a super subroutine that has been assigned
to c, where, the inner subroutine modifies the inner data by appending
a to it.

And in the above Java example, StringBuffer class has another method
"toString()" used to convert this into a String Class, necessary
because System.out.println's parameter requires a String type, not
StringBuffer.

For a example of the complexity of classes and methods, see the Java
documentation for the StringBuffer class at
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/StringBuffer.html
(local copy)

In the same way, numbers in Java have become a formalization of many
classes: Double, Float, Integer, Long... and each has a bunch of
"methods" to operate or convert from one to the other.

Instead of
aNumber = 3;
print aNumber^3;

In Java the programer needs to master the ins and outs of the several
number classes, and decide which one to use. (and if a program later
needs to change from one type of number to another, it is often
cumbersome.)

This Object Oriented Programing style and dedicated languages (such as
C++, Java) have become a fad like wild fire among the programing mass
of ignoramuses in the industry. Partly because of the data-centric new
perspective, partly because the novelty and mysticism of new syntax and
jargonization.

It is especially hyped by the opportunist Sun Microsystems with the
inception of Java, internet, and web applications booms around 1995. At
those times, OOP (and Java) were thought to revolutionize the industry
and solve all software engineering problems, in particular by certain
"reuse of components" concept that was thought to come with OOP.

As part of this new syntax and purity, where everything in a program is
of Classes and Objects and Methods, many complex issues and concept
have arisen in OOP.

We now know that the jargon Class is originally and effectively just a
boxed set of data and subroutines, all defined inside a subroutine. And
the jargon "Object" is just a variable that has been set to this super
subroutine. And the inner subroutines are what's called Methods.

----------
to be continued tomorrow.

This is part of an installment of the article
“What are OOP's Jargons and Complexities”
by Xah Lee, 20050128. The full text is at
 http://xahlee.org/Periodic_dosage_dir/t2/oop.html

© Copyright 2005 by Xah Lee. Verbatim duplication of the complete
article for non-profit purposes is granted.

The article is published in the following newsgroups:
comp.lang.c,comp.lang.c++,comp.lang.lisp,comp.unix.programmer
comp.lang.python,comp.lang.perl.misc,comp.lang.scheme,comp.lang.java.programmer
comp.lang.functional,comp.object,comp.software-eng,comp.software.patterns

 Xah
 ···@xahlee.org
∑ http://xahlee.org/

From: Eric Lavigne
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <1116854404.037486.200270@g49g2000cwa.googlegroups.com>
>or in lisp style
>(set a "a string")
>(set b "another one")
>(set c (join a b))
>(print c)

This code has a syntax error. If you use "set" then you have to quote
the first argument:
(set 'a "a string")
Alternatively, you could use the more popular setq or setf:
(setq a "a string")
(setf a "a string")
Setq is a macro whose only purpose is to transform (setq x y) to (set
'x y) while setf is a far more powerful macro that can sometimes
perform function inversion to accomplish its task.
From: Eric Lavigne
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <1116855197.434557.301500@g49g2000cwa.googlegroups.com>
>So, a simple code like this in normal languages:
>a = "a string";
>b = "another one";
>c = join(a,b);
>print c;

>becomes in pure OOP languages:
>public class test {
>  public static void main(String[] args) {
>    String a = new String("a string");
>    String b = new String("another one");
>    StringBuffer c = new StringBuffer(40);
>    c.append(a); c.append(b);
>    System.out.println(c.toString());
>    }
>}

I don't think it has to be that complicated. I'm new to Java, and don't
have a compiler handy, but wouldn't this work?

String a = new String("a string");
String b = new String("another one");
String c = a + b;
System.out.printIn(c);
From: Flash Gordon
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <s9a9m2x7vo.ln2@brenda.flash-gordon.me.uk>
Eric Lavigne wrote:

Please don't remove attributions for quoted material.

>>So, a simple code like this in normal languages:

<snip>

> I don't think it has to be that complicated. I'm new to Java, and don't
> have a compiler handy, but wouldn't this work?

<snip>

Please watch for cross posts and remove any groups not appropriate for 
your reply. Java obviously has nothing to do with C, C++ or Lisp so is 
definitely off topic in comp.lang.c and comp.lang.c++ and I assume in 
comp.lang.lisp

Also, this Xah Lee characters original post was off topic in 
comp.lang.c, and from the way s\he massively cross posts stuff obviously 
off topic in several of the groups, I would suggest s\he is a troll and 
not worth responding to.

FU set.
-- 
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
From: Frank Buss
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <10ptwoekjbmzp$.ly4vf6y0o113$.dlg@40tude.net>
Eric Lavigne wrote:

> I don't think it has to be that complicated. I'm new to Java, and don't
> have a compiler handy, but wouldn't this work?
> 
> String a = new String("a string");
> String b = new String("another one");
> String c = a + b;
> System.out.printIn(c);

in Java it is even easier:

String a = "a string";
String b = "another one";
String c = a + b;
System.out.printIn(c);

but Xah Lee is right: in Java you have to wrap it in some function of a
class, so use Lisp:

(defparameter a "a string")
(defparameter b "another one")
(defparameter c (concatenate 'string a b))
c

-- 
Frank Bu�, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
From: ···············@yahoo.com
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <1116875737.529726.32410@z14g2000cwz.googlegroups.com>
The analogy with defparameter is unnecessarily strong, IMO.

(defun main ()
  (let* ((a "a string")
         (b "another one")
         (c (concatenate 'string a b)))
    c))
From: Duck Dodgers
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <1116855699.694164.58160@g47g2000cwa.googlegroups.com>
> a simple code like this in normal languages
How do you define a "normal" language? Your view seems rather narrow.

> or in lisp style
LISP isn't a normal language? So is it an "abnormal" language, since it
doesn't fall into your "normal" and "OOP" world of computer
programming? If find your arguments so far to be nonsensical since
you're having trouble with simple classification.

> becomes in pure OOP languages
Funny how you use the most concise syntax possible for your favored
languages and the least concise possible for your OOP example. A better
Java example would be:

public class test {
  public static void main(String [] args) {
    String a = "a string";
    String b = "another one";
    String c = a + b;
    System.out.println(c);
  }
}

Oddly enough, that's only two logical lines longer than your supposedly
superior examples. Of course, you also need to consider that many
programming languages (that happen to not be OOP) require some form of
framework such as library inclusion of a function at the top lexical
level to act as an entry point, so most runnable examples will be
longer and more complicated whether they be OOP or not. Your example
translated to C would look like this:

#include <stdio.h>
#include <string.h>

int main(void)
{
  char *a = "a string";
  char *b = "another one";
  char c[20];
  strcpy(c, a);
  strcat(c, b);
  puts(c);
  return 0;
}

C isn't OOP, yet the code is longer than even your verbose Java example
and not any easier to understand to a newcomer. Though C isn't a high
level scripting language, so it may be "abnormal" according to your
definition of programming languages.

> This Object Oriented Programing style and dedicated languages (such
as C++, Java)
You realize that C++ isn't an object-oriented programming language,
right? It's a multi-paradigm language that supports several programming
styles, among which, one is OOP. In fact, to make the best use of C++,
you would find yourself mixing multiple styles together to get the
powerful flexibility that makes good applications.

> among the programing mass of ignoramuses in the industry
You don't seem like such a bright bulb yourself. Perhaps if you gave a
more objective and well thought out comparison of OOPL and non-OOPL
then I (and probably most everyone else) wouldn't shrug you off as just
another biased fool who has his head too far up his own ass to smell
the bullshit.

By the way, I'm not a fan of OOP, so my opinion is based completely on
how you presented the material, not my own opinion of the topic.
From: Jirka Klaue
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <op.sq8d3ez44kb77n@mohur.intern.dresearch.de>
Duck Dodgers wrote:

> Your example translated to C would look like this:
> #include <stdio.h>
> #include <string.h>
> int main(void)
> {
>   char *a = "a string";
>   char *b = "another one";
>   char c[20];
>   strcpy(c, a);
>   strcat(c, b);
>   puts(c);
>   return 0;
> }

ITYM:

   #include <stdio.h>
   #include <string.h>

   int main(void)
   {
     char *a = "a string", *b = "another one", c[20];
     puts(strcat(strcpy(c, a), b));
   }

   /* ;-) */

Jirka
From: Duck Dodgers
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <1116857859.702850.249530@o13g2000cwo.googlegroups.com>
I say what I mean and mean nothing at all. ;-) Putting aside the
stylistic reasons for not performing multiple definitions/operations on
a single line, my example was a direct translation of the Python-esque
code, it wasn't intended to be the most concise C possible. And I also
don't compile as C99, so your code would have undefined behavior for
me. So no, that's not what I meant at all. ;-)
From: Richard Bos
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <4291ee76.276511186@news.xs4all.nl>
"Jirka Klaue" <······@tkn.tu-berlin.de> wrote:

> ITYM:
> 
>    #include <stdio.h>

And _I_ think you all mean: "Oops, we shouldn't have followed up to a
known kook and/or troll".

HTH; HAND.

Richard
From: Morten Alver
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <d6sop6$n0s$1@orkan.itea.ntnu.no>
> ITYM:
> 
>   #include <stdio.h>
>   #include <string.h>
> 
>   int main(void)
>   {
>     char *a = "a string", *b = "another one", c[20];
>     puts(strcat(strcpy(c, a), b));
>   }
> 
>   /* ;-) */

Just for the record, in Java you could write:

String a = "a string", b = "another one", c = a+b;
System.out.println(c);

All of this is irrelevant, the point is that the comparison by the OP is
meaningless as an example of what OOP leads to.


--
Morten
From: Tim X
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <87psvh9fge.fsf@tiger.rapttech.com.au>
Morten Alver <······@invalid.no> writes:

> > ITYM:
> > 
> >   #include <stdio.h>
> >   #include <string.h>
> > 
> >   int main(void)
> >   {
> >     char *a = "a string", *b = "another one", c[20];
> >     puts(strcat(strcpy(c, a), b));
> >   }
> > 
> >   /* ;-) */
> 
> Just for the record, in Java you could write:
> 
> String a = "a string", b = "another one", c = a+b;
> System.out.println(c);
> 
> All of this is irrelevant, the point is that the comparison by the OP is
> meaningless as an example of what OOP leads to.
> 
The OP is a fool and well known to be one. Xah has a reputation for
posting flawed and incorrect information on a regular basis. I think
it was only last week he was claiming Perl didn't support lists and
today he is claiming that *everything* in Java is a class - unless
things have changed a lot since I escaped java 6 years ago, not
everything is a class - for example int, double and float do not have
to be classes (though they do have class versions as well). In fact, I
seem to remember in my initial reading concerning the design of Java
that it was decided that making everyting a class was a *bad idea*,
especially for arithmetic, which is why int, double, float are not
implemented as objects and that the object versions are included for
when you need interoperability with class objects. 

If you want a good laugh, visit Xah's homepage. He makes some
incredibly amusing claims and statements of 'fact' - as they say, on
the Internet, nobody knows your a dog!

Tim
 
-- 
Tim Cross
The e-mail address on this message is FALSE (obviously!). My real e-mail is
to a company in Australia called rapttech and my login is tcross - if you 
really need to send mail, you should be able to work it out!
From: alex goldman
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <1482841.4WpqR85RcB@yahoo.com>
Tim X wrote:

> If you want a good laugh, visit Xah's homepage.

He mentions that over a million people already visit it per year.
From: Stephane Zuckerman
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <Pine.OSF.4.58.0505231641300.447918@vega.utc.fr>
> ITYM:
>
>    #include <stdio.h>
>    #include <string.h>
>
>    int main(void)
>    {
>      char *a = "a string", *b = "another one", c[20];
>      puts(strcat(strcpy(c, a), b));
>    }
>
>    /* ;-) */

You're cheating ! :-)

public class test {
  public static void main(String [] args) {
    String a = "a string", b = "another one";
    System.out.println(a + b); // yes, I know you already know that :-)
  }
} // Java - 1 ; C - 0... O:-)


-- 
"Je deteste les ordinateurs : ils font toujours ce que je dis, jamais ce
que je veux !"
"The obvious mathematical breakthrough would be development of an easy
way to factor large prime numbers." (Bill Gates, The Road Ahead)
From: Ola Bini
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <d6sohr$k6v$1@news.su.se>
If you're going to critize programming paradigms - and specific 
languages - wouldn't it be GREAT to actually be fluent in the languages 
you're talking about? There are quite a few problems with the things 
you've said:

 > We now know that the jargon Class is originally and effectively just a
 > boxed set of data and subroutines, all defined inside a subroutine. And
 > the jargon "Object" is just a variable that has been set to this super
 > subroutine. And the inner subroutines are what's called Methods.
 >

No, this is incorrect. There is no possibility to actually model 
subclasses if a Class only was a "supersubroutine".

 > In Java the programer needs to master the ins and outs of the several
 > number classes, and decide which one to use. (and if a program later
 > needs to change from one type of number to another, it is often
 > cumbersome.)

This is simply NOT TRUE. Java has primitive number types, which makes 
these simple to work with, very much like C data types.

 > And in the above Java example, StringBuffer class has another method
 > "toString()" used to convert this into a String Class, necessary
 > because System.out.println's parameter requires a String type, not
 > StringBuffer.

This is, as almost all your statements, not true. What you don't mention 
is that PrintStream.println() actually is overloaded to take an Object, 
and call that objects toString() automatically.

 > For a example of the complexity of classes and methods, see the Java
 > documentation for the StringBuffer class at
 > http://java.sun.com/j2se/1.4.2/docs/api/java/lang/StringBuffer.html

This doesn't actually SAY anything. I could give you a few links to CLHS 
pages, which define the functions and macros for working with strings 
and sequences, and you would easily find as much complexity there.

 > public class test {
 >   public static void main(String[] args) {
 >     String a = new String("a string");
 >     String b = new String("another one");
 >     StringBuffer c = new StringBuffer(40);
 >     c.append(a); c.append(b);
 >     System.out.println(c.toString());
 >     }
 > }

As already been noted here, the idiomatic Java way of writing this looks 
somewhat like this:

public class Test {
	public static void main(final String[] args) {
	  final String a = "a string";
	  final String b = "another one";
	  final String c = a + b;
	  System.out.println(c);
         }
}

Furthermore, you could do this in a simple functional style like this:
public class Test {
	public static void main(final String[] args) {
	  System.out.println("a string" + "another one");
         }
}

 > For example, in Java, a string is a class String. And inside the class
 > String, there are Methods to manipulate strings, such as finding the
 > number of chars, or extracting parts of the string. This can get very
 > complicated. For example, in Java, there are actually two Classes of
 > strings: One is String, and the other is StringBuffer. Which one to use
 > depends on whether you intend to change the data.

This is also incorrect. The String class is the only one class available 
for handling strings. The StringBuffer/StringBuilder is simply an 
utility class.



I do not say that OO is good for everything. In fact I hold the opposite 
view, that it's harmful in many instances. The Lisp way is almost always 
better. This critique is purely based on the fact that your column was 
very full of errors and omitted information.

/O
From: Stefaan A Eeckels
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <20050523165719.35c312f0.tengo@DELETEMEecc.lu>
On 23 May 2005 03:21:30 -0700
"Xah Lee" <···@xahlee.org> wrote:

> Ill-informed drivel

                                  ___________________
                          /|  /|  |                  |
                          ||__||  |      Please do   |
                         /   O O\__         NOT      |
                        /          \     feed the    |
                       /      \     \     troll      |
                      /   _    \     \ ______________|
                     /    |\____\     \     ||
                    /     | | | |\____/     ||
                   /       \|_|_|/   \    __||
                  /  /  \            |____| ||
                 /   |   | /|        |      --|
                 |   |   |//         |____  --|
          * _    |  |_|_|_|          |     \-/
       *-- _--\ _ \     //           |
         /  _     \\ _ //   |        /
       *  /   \_ /- | -     |       |
         *      ___ c_c_c_C/ \C_c_c_c____________


-- 
Stefaan
-- 
As complexity rises, precise statements lose meaning,
and meaningful statements lose precision. -- Lotfi Zadeh 
From: ···@xahlee.org
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <1117003250.853915.193290@f14g2000cwb.googlegroups.com>
The Rise of “Static” versus “Instance” variables

In a normal programing language, variables inside functions are used by
the function, called local variables.

In OOP paradigm, as we've seen, super-subroutines (classes) are
assigned to variables (instantiation), and the inner-subroutines
(methods) are called thru the variables (objects). Because of this
mechanism, what's once known as local variables (class variables) can
now also be accessed thru the assigned variable (objet) by design. In
OOP parlance, this is to say that a class's variables can be accessed
thru the object reference, such as in myObject.data=4. For example:
mySurface = new a_surface();
mySurface.coordinatesList={...} // assign initial coordinates

However, sometimes a programmer only needs a collection of variables.
For exmple, a list of colors:
black = "#000000";
gray = "#808080";
green = "#008000";

In pure OOP, data as these now come with a subroutine (class) wrapper:
class listOfColors() {
  black = "#000000";
  gray = "#808080";
  green = "#008000";
}

Now to access these values, normally one needs to assign this
subroutine (class) to a variable (instantiation) as to create a object:
myColors = new listOfColors(); // instantiation! (creating a "object")
newColor = myColors.black;

As a workaround of this extraneous step is the birth of the concept of
“static” variables. (with the keyword “static” in Java) When a
variable is declared static, that variable can be accessed without
needing to instantiate its class. Example:
class listOfColors() {
  static black = "#000000";
  static gray = "#808080";
  static green = "#008000";
}
newColor = listOfColors.black;   // no instantiation required

The issue of staticality is also applicable to inner-subroutines
(methods). For example, if you are writing a collection of math
functions such as Sine, Cosine, Tangent... etc, you don't really want
to create a instance in order to use. Example:
class mathFunctions() {
  static sin (x) {...};         // a static method
  ...
}
print mathFunctions.sin(1);  // no need to create object before use


The non-static variant of variables and methods are called “instance
variables” or “instance methods”, or collectively “instance
members”. Note that static members and instance members are very
different. With static members, variables and methods can be called
without creating a object. But more subtly, for a static variable,
there is just one copy of the variable; for instance variables, each
object maintains its own copy of the variable. A class can declare just
some variables static. So, when multiple objects are created from the
class, some variables will share values while others having independent
copies. For example:
class a_surface() {
  static pi;                     // a static variable
  coordinatesList;               // a instance variable
  ...
};
a_surface.pi=3.1415926;          // assign value of pi for all
a_surface objects
mySurface1 = new a_surface();
mySurface1.coordinatesList={...} // assign coordinates to one a_surface
object
mySurface2 = new a_surface();
mySurface2.coordinatesList={...} // assign coordinates to another
a_surface object

The issues of static versus instance members, is one complexity arising
out of OOP.

----------
to be continued tomorrow.

This is part of an installment of the article
“What are OOP's Jargons and Complexities”
by Xah Lee, 20050128. The full text is at
 http://xahlee.org/Periodic_dosage_dir/t2/oop.html

© Copyright 2005 by Xah Lee. Verbatim duplication of the complete
article for non-profit purposes is granted.

The article is published in the following newsgroups:
comp.lang.c,comp.lang.c++,comp.lang.lisp,comp.unix.programmer
comp.lang.python,comp.lang.perl.misc,comp.lang.scheme,comp.lang.java.programmer
comp.lang.functional,comp.object,comp.software-eng,comp.software.patterns

 Xah
 ···@xahlee.org
∑ http://xahlee.org/
From: Xah Lee
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <1117264296.056307.66000@o13g2000cwo.googlegroups.com>
The Rise of “Constructors” and “Accessors”

A instantiation, is when a variable is assigned a super-subroutine
(class). A variable assigned such a super-subroutine is now called a
instance of a class or a object.

In OOP practice, certain inner-subroutines (methods) have developed
into specialized purposes. A inner-subroutine that is always called
when the super-subroutine is assigned to a variable (instantiation), is
called a constructor or initializer. These specialized
inner-subroutines are sometimes given a special status in the language.
For example in Java the language, constructors are different from
methods.

In OOP, it has developed into a practice that in general the data
inside super-subroutines are supposed to be changed only by the
super-subroutine's inner-subroutines, as opposed to by reference thru
the super-subroutine. (In OOP parlance: class's variables are supposed
to be accessed/changed only by the class's methods.) Though this
practice is not universal or absolute. Inner-subroutines that change or
return the value of variables are called accessors. For example, in
Java, a string class's method length() is a accessor.

Because constructors are usually treated as a special method at the
language level, its concept and linguistic issues is a OOP machinery
complexity, while the Accessor concept is a OOP engineering complexity.

-----
to be continued tomorrow.

This is part of an installment of the article
“What are OOP's Jargons and Complexities”
by Xah Lee, 20050128. The full text is at
 http://xahlee.org/Periodic_dosage_dir/t2/oop.html

© Copyright 2005 by Xah Lee. Verbatim duplication of the complete
article for non-profit purposes is granted.

The article is published in the following newsgroups:
comp.lang.c,comp.lang.c++,comp.lang.lisp,comp.unix.programmer
comp.lang.python,comp.lang.perl.misc,comp.lang.scheme,comp.lang.java.programmer
comp.lang.functional,comp.object,comp.software-eng,comp.software.patterns

 Xah
 ···@xahlee.org
∑ http://xahlee.org/
From: Xah Lee
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <1117532542.488203.153210@z14g2000cwz.googlegroups.com>
the Rise of “Access Specifiers” (or, the Scoping Complexity of OOP)

In programing, a variable has a scope — meaning where the variable
can be seen. Normally, there are two basic models: dynamically scoped
and lexically scoped. Dynamic scoping is basically a time based system,
while lexical scoping is text based (like “what you see is what you
get”). For example, consider the following code:
subroutine f() {return y}
{y=3; print f()}

In dynamic scoping, the printed result is 3, because during evaluation
of the block all values of y is set to 3. In lexical scoping, “y”
is printed because any y in the block is set to 3 before f is called.
With regards to language implementation, Dynamic Scoping is the
no-brainer of the two, and is the model used in earlier languages. Most
of the time, lexical scoping is more natural and desired.

Scoping is also applicable to subroutines. That is to say, where
subroutines can be seen. A subroutine's scope is usually at the level
of source file (or a concept of a module/package/library), because
subroutines are often used in the top level of a source file, as
opposed to inside a code block like variables.

In general, the complexity of scoping is really just how deeply nested
a name appears. For example see in the following code:
name1;     // top level names. Usually subroutines, or global
variables.
{
  name2    // second level names. Usually variables inside subroutines.
  {
    name3  // deeper level names. Less often used in structured
programing.
  }
}

If a programing language uses only one single file of commands in
sequence as in the early languages such as BASIC, there would be no
scoping concept. The whole program is of one single scope.

OOP has created a immense scoping complexity because its mode of
computing is calling nested subroutines (methods) inside subroutines
(classes). We detail some aspects in the following.

In OOP, variables inside subroutines (class variables) can also be
accessed thru a reference the subroutine is assigned to (that is, a
object). In OOP parlance: a variable in a class has a scope, while the
same variable when the class is instantiated (a objet) is a different
scoping issue. In other words, OOP created a new entity “variable
thru reference” that comes with its own scoping issue. For example:
class a_surface() {
  coordinates={...};               // a variable
}

class main() {
  mySurface = new a_surface();
  mySurface.coordinates = {...};   // the same variable
}

In the above code, the variable “coordinates” appears in two
places. Once as defined inside a_surface, and once as a instantiated
version of a_surface, that is, a object. The variable as thru the
object reference apparently has a entirely different scoping issue than
the same variable inside the subroutine (class) definition. The
question for OOP language designers is: what should the scope be for
variables referred thru objects? Within the class the object is
created? within the class the variable is defined? globally? (and what
about inherited classes? (we will cover OOP inheritance later))

As we've seen, methods are just inner-subroutines, and creating objects
to call methods is OOP's paradigm. In this way, names at the
second-level programing structure often associate with variables (and
inner-subroutines), is now brought to the forefront. This is to say,
the scoping of subroutines are raised to a level of complexity as the
scoping of variables. (they are now both in the 2nd level of names (or
deeper).)

All in all, the scoping complexities of OOP as applied to different OOP
entities (classes, class variables, class's methods, object variables
and methods) is manifested as access specifiers in Java. In Java,
access specifiers are keywords “private”, “protected”,
“public”, used to declare the scope of a entity. Together with a
default scope of no-declaration, they create 4 types of scope, and have
entirely different effects when used upon a variable, a method, a
constructor, and a class.

See this tutorial of Java's access specifiers for detail:
http://xahlee.org/java-a-day/access_specifiers.html
-----
to be continued tomorrow.

This is part of an installment of the article
“What are OOP's Jargons and Complexities”
by Xah Lee, 20050128. The full text is at
 http://xahlee.org/Periodic_dosage_dir/t2/oop.html

© Copyright 2005 by Xah Lee. Verbatim duplication of the complete
article for non-profit purposes is granted.

The article is published in the following newsgroups:
comp.lang.c,comp.lang.c++,comp.lang.lisp,comp.unix.programmer
comp.lang.python,comp.lang.perl.misc,comp.lang.scheme,comp.lang.java.programmer
comp.lang.functional,comp.object,comp.software-eng,comp.software.patterns

 Xah
 ···@xahlee.org
∑ http://xahlee.org/
From: Xah Lee
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <1117829975.997101.286830@f14g2000cwb.googlegroups.com>
The Rise of “Inheritance”

In well-thought-out languages, functions can have inner functions, as
well as taking other functions as input and return function as output.
Here are some examples illustrating the use of such facilities:
subroutine generatePower(n) {
  return subroutine (x) {return x^n};
}

In the above example, the subroutine generatePower returns a function,
which takes a argument and raise it to nth power. It can be used like
this:
print generatePower(2)(5)  // prints 25

Example: fixedPoint:
subroutine fixedPoint(f,x) {
  temp=f(x);
  while (f(x) != temp) {
    temp=f(temp);
  }
  return temp;
}

In the above example, fixedPoint takes two arguments f and x, where f
is taken to be a function. It applies f to x, and apply f to that
result, and apply f to that result again, and again, until the result
is the same. That is to say, it computes f[f[f[...f[x]...]]].
FixedPoint is a math notion. For example, it can be employeed to
implement Newton's Method of finding solutions as well as many problems
involving iteration or recursion. FixedPoint may have a optional third
parameter of a true/false function fixedPoint(func,arg,predicate) for
determining when the nesting should stop. In this form, it is
equivalent to the “while loop” in procedural languages.

Example: composition:
subroutine composition(a,b,c,...) {
  return subroutine {a(b(...c...))};
}

The above example is the math concept of function composition. That is
to say, if we apply two functions in sequence as in g[f[x]], then we
can think of it as one single function that is a composition of f and
g. In math notation, it is often denoted as (g∘f). For example,
g[f[x]]→y is the same as (g∘f)[x]→y. In our pseudo-code, the
function composition takes any number of arguments, and returns a
single function of their composition.

When we define a subroutine, for example:
subroutine f(n) {return n*n}

the function is power of two, but the function is named f. Note here
that a function and its name are two different concepts. In
well-thought-out languages, defining a function and naming a function
are not made inseparable. In such languages, they often have a keyword
“lambda” that is used to define functions. Then, one can assign it
a name if one so wishes. This separation of concepts made many of the
lingustic power in the above examples possible. Example:
lambda (n) {return n^2;}        \\ a function
(lambda (n) {return n^2;})(5)   \\ a function applied to 5.
f = lambda (n) {return n^2;}    \\ a function is defined and named
f(5)                            \\ a function applied to 5.
lambda (g) {return lambda {g(f)} }     \\ a function composition of
(g∘f).


The above facilities may seem exotic to industrial programers, but it
is in this milieu of linguistic qualities the object oriented paradigm
arose, where it employees facilities of inner function (method),
assigning function to variable (instantiation), function taking
function as inputs (calling method thru object), and application of
function to expressions (applying method to data in a class).

The data-bundled-with-functions paradigm finds fitting application to
some problems. With the advent of such Objet-Oriented practice, certain
new ideas emerged. One of great consequence is the idea of inheritance.

In OOP practice computations are centered around data as entities of
self-contained boxed sets (objects). Thus, frequently one needs
slightly different boxed sets than previously defined. Copy and Pasting
existing code to define new boxed sets quickly made it unmanageable. (a
messy set of classes). With powerful lingustic evironment and
habituation, one began to write these new boxed-subroutines (classes)
by extending old subroutines (classes) in such a way that the new
subroutine contains all variables and subroutines of a base subroutine
without any of the old code appearing in the body of the subroutine.
Here is a pseudo-code illustration:
g = subroutine extend(f) {
  new variables ...
  new inner-subroutines ...
  return a subroutine that also contains all stuff in subroutine f
}

Here, “extend” is a function that takes another function f, and
returns a new function such that this new function contains all the
boxed-set things in f, but added its own. This new boxed-set subroutine
is given a name g.

In OOP parlance, this is the birth of inheritance. Here, g inherited
from that of f. f is called the base class or superclass of g. g is the
derived class or subclass of f.

In functional terms, inheritance mechanism is a function E that takes
another function f as input and returns a new function g as output,
such that g contained all enclosed members of f with new ones defined
in E. In pure OOP languages such as Java, the function E is exhibited
as a keyword “extends”. For example, the above code would be in
Java:
class g extends f {
  new variables ...
  new inner-subroutines ...
}

Here is the same example in Python, where inheritance takes the form of
a class definition with a parameter:
class g(f):
  new variables ...
  new inner-subroutines ...


Data are the quintessence in computation. Because in OOP all data are
embodied in classes, and wrapping a class to each and every variety of
data is unmanageable, inheritance became the central means to manage
data.

-----
to be continued tomorrow.

This is part of an installment of the article
“What are OOP's Jargons and Complexities”
by Xah Lee, 20050128. The full text is at
 http://xahlee.org/Periodic_dosage_dir/t2/oop.html

© Copyright 2005 by Xah Lee. Verbatim duplication of the complete
article for non-profit purposes is granted.

The article is published in the following newsgroups:
comp.lang.c,comp.lang.c++,comp.lang.lisp,comp.unix.programmer
comp.lang.python,comp.lang.perl.misc,comp.lang.scheme,comp.lang.java.programmer
comp.lang.functional,comp.object,comp.software-eng,comp.software.patterns

 Xah
 ···@xahlee.org
∑ http://xahlee.org/
From: lin8080
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <42A248E0.24C0A244@freenet.de>
Xah Lee schrieb:

> In OOP practice computations are centered around data as entities of
> self-contained boxed sets (objects). Thus, frequently one needs
> slightly different boxed sets than previously defined. Copy and Pasting
> existing code to define new boxed sets quickly made it unmanageable. (a
> messy set of classes). With powerful lingustic evironment and
> habituation, one began to write these new boxed-subroutines (classes)
> by extending old subroutines (classes) in such a way that the new
> subroutine contains all variables and subroutines of a base subroutine
> without any of the old code appearing in the body of the subroutine.

Hallo

To set a new idea I try to describe the oppostite here:
Assume you want n*n to any numbers. So give your OO-Box a few examples
and let the programm(s) have a look for the right methode.

3*3  --> 9
8*8  --> 64
... (working until return happen)

This will show you how many objects you have you can only use for
exactly one thing. Those objects should be removed (they are
problem-oriented). All other objects you can use for more than one case
are better. And consequently you have a new viewpoint to inherit
(recursive inherit, when a method can change other methods cross and
backwards).
Doing so to all objects will give you no control about what happens
inside. You only judge the result to: is good or not. At this point you
may see, what object oriented can be else. This can end in a object
environment, where all objects do more or less the same thing.

Or, an other try:

What you have is kind of monolithic. One object, one variable, one
process to manipulate the variable and one return value of the
manipulated variable. Maybe you take two or more variables in, the
variables have to be of the same kind (say all integer), otherwise your
object can't handle this. 
Now your objekt should realize the type of variable and then be able to
give the variable to another object, which can handle that type. So
create a directions-object that calls other objects as
subroutines/methods to get a return value. You need a describer object,
that should know all kinds of variable-types the system can handle and
the special subroutine for not handled datas to create a new set of
subroutines. If it is good, one object passes variables only once and do
not controll, what other objects do. Else, when you allow your object(s)
to change itself, there is no need for new objects and your system keeps
small but the passthorugh time can be longer. (In my experiments I come
to oneway layers.)

stefan
From: Xah Lee
Subject: Re: What are OOP's Jargons and Complexities?
Date: 
Message-ID: <1118167370.436359.13310@g49g2000cwa.googlegroups.com>
The Rise of Class Hierarchy

Because of psychological push for purity, in Java there are no longer
plain subroutines. Everything is a method of some class. Standard
functions like opening a file, square root a number, for loop thru a
list, if else branching statements, or simple arithmetic operations...
must now somehow become a method of some class. In this way, coupled
with the all-important need to manage data with inheritance, the OOP
Class Hierarchy is born.

Basic data types such as now the various classes of numbers, are now
grouped into a Number class hierarchy, each class having their own set
of methods. The characters, string or other data types, are lumped into
one hierarchy class of data types. Many types of lists (variously known
as arrays, vectors, lists, hashes...), are lumped into a one hierarchy,
with each Classe node having its own set methods as appropriate. Math
functions, are lumped into some math class hierarchy.

Now suppose the plus operation +, where does it go? Should it become
methods of the various classes under Number headings, or should it be
methods of the Math class set? Each language deals with these issues
differently. As a example, see this page for the hierarchy of Java's
core language classes:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/package-tree.html
(local copy)

OOP being inherently complex exacerbated by marketing propaganda, and
the inheritance and hierarchy concept is so entangled in OOP, sometimes
OOP is erroneously thought of as languages with a hierarchy. (there are
now also so-called Object-Oriented databases that ride the fad of
“all data are trees” ...)

Normally in a program, when we want to do some operation we just call
the subroutine on some data. Such as
open(this_file)
square(4)

But now with the pure OOP style, there can no longer be just a number
or this_file path, because everything now must be a Object. So, the
"this_file", usually being just a string representing the path to a
file on the disk, is now some "file object". Initiated by something
like
this_file = new File("path to file");

where this file class has a bunch of methods such as reading or writing
to it.

see this page for the complexity of the IO tree
http://java.sun.com/j2se/1.4.2/docs/api/java/io/package-tree.html
(local copy)

see this page for the documentation of the File class itself, along
with its 40 or so methods and other things.
http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html (local copy)

-------
to be continued...

This is part of an installment of the article
“What are OOP's Jargons and Complexities”
by Xah Lee, 20050128. The full text is at
 http://xahlee.org/Periodic_dosage_dir/t2/oop.html

© Copyright 2005 by Xah Lee. Verbatim duplication of the complete
article for non-profit purposes is granted.

The article is published in the following newsgroups:
comp.lang.c,comp.lang.c++,comp.lang.lisp,comp.unix.programmer
comp.lang.python,comp.lang.perl.misc,comp.lang.scheme,comp.lang.java.programmer
comp.lang.functional,comp.object,comp.software-eng,comp.software.patterns

 Xah
 ···@xahlee.org
∑ http://xahlee.org/