Static typing, polymorphism, inheritance
From: Costin Cozianu (c_cozianu_at_hotmail.com)
Date: 10/31/03
- Next message: Dave Harris: "Re: Naive, possibly silly question"
- Previous message: Ken: "Estimating OO?"
- Next in thread: Thomas G. Marshall: "Re: Static typing, polymorphism, inheritance"
- Reply: Thomas G. Marshall: "Re: Static typing, polymorphism, inheritance"
- Reply: TLOlczyk: "Re: Static typing, polymorphism, inheritance"
- Reply: TLOlczyk: "Re: Static typing, polymorphism, inheritance"
- Reply: TLOlczyk: "Re: Static typing, polymorphism, inheritance"
- Reply: Dave Harris: "Re: Static typing, polymorphism, inheritance"
- Reply: Topmind: "Re: Static typing, polymorphism, inheritance"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 31 Oct 2003 13:05:51 -0800
S Perryman wrote:
> "Ilja Preuß" <preuss@disy.net> wrote in message news:<bniju3$pq4$1@stu1id2.ip.tesion.net>...
>
>
>>S Perryman wrote:
>
>
>>[ code fragment snipped for brevity ... ]
>
>
>>The above is a perfectly normal thing to do in any dynamically typed OO
>>language, so it's certainly not impossible. So, what is your point again?
>
>
> The most obvious point seems to be that you obviously don't understand
> the
> example.
>
> Who says the above is a fragment from a "dynamically typed" prog lang
> ??
> Not me pal. You obviously was driven by some compelling need to assume
> so.
> Why is that ??
>
> To compound your mistake, assume the example is from a
> *strictly-typed* prog lang. With the extra piece of information, try
> to answer the original
> question (repeated again) if you have the ability to do so (tis not
> easy
> IMHO) :
>
> * Why it is impossible (theoretically or practically) for a s/w
> * system to ever be able to allow #2 , unless Person and Employee have
> * an inheritance relationship.
>
> Hint: heed the "CS101" comment before you try to answer ...
>
>
> Regards,
> Steven Perryman
It's not exactly CS 101, but anyway it's time to unveil the mistery.
Here's some code, totally statically typed, if Uncle Bob et. comp
recognizes the language, we should give him a prize with if he also
promises for the future to stay within his area of expertise:.
---
class person name_ age_=
object
val name = name_
val age = age_
method getAge() = age
method getName() = name
method print stream =
Printf.fprintf stream "This is me: %s, age %d" name age
end
;;
class employee name_ age_ empID_=
object
val name = name_
val age = age_
val empID= empID_
method getAge() = age
method getName() = name
method print stream =
Printf.fprintf stream "This is me: %s, age %d, ID: %x"
name age empID
end
;;
let showPerson p=
print_endline ( p#getName() );
print_endline ( string_of_int (p#getAge()) )
;;
let x= new person "Steve" 25
let y= new employee "Costin" 25 1001
;;
showPerson x ;;
showPerson y ;;
(* or even better, here's a polymorphic list : *)
let myList= [ new person "Steve" 20 ; new employee "Costin" 20 1001]
;;
(* And here's a kind of iteration, functional style *)
List.map (fun x -> x#print stdout) myList
;;
----
The code above is totally and irreversibly statically typed, and it does
what one expects it to do. The 2 classes person and employee are in no
relation whatsoever with each other, and obviosuly not in an inheritance
relation, although the language does also support inheritance.
The # replaced the do in typical OO languages, cause it's a little bit
funkier.
Inspite programmers having the option to avoid type annotations, it
still is considered *bad style* to leave the code like I did above --
that is Python style -- and most programmers will annotate the important
variables and parameters with their types.
All this fuss about Python and dynamic typing that it speeds up
development and stuff by saving you a few keystorke is much ado about
nothing. Actually what it does is it helps you not to think about what
you are doing, and even when you do think about it, it helps you not to
write it down, so that the next person who looks at the code will have
to perform a very expensive work of figuring out what's all about.
best,
Costin
- Next message: Dave Harris: "Re: Naive, possibly silly question"
- Previous message: Ken: "Estimating OO?"
- Next in thread: Thomas G. Marshall: "Re: Static typing, polymorphism, inheritance"
- Reply: Thomas G. Marshall: "Re: Static typing, polymorphism, inheritance"
- Reply: TLOlczyk: "Re: Static typing, polymorphism, inheritance"
- Reply: TLOlczyk: "Re: Static typing, polymorphism, inheritance"
- Reply: TLOlczyk: "Re: Static typing, polymorphism, inheritance"
- Reply: Dave Harris: "Re: Static typing, polymorphism, inheritance"
- Reply: Topmind: "Re: Static typing, polymorphism, inheritance"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|