The Artima Developer Community
Sponsored Link

Weblogs Forum
Programming with "Duh" Typing

370 replies on 25 pages. Most recent reply: Aug 8, 2007 9:54 AM by James Watson

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 370 replies on 25 pages [ « | 1 ... 17 18 19 20 21 22 23 24 25 | » ]
James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Programming with "Duh" Typing Posted: Jul 30, 2007 9:28 AM
Reply to this message Reply
Advertisement
> James Watson wrote
> > You'll have to explain what you mean by that if you want
> a
> > meaningful answer.
>
> I mean you seem to be quarreling about definitions without
> providing any.

It's not clear to me why it is necessary to define 'correct' or 'correctness' or explain that they are synonyms. I don't see you defining every common English word that you use.

If it is the case that you aren't clear what 'correct' means in this context, why did you challenge me instead of Achilleas since he introduced the term into the conversation (or reintroduced it anyway.)

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Programming with "Duh" Typing Posted: Jul 30, 2007 9:32 AM
Reply to this message Reply
> James Watson wrote
> > You'll have to explain what you mean by that if you want
> a
> > meaningful answer.
>
> I mean you seem to be quarreling about definitions without
> providing any.

On a side note, the only person in this thread that I have noticed quarreling about definitions is you.

Petrik de Heus

Posts: 19
Nickname: p8
Registered: Jul, 2007

Re: Programming with "Duh" Typing Posted: Jul 30, 2007 10:02 AM
Reply to this message Reply
> Any automated refactoring is superior to manual
> refactoring, even if it's a simple string search/replace
> that asks for confirmation from the user, as is the case
> in dynamically typed languages.

The Ruby refactoring browsers uses the AST to do common refactorings.

http://r2.ifs.hsr.ch/screencasts/extract_method.htm
http://r2.ifs.hsr.ch/screencasts/rename_method.htm

Petrik de Heus

Posts: 19
Nickname: p8
Registered: Jul, 2007

Re: Programming with "Duh" Typing Posted: Jul 30, 2007 10:14 AM
Reply to this message Reply
> - It's never because of a faster edit-compile-run-debug
> cycle. Eclipse makes this cycle ultra fast, and most of
> my time is usually spent getting the system up and running
> (i.e. web server or database accesses) or restoring it to
> a state that corresponds to the area that I'm currently
> working on or debugging.

I haven't seen anything that beats autotest yet.
http://topfunky.com/clients/blog/autotest-tm.mov
Especially with auto saving changed files where I just switch to my terminal app to see the results in a second.
This fast cycle can be very addictive, leading to a lot of frustration when I have to code Java.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Programming with "Duh" Typing Posted: Jul 30, 2007 10:14 AM
Reply to this message Reply
> If you've paid attention, the primary arguments, at least
> as posed by myself and James Watson, have been centered
> around how static typing saves time by:
> (1) Catching typos
> (2) Automating Refactoring
> (3) Increasing code clarity

And I think the most important:

(4) it allows for more precise analysis of code.

This is related to clarity but I think most people think of 'easy to read' when they see clarity. I do anyway.

> If I mispell a function name in a dynamic language, I have
> to wait until something causes that codepath to be
> executed before I find that error. Yes, eventually it
> will be found. But it can take a long time to do it.

You being pretty forgiving by addressing only the point that Achilleas wants to argue.

What he keeps avoiding is addressing the other parts of our argument. Most of the life of an application will be spent in maintenance and I believe that most of the cost of an application is in maintenance and enhancements.

If all we are talking about is getting a working application out of the door, then I think it's possible that using dynamic language may save time. I say 'may' because I'm not sure that dynamic typing is the most important difference between the static typed languages and dynamic typed languages that are commonly compared and contrasted.

In any event my concern is more over what happens a few years down the road. One of the biggest problems I deal with over and over again is that the cost of maintenance increases over time and eventually prevents any forward progress. I am not claiming that static typing eliminates this issue by a long shot. But I do think that dynamic typing can make maintenance much more difficult.

Cedric Beust

Posts: 140
Nickname: cbeust
Registered: Feb, 2004

Re: Programming with "Duh" Typing Posted: Jul 30, 2007 10:21 AM
Reply to this message Reply
> > Any automated refactoring is superior to manual
> > refactoring, even if it's a simple string
> search/replace
> > that asks for confirmation from the user, as is the
> case
> > in dynamically typed languages.
>
> The Ruby refactoring browsers uses the AST to do common
> refactorings.
>
> http://r2.ifs.hsr.ch/screencasts/extract_method.htm
> http://r2.ifs.hsr.ch/screencasts/rename_method.htm

This is actually a perfect illustration of the dangers of dynamic typing.

Here is why.

The video is showing you three classes:

A
B, which extends A
C, which is unrelated to A and B

There three classes define a method "eat". The video shows that if you rename this method to "munch", only A#eat and B#eat get renamed but C#eat is left untouched. Fine.

What the video doesn't show is how this can go wrong.

By virtue of duck typing, I can write the following code:

@animals = []
@animals << A.new
@animals << B.new
@animals << C.new

@animals.each { |a|
a.eat
}

C is unrelated to A and B, but since it has an eat method (duck typing), this code will work.

Except that... it will break after the refactoring since it has now become:

@animals.each { |a|
a.munch
}

and that the third element of @animals is an instance of C, whose "eat" method hasn't been renamed to "munch".

--
Cedric
http://testng.org

Isaac Gouy

Posts: 527
Nickname: igouy
Registered: Jul, 2003

Re: Programming with "Duh" Typing Posted: Jul 30, 2007 10:31 AM
Reply to this message Reply
Cedric Beust wrote
> Any automated refactoring is superior to manual
> refactoring, even if it's a simple string search/replace
> that asks for confirmation from the user, as is the case
> in dynamically typed languages.

It wasn't true that "the Smalltalk IDE ... refactorings ... were just glorified string search/replaces ..." when you stated it in this discussion on Jul 9, 2007 4:03 PM, and it isn't true now that you generalize it to "... a simple string search/replace... as is the case in dynamically typed languages".

Smalltalk refactoring provides search and replace on parse trees - iirc the Java tools that came later followed the same approach.

Isaac Gouy

Posts: 527
Nickname: igouy
Registered: Jul, 2003

Re: Programming with "Duh" Typing Posted: Jul 30, 2007 10:38 AM
Reply to this message Reply
Cedric Beust wrote
> > The Ruby refactoring browsers uses the AST to do common
> > refactorings.

> This is actually a perfect illustration of the dangers of
> dynamic typing.

Cedric, please say whether this example contradicts your much repeated claim that refactoring in dynamically checked languages is simple string search/replace.

Isaac Gouy

Posts: 527
Nickname: igouy
Registered: Jul, 2003

Re: Programming with "Duh" Typing Posted: Jul 30, 2007 10:47 AM
Reply to this message Reply
> > James Watson wrote
> It's not clear to me why it is necessary to define
> 'correct' or 'correctness' or explain that they are
> synonyms. I don't see you defining every common English
> word that you use.
>
> If it is the case that you aren't clear what 'correct'
> means in this context, why did you challenge me instead of
> Achilleas since he introduced the term into the
> conversation (or reintroduced it anyway.)

I stated what I thought was meant by "correct" [Jul 26, 2007 2:51 PM] and when you write "... unit tests also don't prove software to be correct" you seem to be talking about something different.

Petrik de Heus

Posts: 19
Nickname: p8
Registered: Jul, 2007

Re: Programming with "Duh" Typing Posted: Jul 30, 2007 10:59 AM
Reply to this message Reply
> C is unrelated to A and B, but since it has an eat method
> (duck typing), this code will work.
>
> Except that... it will break after the refactoring since
> it has now become:
>
> @animals.each { |a|
> a.munch
> }
>
> and that the third element of @animals is an instance of
> C, whose "eat" method hasn't been renamed to "munch".

Right, and if you try to build the same thing in Java using
reflection you get the same problem.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Programming with "Duh" Typing Posted: Jul 30, 2007 11:03 AM
Reply to this message Reply
> > > James Watson wrote
> > It's not clear to me why it is necessary to define
> > 'correct' or 'correctness' or explain that they are
> > synonyms. I don't see you defining every common
> English
> > word that you use.
> >
> > If it is the case that you aren't clear what 'correct'
> > means in this context, why did you challenge me instead
> of
> > Achilleas since he introduced the term into the
> > conversation (or reintroduced it anyway.)
>
> I stated what I thought was meant by "correct" [Jul 26,
> 2007 2:51 PM] and when you write "... unit tests also
> don't prove software to be correct" you seem to be talking
> about something different.

Yes, I am talking about 'correct' in the way it's defined by the vast majority of English speakers. The definition you attempted to apply to 'correct' is circular.

If we define 'correct' to mean that it compiles then static typing can prove software to be 'correct'. It means nothing.

Rusty Wright

Posts: 8
Nickname: lumpynose
Registered: Jul, 2007

Re: Programming with "Duh" Typing Posted: Jul 30, 2007 11:05 AM
Reply to this message Reply
Achilleas Margaritis wrote:
> I would like to point out that proving statically that
> software is correct is impossible. A static type system
> only proves that what you typed makes some kind of
> sense...but what kind of sense? it's unknown unless you
> run the program.

It seems to me that you're lumping together the idea of the correctness of the logic of the software with the correctness of the software's type usage (e.g., missing methods in Ruby).

The problem for me with that is that with a dynamic language you're relying on unit tests to catch all possible type usage errors. It's possible that some combination of edge cases, exceptions being thrown, etc. could cause an incorrect type to be introduced where it's not expected.

Regardless of whether all lines of code have been exercised by tests you still can't test all possible combinations of events and input.

For me, a statically typed language at least gives me some peace of mind that variables won't get the wrong type.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Programming with "Duh" Typing Posted: Jul 30, 2007 11:08 AM
Reply to this message Reply
> > C is unrelated to A and B, but since it has an eat
> method
> > (duck typing), this code will work.
> >
> > Except that... it will break after the refactoring
> since
> > it has now become:
> >
> > @animals.each { |a|
> > a.munch
> > }
> >
> > and that the third element of @animals is an instance
> of
> > C, whose "eat" method hasn't been renamed to "munch".
>
> Right, and if you try to build the same thing in Java
> using
> reflection you get the same problem.

Reflection in Java is a form of dynamic typing. This is not a thread about Java vs. Ruby. What point do you think you are making here?

Cedric Beust

Posts: 140
Nickname: cbeust
Registered: Feb, 2004

Re: Programming with "Duh" Typing Posted: Jul 30, 2007 11:19 AM
Reply to this message Reply
> > and that the third element of @animals is an instance
> of
> > C, whose "eat" method hasn't been renamed to "munch".
>
> Right, and if you try to build the same thing in Java
> using reflection you get the same problem.

If you are trying to prove that "if you bypass the Java type system, then you end up in the same situation as in a dynamically typed language", then... well, duh.

Not sure what you are trying to prove here and how this relates to the point I was making about the pitfalls of duck typing.

--
Cedric

Cedric Beust

Posts: 140
Nickname: cbeust
Registered: Feb, 2004

Re: Programming with "Duh" Typing Posted: Jul 30, 2007 11:23 AM
Reply to this message Reply
> Cedric Beust wrote
> > > The Ruby refactoring browsers uses the AST to do
> common
> > > refactorings.
>
> > This is actually a perfect illustration of the dangers
> of
> > dynamic typing.
>
> Cedric, please say whether this example contradicts your
> much repeated claim that refactoring in dynamically
> checked languages is simple string search/replace.

I stand corrected. My phrasing was probably too broad, and I was just trying to debunk the myth that "the Smalltalk browser was already doing all these refactorings 20 years ago".

The truth is that it was not, and it could not.

Using an AST to guide a refactoring is certainly a step up from doing a string search/replace, but as I showed above, there is only so far it can go when it's dealing with a tree that doesn't contain any typing information.

--
Cedric
http://testng.org

Flat View: This topic has 370 replies on 25 pages [ « | 17  18  19  20  21  22  23  24  25 | » ]
Topic: Programming with "Duh" Typing Previous Topic   Next Topic Topic: Python 3000 Plea for Help


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2017 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us