The Artima Developer Community
Sponsored Link

Artima Developer Spotlight Forum
Michael Feathers on Patronizing Language Design

37 replies on 3 pages. Most recent reply: Jul 30, 2009 12:36 AM by Darko Latkovic

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 37 replies on 3 pages [ « | 1 2 3 ]
Eivind Eklund

Posts: 49
Nickname: eeklund2
Registered: Jan, 2006

Re: Michael Feathers on Patronizing Language Design Posted: Jul 20, 2009 3:53 PM
Reply to this message Reply
Advertisement
> Michael,
> > I don't recall saying that. I'm all for having the
> > ability to express invariants in code.
>
> I interpreted your blog as stating that a programming
> language where invariants can be expressed and are
> enforced is patronizing.
>
> You, of course, didn't use the word "invariant," but your
> focus was very much on how enforced restrictions are
> unnecessarily patronizing. I interpret most of the
> restrictions you identified (e.g. sealed and final
> classes) as means of expressing invariants.

They do help in enforcing invariants; the problem is that they are very blunt tools.

Final / sealed / frozen classes is used to ensure that nobody later makes a child class that break the invariants of the parent class. A common example is immutable classes: If somebody inherit from them, they could make the class mutable, e.g. by adding a changeable field. By making the class final, you make sure that classes that inherit can't break this invariant.

However, you also make sure that they cannot do valid inheritance. Let's as an example say that the immutable above is an immutable list that allows mutable objects to be contained. Due to allowing mutable objects to be contained, it needs to recalculate hashCode() every time hashCode() is called. Now, a class that inherit from it and only allowed *immutable* objects in the list could cache the hashCode() value, potentially getting significantly better performance. This could be enforced through the type system - but it can't be implemented because the blunt tool of a final class.

This is a drawback with final classes. The benefit is that you can assume that nobody but the original class is violating the promised invariant.

Which of these are more valuable probably varies depending on what environment you are in. My personal experience has been that these kinds of protections added by others regularly get in my way, while I haven't gotten any problems where I say "Oh, I'd love to have final" from programming in languages that lack them.


The same cost/benefit calculation goes for multiple inheritance: While I know that in theory inheritance diamonds can create problems, in 20 years of OO programming I've come across problems with this once, while when I program in Java, I come across duplication and clumsy APIs daily - clumsiness and duplication that could have been cleanly implemented with multiple inheritance.

david david

Posts: 16
Nickname: david21001
Registered: Mar, 2007

Re: Michael Feathers on Patronizing Language Design Posted: Jul 22, 2009 2:53 PM
Reply to this message Reply
> Without bondage & discipline you are not an "engineer" or
> come even close but an "artist" or worse: a "cowboy
> coder". It's almost like a class distinction.

this sounds a little kinky to me ;)

david david

Posts: 16
Nickname: david21001
Registered: Mar, 2007

Re: Michael Feathers on Patronizing Language Design Posted: Jul 22, 2009 2:57 PM
Reply to this message Reply
> It seems that languages focused on preventing you from
> doing the wrong thing (e.g. Java) receive harsh criticism,
> whereas languages focused on enabling and encouraging you
> to do the right thing (e.g. Scala) receive much praise.
> Different still are languages that encourage you to do
> o stupid things like cast a pointer to an integer or
> vice-versa (e.g. C), which are languages that frequently
> come under attack.


the developer can really do stupid things without any encouragement

Peter Booth

Posts: 62
Nickname: alohashirt
Registered: Aug, 2004

Re: Michael Feathers on Patronizing Language Design Posted: Jul 22, 2009 4:10 PM
Reply to this message Reply
SLIGHT ASIDE:

I must have at least 300 programming books scattered through my home. Michael Feather's book on working with legacy code is one of the most useful three or four books I have. It's a superbly practical, pragmatic, coherent book about the real issues that experienced developers deal with when working on mature code-bases.

For this reason, his opinions carry a lot of weight with me.

Morgan Conrad

Posts: 307
Nickname: miata71
Registered: Mar, 2006

Hello Artima - I may want to post a long reply later Posted: Jul 22, 2009 5:03 PM
Reply to this message Reply
Note to Artima moderators - I may want to write a long reply to this post, based on my recently reviewing/updating my C++ knowledge, since my last decade was working with the "patronizing" language, Java. The particular book I'm reading, Sams Teach Yourself C++ in 21 Days, is good, and full of Dos and Don'ts, like

"DON'T mark the constructor as virtual."

There's even an exercise testing this. Apparently, coders do this and bad things happen(?) Seems like this is a perfect place for a "patronizing" compiler to prevent the coder form being just plain dumb.

I'm off camping for a week or so, but how would I go about replying with a long post/blog?

art src

Posts: 33
Nickname: articulate
Registered: Sep, 2005

Re: Hello Artima - I may want to post a long reply later Posted: Jul 28, 2009 8:52 PM
Reply to this message Reply
If you mark a constructor virtual this happens:

-sh-3.00$ g++ test.cpp && a.out
test.cpp:7: error: constructors cannot be declared virtual
-sh-3.00$

Michael Feathers

Posts: 448
Nickname: mfeathers
Registered: Jul, 2003

Re: Hello Artima - I may want to post a long reply later Posted: Jul 29, 2009 8:00 AM
Reply to this message Reply
> If you mark a constructor virtual this happens:
>
> -sh-3.00$ g++ test.cpp && a.out
> test.cpp:7: error: constructors cannot be declared
> virtual
> -sh-3.00$

True. Not to derail the thread, but the reason constructors can't be virtual in languages like Java, C#, and C++ is not patronization, it's the fact that they would make no sense semantically. FWIW, I feel that constructors are really a bit of a language hack. That's why they have so many odd rules.

Darko Latkovic

Posts: 9
Nickname: darko
Registered: Jul, 2009

Re: Hello Artima - I may want to post a long reply later Posted: Jul 30, 2009 12:36 AM
Reply to this message Reply
> FWIW, I feel that constructors are really a bit of a language hack. That's why they have so many odd rules.

Michael, what would you prefer as a mechanism for the object creation? Do you think there could have been some better alternative for Java or C++?

Flat View: This topic has 37 replies on 3 pages [ « | 1  2  3 ]
Topic: Laurence Vanhelsuwé on Java Collections Pitfalls Previous Topic   Next Topic Topic: Two-Way Data Binding in Flex 4

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use