Re: dynamic vs static type checking (was Re: [SLUG] Your top-ten linux desktop apps)

2005-09-29 Thread Bruce Badger
On 9/29/05, Angus Lees [EMAIL PROTECTED] wrote:
 At Tue, 27 Sep 2005 12:00:09 +1000, Bruce Badger wrote:
  In fact, the very best of the JITing VMs can get performance that
  exceeds that attainable by static compilation - because there is
  more information available at run time to base the tuning decisions
  upon.

 If a program's use changes over its invocation, and the JIT
 continually shifts its optimisation targets, then I can see the
 potential benefit of this approach.  I don't believe, however, that
 there are many programs that have this dynamic behaviour.

I agree.  It is only in very dynamic, high throughput and long-lived
services that one would see a measurable benefit in having such a
sophisticated VM, though I would not be surprised to see heavily used
web servers falling into this category.

 You can gain the same runtime knowledge in a statically compiled C
 program by compiling with gcc's -ffprofile-arcs, running over some
 typical use cases (will write a bunch of .gcda files) and then
 recompiling with -fbranch-probabilities.

Right.  For static problems, or problems with a well understood number
of modes of operation static compilation can be superb.  For each new
mode encountered in the wild, though, one would have to tweak the
compiler hints and rebuild to keep up with our imaginary perfect
JITer.

I think the key is your first point.  The cases where absolute
performance is critical are very rare indeed.  I'm happy, though, that
I am using an environment where I can focus on the problem at hand,
and delegate many low-level issues to the environment itself and at
the same time expect performance on a par with (and perhaps even
better than?) the best hand-crafted binaries.

Only real circumstances will tell.  I'd love to work in an environment
that was sophisticated and high-load enough to put some of the
advanced JITing VMs to the test.

All the best,
 Bruce
--
Make the most of your skills - with OpenSkills
http://www.openskills.org/
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: dynamic vs static type checking (was Re: [SLUG] Your top-ten linux desktop apps)

2005-09-28 Thread Angus Lees
At Tue, 27 Sep 2005 12:00:09 +1000, Bruce Badger wrote:
 On 9/27/05, Erik de Castro Lopo [EMAIL PROTECTED] wrote:
  There are large classes of problems where running speed is an
  important issue. Static typing does make for faster run times
  and in cases where that moves your program from being too
  slow to being fast enough, that is not a premature optimisation.
 
 Modern VMs (e.g. many of the Smalltalk VMs) dynamically compile code,
 i.e. they JIT.  
[...]
 In fact, the very best of the JITing VMs can get performance that
 exceeds that attainable by static compilation - because there is
 more information available at run time to base the tuning decisions
 upon.

If a program's use changes over its invocation, and the JIT
continually shifts its optimisation targets, then I can see the
potential benefit of this approach.  I don't believe, however, that
there are many programs that have this dynamic behaviour.

You can gain the same runtime knowledge in a statically compiled C
program by compiling with gcc's -ffprofile-arcs, running over some
typical use cases (will write a bunch of .gcda files) and then
recompiling with -fbranch-probabilities.

-- 
 - Gus
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


dynamic vs static type checking (was Re: [SLUG] Your top-ten linux desktop apps)

2005-09-26 Thread Erik de Castro Lopo
QuantumG wrote:

 Erik de Castro Lopo wrote:
 
 Thats why I'm so keen on O'Caml. It offers even more static analysis
 than C and C++. Its significantly more difficult to write bugs into
 an O'Caml program than a C or C++ program.
 
 Sounds like the antithesis of Objective-C and other dynamically typed 
 languages.

Yep, thats right.

The problem with dynamic typing is that it postones testing for an
important class of errors (type errors) until run time. The main
way of avoiding type errors in dynamically typed languages is by
using a test suite (or face the possibility of sending a program 
with unchecked type errors to your customers). Even if you have a 
test suite, how sure are you that it will catch all errors? How
much effort are you putting into the development of the test 
suite?

Contrast the above with O'Caml (or Haskell) where you cannot create
an executable with type errors [0]. You still need a test suite for
programs written in O'caml, but the set of possible problems to
test for is much smaller and hence requires less effort [1].

Erik

[0] : Well you can, by using the O'caml Marshall module (which most
  O'Caml programmers don't use very often if at all) or by 
  linking O'caml to C code.

[1] : Yes, I'm lazy.



 
 Fun.
 
 Trent
 -- 
 SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
 Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
 


-- 
+---+
  Erik de Castro Lopo
+---+
The object-oriented model makes it easy to build up programs by
accretion. What this often means, in practice, is that it provides
a structured way to write spaghetti code. -- Paul Graham
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: dynamic vs static type checking (was Re: [SLUG] Your top-ten linux desktop apps)

2005-09-26 Thread Bruce Badger
On 9/27/05, Erik de Castro Lopo [EMAIL PROTECTED] wrote:
 The problem with dynamic typing is that it postones testing for an
 important class of errors (type errors) until run time.

Nah.  In fact the oposite is true.  Static typing is just another form
of premature optimisation!

I make extensive use of dynamically typed languages (Smalltalk mostly)
and the class of problem one might imagine that static typing save you
from I just don't encounter in practice.

Each to their own, of course :-)

--
Make the most of your skills - with OpenSkills
http://www.openskills.org/
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: dynamic vs static type checking (was Re: [SLUG] Your top-ten linux desktop apps)

2005-09-26 Thread Bruce Badger
On 9/27/05, Erik de Castro Lopo [EMAIL PROTECTED] wrote:
 There are large classes of problems where running speed is an
 important issue. Static typing does make for faster run times
 and in cases where that moves your program from being too
 slow to being fast enough, that is not a premature optimisation.

Modern VMs (e.g. many of the Smalltalk VMs) dynamically compile code,
i.e. they JIT.  The more sophisticated ones use type inferencing to
tighten up the compiled code at runtime.  This adds the runtime
benefits of having type information to the coding time benefits of
dynamic typing.  In fact, the very best of the JITing VMs can get
performance that exceeds that attainable by static compilation -
because there is more information available at run time to base the
tuning decisions upon.

The down side to JITing is that there is a start-up cost.  Every time
a program starts, the process of compiling and tuning begins. 
Statically compiled code is therefore much faster out of the blocks. 
This is very much like the story of the tortoise and the hare - the
quality JIT will overtake the statically compiled code, but whether it
will do it before the end of the race depends on the length and nature
of the race.

Horses (or tortoises) for courses.

Of course, languages like Ocaml bring bring significant coding time
benefits to the table too!  The declarative nature of Objective Caml
suits some kinds of problems really well.

 Correct me if I'm wrong, but my understanding of Smalltalk is that
 all objects live in a class heirarchy that inherits from a base
 class.

Given a sane programmer - yes.  There are ways to create new root
classes, but anyone doing this in code destined for a production
environment should scolded, and perhaps even spanked.

 That means that given an operation on two objects A and
 B that is not defined on A and B, then the runtime system can
 walk back along the class heirarchy of both A and B until (hopefully)
 it finds parent classes of A and B that do allow the required
 operation.

Exactly

All the best,
 Bruce
--
Make the most of your skills - with OpenSkills
http://www.openskills.org/
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: dynamic vs static type checking (was Re: [SLUG] Your top-ten linux desktop apps)

2005-09-26 Thread yiz




However, other dynamically typed languages like Python, php and to a
lesser extent Perl do not have anywhere near as sane a system. I
suspect that the Smalltalk equivalent of the following Python code
might actually do the right thing:

   a = [ 1, help ]
   b = a + 10

but Python squeals like a stuck pig (read runtime error).



So it should ... just because a language is made for the ease to use does not
mean it should just accept any random input and not to complain.

b = a + 10 isn't exactly  programmingly intuitive, it could potentially mean:

I) b = [l, help, 10]

II) (if l is of type int) b = [l+10, help]

III) b is the address of a plus 10 units.

yiz







--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: dynamic vs static type checking (was Re: [SLUG] Your top-ten linux desktop apps)

2005-09-26 Thread Erik de Castro Lopo
[EMAIL PROTECTED] wrote:

  However, other dynamically typed languages like Python, php and to a
  lesser extent Perl do not have anywhere near as sane a system. I
  suspect that the Smalltalk equivalent of the following Python code
  might actually do the right thing:
 
 a = [ 1, help ]
 b = a + 10
 
  but Python squeals like a stuck pig (read runtime error).
 
 
 So it should ... just because a language is made for the ease to use does not
 mean it should just accept any random input and not to complain.

Yes, I agree that it should complain, but I think it should
complain at compile time in front of the developer, not at
run time in front of the end user.

Erik
-- 
+---+
  Erik de Castro Lopo
+---+
There are only two things wrong with C++: The initial concept and
the implementation. -- Bertrand Meyer
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html