This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Native Compiler for Scala

25 replies
Quenio dos Santos
Joined: 2009-11-15,
User offline. Last seen 42 years 45 weeks ago.
Hello All,
I don't know if you have heard the buzz about the new Go programming language from Google, which is been touted as the new systems language to replace C/C++.
I have been exploring it, and although I found it interesting initially, now I am not so impressed. Just for starters, it doesn't support sub-typing. I can't really see how can you live without sub-typing and inheritance in a modern programming language.
I honestly believe that Scala would be a great systems language if a native compiler was available for Scala. Has that ever crossed the mind of the Scala development team, or anybody else?
- Quenio
David Flemström
Joined: 2009-08-10,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala

I, too, have been wondering this. It would be almost trivial to build a
compiler for LLVM.

The biggest obstacles I can think of would be those of:
1. Implementing runtime reflection (or even just runtime type info for pattern
matching).
2. Getting a native type system to behave like the Scala type system does
(e.g. having AnyVal and AnyRef, Nothing and Null behave the same way they do
in the nsc).
3. Porting over all of the libraries that depend (more or less) on Java code.
The decision to use java.lang.String in Scala instead of an own String
implementation might prove fatal.

Some advantages a native implementation would give over the JVM:
1. Faster code (not necessarily, but it has a better chance of being faster)
2. Less memory consumption
3. Possibility of storing small classes with nothing but "val"s on the stack
4. A more rigorous base for the language (No need for Foo$obj$plus.class
names, no need to create Java forwarders and no need for working around
various JVM array issues etc)

Problems:
1. How can Java dependencies be replaced? Is it possible to use VMKit to
actually make it possible to use Java dependencies in native code?
2. How would you interact with other native libraries (from the C/C++ world)?

On Sunday 15 November 2009 08:37:19 Quenio dos Santos wrote:
> Hello All,
>
> I don't know if you have heard the buzz about the new Go programming
> language from Google, which is been touted as the new systems language to
> replace C/C++.
>
> I have been exploring it, and although I found it interesting initially,
> now I am not so impressed. Just for starters, it doesn't support
> sub-typing. I can't really see how can you live without sub-typing and
> inheritance in a modern programming language.
>
> I honestly believe that Scala would be a great systems language if a native
> compiler was available for Scala. Has that ever crossed the mind of the
> Scala development team, or anybody else?
>
> - Quenio
>

Goddard Jiri
Joined: 2009-10-16,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala
Hi,

interesting thoughts. I've heard about Go, but I don't give it too much chance. Google is becoming certainly ¨The Evil¨ :)
Back on the track - what about profiles instead of native compiler? Like the ones you can find in shading languages.
I think it would be a good start - the profile doesn't need to support everything from start. Let's say it would speed up just certain
portions of code or use native libs that actually are really faster, not the ones that might be faster.

Jiri

On Sun, Nov 15, 2009 at 8:56 AM, David Flemström <david [dot] flemstrom [at] gmail [dot] com> wrote:
I, too, have been wondering this. It would be almost trivial to build a
compiler for LLVM.

The biggest obstacles I can think of would be those of:
1. Implementing runtime reflection (or even just runtime type info for pattern
matching).
2. Getting a native type system to behave like the Scala type system does
(e.g. having AnyVal and AnyRef, Nothing and Null behave the same way they do
in the nsc).
3. Porting over all of the libraries that depend (more or less) on Java code.
The decision to use java.lang.String in Scala instead of an own String
implementation might prove fatal.

Some advantages a native implementation would give over the JVM:
1. Faster code (not necessarily, but it has a better chance of being faster)
2. Less memory consumption
3. Possibility of storing small classes with nothing but "val"s on the stack
4. A more rigorous base for the language (No need for Foo$obj$plus.class
names, no need to create Java forwarders and no need for working around
various JVM array issues etc)

Problems:
1. How can Java dependencies be replaced? Is it possible to use VMKit to
actually make it possible to use Java dependencies in native code?
2. How would you interact with other native libraries (from the C/C++ world)?

On Sunday 15 November 2009 08:37:19 Quenio dos Santos wrote:
> Hello All,
>
> I don't know if you have heard the buzz about the new Go programming
> language from Google, which is been touted as the new systems language to
> replace C/C++.
>
> I have been exploring it, and although I found it interesting initially,
>  now I am not so impressed. Just for starters, it doesn't support
>  sub-typing. I can't really see how can you live without sub-typing and
>  inheritance in a modern programming language.
>
> I honestly believe that Scala would be a great systems language if a native
> compiler was available for Scala. Has that ever crossed the mind of the
> Scala development team, or anybody else?
>
> - Quenio
>



--
web: http://dredwerkz.ic.cz
group: http://groups.google.com/group/dr3dwerkz
icq: 218 659 431
David Flemström
Joined: 2009-08-10,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala

On Sunday 15 November 2009 09:09:33 Goddard Jiri wrote:
> Hi,
>
> interesting thoughts. I've heard about Go, but I don't give it too much
> chance. Google is becoming certainly ¨The Evil¨ :)
> Back on the track - what about profiles instead of native compiler? Like
> the ones you can find in shading languages.
> I think it would be a good start - the profile doesn't need to support
> everything from start. Let's say it would speed up just certain
> portions of code or use native libs that actually are really faster, not
> the ones that might be faster.
How would you go about combining JVM code with native code? How would the
native code replacement work? If you include ".so"'s or ".dll"'s and use JNI
in JARs, they will become platform dependent, and that would be a headache to
manage.

I think that this would be more difficult to implement than to just make a
completely native compiler.
>
> Jiri
>
> On Sun, Nov 15, 2009 at 8:56 AM, David Flemström
>
> wrote:
> > I, too, have been wondering this. It would be almost trivial to build a
> > compiler for LLVM.
> >
> > The biggest obstacles I can think of would be those of:
> > 1. Implementing runtime reflection (or even just runtime type info for
> > pattern
> > matching).
> > 2. Getting a native type system to behave like the Scala type system does
> > (e.g. having AnyVal and AnyRef, Nothing and Null behave the same way they
> > do
> > in the nsc).
> > 3. Porting over all of the libraries that depend (more or less) on Java
> > code.
> > The decision to use java.lang.String in Scala instead of an own String
> > implementation might prove fatal.
> >
> > Some advantages a native implementation would give over the JVM:
> > 1. Faster code (not necessarily, but it has a better chance of being
> > faster)
> > 2. Less memory consumption
> > 3. Possibility of storing small classes with nothing but "val"s on the
> > stack
> > 4. A more rigorous base for the language (No need for Foo$obj$plus.class
> > names, no need to create Java forwarders and no need for working around
> > various JVM array issues etc)
> >
> > Problems:
> > 1. How can Java dependencies be replaced? Is it possible to use VMKit to
> > actually make it possible to use Java dependencies in native code?
> > 2. How would you interact with other native libraries (from the C/C++
> > world)?
> >
> > On Sunday 15 November 2009 08:37:19 Quenio dos Santos wrote:
> > > Hello All,
> > >
> > > I don't know if you have heard the buzz about the new Go programming
> > > language from Google, which is been touted as the new systems language
> > > to replace C/C++.
> > >
> > > I have been exploring it, and although I found it interesting
> > > initially, now I am not so impressed. Just for starters, it doesn't
> > > support sub-typing. I can't really see how can you live without
> > > sub-typing and inheritance in a modern programming language.
> > >
> > > I honestly believe that Scala would be a great systems language if a
> >
> > native
> >
> > > compiler was available for Scala. Has that ever crossed the mind of the
> > > Scala development team, or anybody else?
> > >
> > > - Quenio
>

Goddard Jiri
Joined: 2009-10-16,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala
I forgot to say that I'm no expert on compilers.
Anyway, having native compiler is about being platform dependent if I got it right.
I just know that the profiles idea is working with another languages.
Even Java supports kind of profiles in JSL (Java Shading Language) that is used with Java 3D.

Jiri

On Sun, Nov 15, 2009 at 9:18 AM, David Flemström <david [dot] flemstrom [at] gmail [dot] com> wrote:
On Sunday 15 November 2009 09:09:33 Goddard Jiri wrote:
> Hi,
>
> interesting thoughts. I've heard about Go, but I don't give it too much
> chance. Google is becoming certainly ¨The Evil¨ :)
> Back on the track - what about profiles instead of native compiler? Like
>  the ones you can find in shading languages.
> I think it would be a good start - the profile doesn't need to support
> everything from start. Let's say it would speed up just certain
> portions of code or use native libs that actually are really faster, not
>  the ones that might be faster.
How would you go about combining JVM code with native code? How would the
native code replacement work? If you include ".so"'s or ".dll"'s and use JNI
in JARs, they will become platform dependent, and that would be a headache to
manage.

I think that this would be more difficult to implement than to just make a
completely native compiler.
>
> Jiri
>
> On Sun, Nov 15, 2009 at 8:56 AM, David Flemström
>
> <david [dot] flemstrom [at] gmail [dot] com>wrote:
> > I, too, have been wondering this. It would be almost trivial to build a
> > compiler for LLVM.
> >
> > The biggest obstacles I can think of would be those of:
> > 1. Implementing runtime reflection (or even just runtime type info for
> > pattern
> > matching).
> > 2. Getting a native type system to behave like the Scala type system does
> > (e.g. having AnyVal and AnyRef, Nothing and Null behave the same way they
> > do
> > in the nsc).
> > 3. Porting over all of the libraries that depend (more or less) on Java
> > code.
> > The decision to use java.lang.String in Scala instead of an own String
> > implementation might prove fatal.
> >
> > Some advantages a native implementation would give over the JVM:
> > 1. Faster code (not necessarily, but it has a better chance of being
> > faster)
> > 2. Less memory consumption
> > 3. Possibility of storing small classes with nothing but "val"s on the
> > stack
> > 4. A more rigorous base for the language (No need for Foo$obj$plus.class
> > names, no need to create Java forwarders and no need for working around
> > various JVM array issues etc)
> >
> > Problems:
> > 1. How can Java dependencies be replaced? Is it possible to use VMKit to
> > actually make it possible to use Java dependencies in native code?
> > 2. How would you interact with other native libraries (from the C/C++
> > world)?
> >
> > On Sunday 15 November 2009 08:37:19 Quenio dos Santos wrote:
> > > Hello All,
> > >
> > > I don't know if you have heard the buzz about the new Go programming
> > > language from Google, which is been touted as the new systems language
> > > to replace C/C++.
> > >
> > > I have been exploring it, and although I found it interesting
> > > initially, now I am not so impressed. Just for starters, it doesn't
> > > support sub-typing. I can't really see how can you live without
> > > sub-typing and inheritance in a modern programming language.
> > >
> > > I honestly believe that Scala would be a great systems language if a
> >
> > native
> >
> > > compiler was available for Scala. Has that ever crossed the mind of the
> > > Scala development team, or anybody else?
> > >
> > > - Quenio
>



--
web: http://dredwerkz.ic.cz
group: http://groups.google.com/group/dr3dwerkz
icq: 218 659 431
Tony Morris 2
Joined: 2009-03-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala

Haskell does away with inheritance just fine. Indeed, it reaps the
benefits of having abandoned such a blatant type system flaw.
http://okmij.org/ftp/Computation/Subtyping/

Quenio dos Santos wrote:
> Hello All,
>
> I don't know if you have heard the buzz about the new Go programming
> language from Google, which is been touted as the new systems language
> to replace C/C++.
>
> I have been exploring it, and although I found it interesting
> initially, now I am not so impressed. Just for starters, it doesn't
> support sub-typing. I can't really see how can you live without
> sub-typing and inheritance in a modern programming language.
>
> I honestly believe that Scala would be a great systems language if a
> native compiler was available for Scala. Has that ever crossed the
> mind of the Scala development team, or anybody else?
>
> - Quenio

Quenio dos Santos
Joined: 2009-11-15,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala
Go has neither inheritance nor sub-typing. It has interfaces, which do provide sub-typing on some level, but are limited in my opinion. One interface cannot sub-type another interface, for example.
As far as inheritance being a flaw, I don't think Martin Ordersky would agree with you. Otherwise, he wouldn't have put the feature in Scala :)
Scala not only adopted inheritance but enhanced it with traits.

On Sun, Nov 15, 2009 at 2:27 AM, Tony Morris <tonymorris [at] gmail [dot] com> wrote:
Haskell does away with inheritance just fine. Indeed, it reaps the
benefits of having abandoned such a blatant type system flaw.
http://okmij.org/ftp/Computation/Subtyping/

Quenio dos Santos wrote:
> Hello All,
>
> I don't know if you have heard the buzz about the new Go programming
> language from Google, which is been touted as the new systems language
> to replace C/C++.
>
> I have been exploring it, and although I found it interesting
> initially, now I am not so impressed. Just for starters, it doesn't
> support sub-typing. I can't really see how can you live without
> sub-typing and inheritance in a modern programming language.
>
> I honestly believe that Scala would be a great systems language if a
> native compiler was available for Scala. Has that ever crossed the
> mind of the Scala development team, or anybody else?
>
> - Quenio

--
Tony Morris
http://tmorris.net/



ijuma
Joined: 2008-08-20,
User offline. Last seen 22 weeks 2 days ago.
Re: Native Compiler for Scala

David Flemström gmail.com> writes:
> Some advantages a native implementation would give over the JVM:
> 1. Faster code (not necessarily, but it has a better chance of being faster)

I think you'll find it quite hard to make it faster for long-lived applications
while still meeting the specification of the language. A good example of this is
gcj (although that is for Java). Having said that, gcj does quite well for
applications where start-up time is more important than warmed-up performance.

Given enough time (but this could be a lot of time), everything is possible,
particularly if this native implementation deals with some of the current
weaknesses of the JVM. One has to consider that the JVM is a moving target
though, and it's very possible that those weaknesses will be fixed in future
releases.

Best,
Ismael

Quenio dos Santos
Joined: 2009-11-15,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala
What I said about Go not allowing one interface to sub-type another is technically true, but you can work around that using a new interesting feature called embedding. See more at:http://golang.org/doc/effective_go.html#embedding

On Sun, Nov 15, 2009 at 2:47 AM, Quenio dos Santos <queniodossantos [at] gmail [dot] com> wrote:
Go has neither inheritance nor sub-typing. It has interfaces, which do provide sub-typing on some level, but are limited in my opinion. One interface cannot sub-type another interface, for example.
As far as inheritance being a flaw, I don't think Martin Ordersky would agree with you. Otherwise, he wouldn't have put the feature in Scala :)
Scala not only adopted inheritance but enhanced it with traits.

On Sun, Nov 15, 2009 at 2:27 AM, Tony Morris <tonymorris [at] gmail [dot] com> wrote:
Haskell does away with inheritance just fine. Indeed, it reaps the
benefits of having abandoned such a blatant type system flaw.
http://okmij.org/ftp/Computation/Subtyping/

Quenio dos Santos wrote:
> Hello All,
>
> I don't know if you have heard the buzz about the new Go programming
> language from Google, which is been touted as the new systems language
> to replace C/C++.
>
> I have been exploring it, and although I found it interesting
> initially, now I am not so impressed. Just for starters, it doesn't
> support sub-typing. I can't really see how can you live without
> sub-typing and inheritance in a modern programming language.
>
> I honestly believe that Scala would be a great systems language if a
> native compiler was available for Scala. Has that ever crossed the
> mind of the Scala development team, or anybody else?
>
> - Quenio

--
Tony Morris
http://tmorris.net/




Tony Morris 2
Joined: 2009-03-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala

I didn't mean to imply that absence of inheritance was a good idea for
Go. I listed my opinion on Go a few days ago in private to other
inquiring minds.

I intended only that inheritance is certainly not essential for a
"modern" programming language (which I assumed to be synonymous with
"practical") and is indeed, rather antithetical. One may or may not
agree, but it's quite easy to solidly argue the fact. Scala users
ultimately suffer as a result (see the mailing lists for many examples
with new ones regularly arriving). Thankfully Oleg has done all the
arguing for me so I best not be too loud lest I be coaxed into another
debate!

Quenio dos Santos wrote:
> Go has neither inheritance nor sub-typing. It has interfaces, which do
> provide sub-typing on some level, but are limited in my opinion. One
> interface cannot sub-type another interface, for example.
>
> As far as inheritance being a flaw, I don't think Martin Ordersky
> would agree with you. Otherwise, he wouldn't have put the feature in
> Scala :)
>
> Scala not only adopted inheritance but enhanced it with traits.
>
> On Sun, Nov 15, 2009 at 2:27 AM, Tony Morris > wrote:
>
> Haskell does away with inheritance just fine. Indeed, it reaps the
> benefits of having abandoned such a blatant type system flaw.
> http://okmij.org/ftp/Computation/Subtyping/
>
> Quenio dos Santos wrote:
> > Hello All,
> >
> > I don't know if you have heard the buzz about the new Go programming
> > language from Google, which is been touted as the new systems
> language
> > to replace C/C++.
> >
> > I have been exploring it, and although I found it interesting
> > initially, now I am not so impressed. Just for starters, it doesn't
> > support sub-typing. I can't really see how can you live without
> > sub-typing and inheritance in a modern programming language.
> >
> > I honestly believe that Scala would be a great systems language if a
> > native compiler was available for Scala. Has that ever crossed the
> > mind of the Scala development team, or anybody else?
> >
> > - Quenio
>
> --
> Tony Morris
> http://tmorris.net/
>
>
>

Quenio dos Santos
Joined: 2009-11-15,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala
I may be completely be missing your point here, but I cannot imagine Scala without traits. Maybe, without single inheritance, but not traits. 

On Sun, Nov 15, 2009 at 2:52 AM, Tony Morris <tonymorris [at] gmail [dot] com> wrote:
I didn't mean to imply that absence of inheritance was a good idea for
Go. I listed my opinion on Go a few days ago in private to other
inquiring minds.

I intended only that inheritance is certainly not essential for a
"modern" programming language (which I assumed to be synonymous with
"practical") and is indeed, rather antithetical. One may or may not
agree, but it's quite easy to solidly argue the fact. Scala users
ultimately suffer as a result (see the mailing lists for many examples
with new ones regularly arriving). Thankfully Oleg has done all the
arguing for me so I best not be too loud lest I be coaxed into another
debate!

Quenio dos Santos wrote:
> Go has neither inheritance nor sub-typing. It has interfaces, which do
> provide sub-typing on some level, but are limited in my opinion. One
> interface cannot sub-type another interface, for example.
>
> As far as inheritance being a flaw, I don't think Martin Ordersky
> would agree with you. Otherwise, he wouldn't have put the feature in
> Scala :)
>
> Scala not only adopted inheritance but enhanced it with traits.
>
> On Sun, Nov 15, 2009 at 2:27 AM, Tony Morris <tonymorris [at] gmail [dot] com
> <mailto:tonymorris [at] gmail [dot] com>> wrote:
>
>     Haskell does away with inheritance just fine. Indeed, it reaps the
>     benefits of having abandoned such a blatant type system flaw.
>     http://okmij.org/ftp/Computation/Subtyping/
>
>     Quenio dos Santos wrote:
>     > Hello All,
>     >
>     > I don't know if you have heard the buzz about the new Go programming
>     > language from Google, which is been touted as the new systems
>     language
>     > to replace C/C++.
>     >
>     > I have been exploring it, and although I found it interesting
>     > initially, now I am not so impressed. Just for starters, it doesn't
>     > support sub-typing. I can't really see how can you live without
>     > sub-typing and inheritance in a modern programming language.
>     >
>     > I honestly believe that Scala would be a great systems language if a
>     > native compiler was available for Scala. Has that ever crossed the
>     > mind of the Scala development team, or anybody else?
>     >
>     > - Quenio
>
>     --
>     Tony Morris
>     http://tmorris.net/
>
>
>

--
Tony Morris
http://tmorris.net/



Tony Morris 2
Joined: 2009-03-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala

Scala without traits would be unthinkable! Inheritance is an expensive
implicit.

Quenio dos Santos wrote:
> I may be completely be missing your point here, but I cannot imagine
> Scala without traits. Maybe, without single inheritance, but not traits.
>
> On Sun, Nov 15, 2009 at 2:52 AM, Tony Morris > wrote:
>
> I didn't mean to imply that absence of inheritance was a good idea for
> Go. I listed my opinion on Go a few days ago in private to other
> inquiring minds.
>
> I intended only that inheritance is certainly not essential for a
> "modern" programming language (which I assumed to be synonymous with
> "practical") and is indeed, rather antithetical. One may or may not
> agree, but it's quite easy to solidly argue the fact. Scala users
> ultimately suffer as a result (see the mailing lists for many examples
> with new ones regularly arriving). Thankfully Oleg has done all the
> arguing for me so I best not be too loud lest I be coaxed into another
> debate!
>
> Quenio dos Santos wrote:
> > Go has neither inheritance nor sub-typing. It has interfaces,
> which do
> > provide sub-typing on some level, but are limited in my opinion. One
> > interface cannot sub-type another interface, for example.
> >
> > As far as inheritance being a flaw, I don't think Martin Ordersky
> > would agree with you. Otherwise, he wouldn't have put the feature in
> > Scala :)
> >
> > Scala not only adopted inheritance but enhanced it with traits.
> >
> > On Sun, Nov 15, 2009 at 2:27 AM, Tony Morris
>
> > >> wrote:
> >
> > Haskell does away with inheritance just fine. Indeed, it
> reaps the
> > benefits of having abandoned such a blatant type system flaw.
> > http://okmij.org/ftp/Computation/Subtyping/
> >
> > Quenio dos Santos wrote:
> > > Hello All,
> > >
> > > I don't know if you have heard the buzz about the new Go
> programming
> > > language from Google, which is been touted as the new systems
> > language
> > > to replace C/C++.
> > >
> > > I have been exploring it, and although I found it interesting
> > > initially, now I am not so impressed. Just for starters,
> it doesn't
> > > support sub-typing. I can't really see how can you live
> without
> > > sub-typing and inheritance in a modern programming language.
> > >
> > > I honestly believe that Scala would be a great systems
> language if a
> > > native compiler was available for Scala. Has that ever
> crossed the
> > > mind of the Scala development team, or anybody else?
> > >
> > > - Quenio
> >
> > --
> > Tony Morris
> > http://tmorris.net/
> >
> >
> >
>
> --
> Tony Morris
> http://tmorris.net/
>
>
>

Elazar Leibovich
Joined: 2009-10-07,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala
Please note that Scala is designed more for abstractness than to speed.For example, implicit conversions should give clearer code, but impose performance penalty.

On Sun, Nov 15, 2009 at 9:37 AM, Quenio dos Santos <queniodossantos [at] gmail [dot] com> wrote:
Hello All,
I don't know if you have heard the buzz about the new Go programming language from Google, which is been touted as the new systems language to replace C/C++.
I have been exploring it, and although I found it interesting initially, now I am not so impressed. Just for starters, it doesn't support sub-typing. I can't really see how can you live without sub-typing and inheritance in a modern programming language.
I honestly believe that Scala would be a great systems language if a native compiler was available for Scala. Has that ever crossed the mind of the Scala development team, or anybody else?
- Quenio

ijuma
Joined: 2008-08-20,
User offline. Last seen 22 weeks 2 days ago.
Re: Native Compiler for Scala

Elazar Leibovich gmail.com> writes:
> Please note that Scala is designed more for abstractness than to speed.For
> example, implicit conversions should give clearer code, but impose performance
> penalty.

Not necessarily. Many implicit conversions are short-lived and it's possible for
the JIT to elide the allocation by using escape analysis.

One could say that Scala requires a sophisticated JIT for best performance when
taking advantage of some of its abstraction features.

Best,
Ismael

Quenio dos Santos
Joined: 2009-11-15,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala
This article you referenced is very interesting. It basically shows that you can break the contract of a super-class by changing the behavior in the sub-class. 
I don't think this common, easily-resolvable issue should be a suggestion that inheritance is evil. Even with interfaces, you can always provide an implementation that breaks the contract of the interface.
Also, in the article, the author suggests that test suite was carefully implemented by the authors of both the Bag and the Set. However, one important characteristic was not checked by the test suite: add(x);add(x);count(x) ==2. Exactly the one that failed in the foo() method of the example.
It is interesting to me that one of the few languages that actually has built-in support for checking contracts (Eiffel) was designed by Bertrand Meyer, which stated clearly in his book "Object-Oriented Software Construction" that it is just fine to use inheritance as a way to re-use code even if the super-class and the sub-class have no sub-type relationship in the real world.
Eiffel is a serious language implementation that has been around for years and is well-respected in the academic community. It has multiple inheritance, which works very similarly to traits, and it doesn't suffer from the diamond problem.

On Sun, Nov 15, 2009 at 2:27 AM, Tony Morris <tonymorris [at] gmail [dot] com> wrote:
Haskell does away with inheritance just fine. Indeed, it reaps the
benefits of having abandoned such a blatant type system flaw.
http://okmij.org/ftp/Computation/Subtyping/

Quenio dos Santos wrote:
> Hello All,
>
> I don't know if you have heard the buzz about the new Go programming
> language from Google, which is been touted as the new systems language
> to replace C/C++.
>
> I have been exploring it, and although I found it interesting
> initially, now I am not so impressed. Just for starters, it doesn't
> support sub-typing. I can't really see how can you live without
> sub-typing and inheritance in a modern programming language.
>
> I honestly believe that Scala would be a great systems language if a
> native compiler was available for Scala. Has that ever crossed the
> mind of the Scala development team, or anybody else?
>
> - Quenio

--
Tony Morris
http://tmorris.net/



Tony Morris 2
Joined: 2009-03-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala

It is a common myth that inheritance is related to code reuse, except
perhaps that it prevents reuse to some extent under certain conditions.

Inheritance is simply an implicit function (plus problems). The
difference being cognitive; the arrow is pointing upward instead of
rightward.

Quenio dos Santos wrote:
> This article you referenced is very interesting. It basically shows
> that you can break the contract of a super-class by changing the
> behavior in the sub-class.
>
> I don't think this common, easily-resolvable issue should be a
> suggestion that inheritance is evil. Even with interfaces, you can
> always provide an implementation that breaks the contract of the
> interface.
>
> Also, in the article, the author suggests that test suite was
> carefully implemented by the authors of both the Bag and the Set.
> However, one important characteristic was not checked by the test
> suite: add(x);add(x);count(x) ==2. Exactly the one that failed in the
> foo() method of the example.
>
> It is interesting to me that one of the few languages that actually
> has built-in support for checking contracts (Eiffel) was designed by
> Bertrand Meyer, which stated clearly in his book "Object-Oriented
> Software Construction
> "
> that it is just fine to use inheritance as a way to re-use code even
> if the super-class and the sub-class have no sub-type relationship in
> the real world.
>
> Eiffel is a serious language implementation that has been around for
> years and is well-respected in the academic community. It has multiple
> inheritance, which works very similarly to traits, and it doesn't
> suffer from the diamond problem.
>
> On Sun, Nov 15, 2009 at 2:27 AM, Tony Morris > wrote:
>
> Haskell does away with inheritance just fine. Indeed, it reaps the
> benefits of having abandoned such a blatant type system flaw.
> http://okmij.org/ftp/Computation/Subtyping/
>
> Quenio dos Santos wrote:
> > Hello All,
> >
> > I don't know if you have heard the buzz about the new Go programming
> > language from Google, which is been touted as the new systems
> language
> > to replace C/C++.
> >
> > I have been exploring it, and although I found it interesting
> > initially, now I am not so impressed. Just for starters, it doesn't
> > support sub-typing. I can't really see how can you live without
> > sub-typing and inheritance in a modern programming language.
> >
> > I honestly believe that Scala would be a great systems language if a
> > native compiler was available for Scala. Has that ever crossed the
> > mind of the Scala development team, or anybody else?
> >
> > - Quenio
>
> --
> Tony Morris
> http://tmorris.net/
>
>
>

Quenio dos Santos
Joined: 2009-11-15,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala
On Sun, Nov 15, 2009 at 4:17 PM, Tony Morris <tonymorris [at] gmail [dot] com> wrote:
It is a common myth that inheritance is related to code reuse, except
perhaps that it prevents reuse to some extent under certain conditions.

One can use inheritance to reuse code. It is a fact. Programmers do that everyday. 

Inheritance is simply an implicit function (plus problems). The
difference being cognitive; the arrow is pointing upward instead of
rightward.

Like any other tool, one can use inheritance to hurt itself if one doesn't know how to use it properly. That doesn't mean you should remove it from your toolbox, one just needs to read the "manual" before one goes about using it :)
Tony Morris 2
Joined: 2009-03-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala

That's great news! Now where can I find an example of this fact?

Quenio dos Santos wrote:
> On Sun, Nov 15, 2009 at 4:17 PM, Tony Morris > wrote:
>
> It is a common myth that inheritance is related to code reuse, except
> perhaps that it prevents reuse to some extent under certain
> conditions.
>
>
> One can use inheritance to reuse code. It is a fact. Programmers do
> that everyday.
>
>
>
> Inheritance is simply an implicit function (plus problems). The
> difference being cognitive; the arrow is pointing upward instead of
> rightward.
>
>
> Like any other tool, one can use inheritance to hurt itself if one
> doesn't know how to use it properly. That doesn't mean you should
> remove it from your toolbox, one just needs to read the "manual"
> before one goes about using it :)
>

Quenio dos Santos
Joined: 2009-11-15,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala
Traits are just a clever way of doing multiple inheritance, which allows mixing without some of the issues you would find in C++. It is not much different from multiple inheritance in Eiffel, which also resolves some of the C++ issues. 
I think when you say inheritance, you really mean traditional single inheritance like in Java.

On Sun, Nov 15, 2009 at 3:17 AM, Tony Morris <tonymorris [at] gmail [dot] com> wrote:
Scala without traits would be unthinkable! Inheritance is an expensive
implicit.

Quenio dos Santos wrote:
> I may be completely be missing your point here, but I cannot imagine
> Scala without traits. Maybe, without single inheritance, but not traits.
>
> On Sun, Nov 15, 2009 at 2:52 AM, Tony Morris <tonymorris [at] gmail [dot] com
> <mailto:tonymorris [at] gmail [dot] com>> wrote:
>
>     I didn't mean to imply that absence of inheritance was a good idea for
>     Go. I listed my opinion on Go a few days ago in private to other
>     inquiring minds.
>
>     I intended only that inheritance is certainly not essential for a
>     "modern" programming language (which I assumed to be synonymous with
>     "practical") and is indeed, rather antithetical. One may or may not
>     agree, but it's quite easy to solidly argue the fact. Scala users
>     ultimately suffer as a result (see the mailing lists for many examples
>     with new ones regularly arriving). Thankfully Oleg has done all the
>     arguing for me so I best not be too loud lest I be coaxed into another
>     debate!
>
>     Quenio dos Santos wrote:
>     > Go has neither inheritance nor sub-typing. It has interfaces,
>     which do
>     > provide sub-typing on some level, but are limited in my opinion. One
>     > interface cannot sub-type another interface, for example.
>     >
>     > As far as inheritance being a flaw, I don't think Martin Ordersky
>     > would agree with you. Otherwise, he wouldn't have put the feature in
>     > Scala :)
>     >
>     > Scala not only adopted inheritance but enhanced it with traits.
>     >
>     > On Sun, Nov 15, 2009 at 2:27 AM, Tony Morris
>     <tonymorris [at] gmail [dot] com <mailto:tonymorris [at] gmail [dot] com>
>     > <mailto:tonymorris [at] gmail [dot] com <mailto:tonymorris [at] gmail [dot] com>>> wrote:
>     >
>     >     Haskell does away with inheritance just fine. Indeed, it
>     reaps the
>     >     benefits of having abandoned such a blatant type system flaw.
>     >     http://okmij.org/ftp/Computation/Subtyping/
>     >
>     >     Quenio dos Santos wrote:
>     >     > Hello All,
>     >     >
>     >     > I don't know if you have heard the buzz about the new Go
>     programming
>     >     > language from Google, which is been touted as the new systems
>     >     language
>     >     > to replace C/C++.
>     >     >
>     >     > I have been exploring it, and although I found it interesting
>     >     > initially, now I am not so impressed. Just for starters,
>     it doesn't
>     >     > support sub-typing. I can't really see how can you live
>     without
>     >     > sub-typing and inheritance in a modern programming language.
>     >     >
>     >     > I honestly believe that Scala would be a great systems
>     language if a
>     >     > native compiler was available for Scala. Has that ever
>     crossed the
>     >     > mind of the Scala development team, or anybody else?
>     >     >
>     >     > - Quenio
>     >
>     >     --
>     >     Tony Morris
>     >     http://tmorris.net/
>     >
>     >
>     >
>
>     --
>     Tony Morris
>     http://tmorris.net/
>
>
>

--
Tony Morris
http://tmorris.net/



Tony Morris 2
Joined: 2009-03-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala

No certainly not. I mean inheritance, just like you do. So, where's the
code reuse again?

Quenio dos Santos wrote:
> Traits are just a clever way of doing multiple inheritance, which
> allows mixing without some of the issues you would find in C++. It is
> not much different from multiple inheritance in Eiffel, which also
> resolves some of the C++ issues.
>
> I think when you say inheritance, you really mean traditional single
> inheritance like in Java.
>
> On Sun, Nov 15, 2009 at 3:17 AM, Tony Morris > wrote:
>
> Scala without traits would be unthinkable! Inheritance is an expensive
> implicit.
>
> Quenio dos Santos wrote:
> > I may be completely be missing your point here, but I cannot imagine
> > Scala without traits. Maybe, without single inheritance, but not
> traits.
> >
> > On Sun, Nov 15, 2009 at 2:52 AM, Tony Morris
>
> > >> wrote:
> >
> > I didn't mean to imply that absence of inheritance was a
> good idea for
> > Go. I listed my opinion on Go a few days ago in private to other
> > inquiring minds.
> >
> > I intended only that inheritance is certainly not essential
> for a
> > "modern" programming language (which I assumed to be
> synonymous with
> > "practical") and is indeed, rather antithetical. One may or
> may not
> > agree, but it's quite easy to solidly argue the fact. Scala
> users
> > ultimately suffer as a result (see the mailing lists for
> many examples
> > with new ones regularly arriving). Thankfully Oleg has done
> all the
> > arguing for me so I best not be too loud lest I be coaxed
> into another
> > debate!
> >
> > Quenio dos Santos wrote:
> > > Go has neither inheritance nor sub-typing. It has interfaces,
> > which do
> > > provide sub-typing on some level, but are limited in my
> opinion. One
> > > interface cannot sub-type another interface, for example.
> > >
> > > As far as inheritance being a flaw, I don't think Martin
> Ordersky
> > > would agree with you. Otherwise, he wouldn't have put the
> feature in
> > > Scala :)
> > >
> > > Scala not only adopted inheritance but enhanced it with
> traits.
> > >
> > > On Sun, Nov 15, 2009 at 2:27 AM, Tony Morris
> >
> >
> > >
> >>> wrote:
> > >
> > > Haskell does away with inheritance just fine. Indeed, it
> > reaps the
> > > benefits of having abandoned such a blatant type
> system flaw.
> > > http://okmij.org/ftp/Computation/Subtyping/
> > >
> > > Quenio dos Santos wrote:
> > > > Hello All,
> > > >
> > > > I don't know if you have heard the buzz about the new Go
> > programming
> > > > language from Google, which is been touted as the
> new systems
> > > language
> > > > to replace C/C++.
> > > >
> > > > I have been exploring it, and although I found it
> interesting
> > > > initially, now I am not so impressed. Just for starters,
> > it doesn't
> > > > support sub-typing. I can't really see how can you live
> > without
> > > > sub-typing and inheritance in a modern programming
> language.
> > > >
> > > > I honestly believe that Scala would be a great systems
> > language if a
> > > > native compiler was available for Scala. Has that ever
> > crossed the
> > > > mind of the Scala development team, or anybody else?
> > > >
> > > > - Quenio
> > >
> > > --
> > > Tony Morris
> > > http://tmorris.net/
> > >
> > >
> > >
> >
> > --
> > Tony Morris
> > http://tmorris.net/
> >
> >
> >
>
> --
> Tony Morris
> http://tmorris.net/
>
>
>

Quenio dos Santos
Joined: 2009-11-15,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala
Are you kidding me? Have you ever used Swing?

On Sun, Nov 15, 2009 at 8:41 PM, Tony Morris <tonymorris [at] gmail [dot] com> wrote:
No certainly not. I mean inheritance, just like you do. So, where's the
code reuse again?

Quenio dos Santos wrote:
> Traits are just a clever way of doing multiple inheritance, which
> allows mixing without some of the issues you would find in C++. It is
> not much different from multiple inheritance in Eiffel, which also
> resolves some of the C++ issues.
>
> I think when you say inheritance, you really mean traditional single
> inheritance like in Java.
>
> On Sun, Nov 15, 2009 at 3:17 AM, Tony Morris <tonymorris [at] gmail [dot] com
> <mailto:tonymorris [at] gmail [dot] com>> wrote:
>
>     Scala without traits would be unthinkable! Inheritance is an expensive
>     implicit.
>
>     Quenio dos Santos wrote:
>     > I may be completely be missing your point here, but I cannot imagine
>     > Scala without traits. Maybe, without single inheritance, but not
>     traits.
>     >
>     > On Sun, Nov 15, 2009 at 2:52 AM, Tony Morris
>     <tonymorris [at] gmail [dot] com <mailto:tonymorris [at] gmail [dot] com>
>     > <mailto:tonymorris [at] gmail [dot] com <mailto:tonymorris [at] gmail [dot] com>>> wrote:
>     >
>     >     I didn't mean to imply that absence of inheritance was a
>     good idea for
>     >     Go. I listed my opinion on Go a few days ago in private to other
>     >     inquiring minds.
>     >
>     >     I intended only that inheritance is certainly not essential
>     for a
>     >     "modern" programming language (which I assumed to be
>     synonymous with
>     >     "practical") and is indeed, rather antithetical. One may or
>     may not
>     >     agree, but it's quite easy to solidly argue the fact. Scala
>     users
>     >     ultimately suffer as a result (see the mailing lists for
>     many examples
>     >     with new ones regularly arriving). Thankfully Oleg has done
>     all the
>     >     arguing for me so I best not be too loud lest I be coaxed
>     into another
>     >     debate!
>     >
>     >     Quenio dos Santos wrote:
>     >     > Go has neither inheritance nor sub-typing. It has interfaces,
>     >     which do
>     >     > provide sub-typing on some level, but are limited in my
>     opinion. One
>     >     > interface cannot sub-type another interface, for example.
>     >     >
>     >     > As far as inheritance being a flaw, I don't think Martin
>     Ordersky
>     >     > would agree with you. Otherwise, he wouldn't have put the
>     feature in
>     >     > Scala :)
>     >     >
>     >     > Scala not only adopted inheritance but enhanced it with
>     traits.
>     >     >
>     >     > On Sun, Nov 15, 2009 at 2:27 AM, Tony Morris
>     >     <tonymorris [at] gmail [dot] com <mailto:tonymorris [at] gmail [dot] com>
>     <mailto:tonymorris [at] gmail [dot] com <mailto:tonymorris [at] gmail [dot] com>>
>     >     > <mailto:tonymorris [at] gmail [dot] com <mailto:tonymorris [at] gmail [dot] com>
>     <mailto:tonymorris [at] gmail [dot] com <mailto:tonymorris [at] gmail [dot] com>>>> wrote:
>     >     >
>     >     >     Haskell does away with inheritance just fine. Indeed, it
>     >     reaps the
>     >     >     benefits of having abandoned such a blatant type
>     system flaw.
>     >     >     http://okmij.org/ftp/Computation/Subtyping/
>     >     >
>     >     >     Quenio dos Santos wrote:
>     >     >     > Hello All,
>     >     >     >
>     >     >     > I don't know if you have heard the buzz about the new Go
>     >     programming
>     >     >     > language from Google, which is been touted as the
>     new systems
>     >     >     language
>     >     >     > to replace C/C++.
>     >     >     >
>     >     >     > I have been exploring it, and although I found it
>     interesting
>     >     >     > initially, now I am not so impressed. Just for starters,
>     >     it doesn't
>     >     >     > support sub-typing. I can't really see how can you live
>     >     without
>     >     >     > sub-typing and inheritance in a modern programming
>     language.
>     >     >     >
>     >     >     > I honestly believe that Scala would be a great systems
>     >     language if a
>     >     >     > native compiler was available for Scala. Has that ever
>     >     crossed the
>     >     >     > mind of the Scala development team, or anybody else?
>     >     >     >
>     >     >     > - Quenio
>     >     >
>     >     >     --
>     >     >     Tony Morris
>     >     >     http://tmorris.net/
>     >     >
>     >     >
>     >     >
>     >
>     >     --
>     >     Tony Morris
>     >     http://tmorris.net/
>     >
>     >
>     >
>
>     --
>     Tony Morris
>     http://tmorris.net/
>
>
>

--
Tony Morris
http://tmorris.net/



Tony Morris 2
Joined: 2009-03-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala

No. Yes.

Quenio dos Santos wrote:
> Are you kidding me? Have you ever used Swing?
>
> On Sun, Nov 15, 2009 at 8:41 PM, Tony Morris > wrote:
>
> No certainly not. I mean inheritance, just like you do. So,
> where's the
> code reuse again?
>
> Quenio dos Santos wrote:
> > Traits are just a clever way of doing multiple inheritance, which
> > allows mixing without some of the issues you would find in C++.
> It is
> > not much different from multiple inheritance in Eiffel, which also
> > resolves some of the C++ issues.
> >
> > I think when you say inheritance, you really mean traditional single
> > inheritance like in Java.
> >
> > On Sun, Nov 15, 2009 at 3:17 AM, Tony Morris
>
> > >> wrote:
> >
> > Scala without traits would be unthinkable! Inheritance is an
> expensive
> > implicit.
> >
> > Quenio dos Santos wrote:
> > > I may be completely be missing your point here, but I
> cannot imagine
> > > Scala without traits. Maybe, without single inheritance,
> but not
> > traits.
> > >
> > > On Sun, Nov 15, 2009 at 2:52 AM, Tony Morris
> >
> >
> > >
> >>> wrote:
> > >
> > > I didn't mean to imply that absence of inheritance was a
> > good idea for
> > > Go. I listed my opinion on Go a few days ago in
> private to other
> > > inquiring minds.
> > >
> > > I intended only that inheritance is certainly not
> essential
> > for a
> > > "modern" programming language (which I assumed to be
> > synonymous with
> > > "practical") and is indeed, rather antithetical. One
> may or
> > may not
> > > agree, but it's quite easy to solidly argue the fact.
> Scala
> > users
> > > ultimately suffer as a result (see the mailing lists for
> > many examples
> > > with new ones regularly arriving). Thankfully Oleg has
> done
> > all the
> > > arguing for me so I best not be too loud lest I be coaxed
> > into another
> > > debate!
> > >
> > > Quenio dos Santos wrote:
> > > > Go has neither inheritance nor sub-typing. It has
> interfaces,
> > > which do
> > > > provide sub-typing on some level, but are limited in my
> > opinion. One
> > > > interface cannot sub-type another interface, for
> example.
> > > >
> > > > As far as inheritance being a flaw, I don't think Martin
> > Ordersky
> > > > would agree with you. Otherwise, he wouldn't have
> put the
> > feature in
> > > > Scala :)
> > > >
> > > > Scala not only adopted inheritance but enhanced it with
> > traits.
> > > >
> > > > On Sun, Nov 15, 2009 at 2:27 AM, Tony Morris
> > >
> >
> >
> >>
> > > > >
> >
> >>>> wrote:
> > > >
> > > > Haskell does away with inheritance just fine.
> Indeed, it
> > > reaps the
> > > > benefits of having abandoned such a blatant type
> > system flaw.
> > > > http://okmij.org/ftp/Computation/Subtyping/
> > > >
> > > > Quenio dos Santos wrote:
> > > > > Hello All,
> > > > >
> > > > > I don't know if you have heard the buzz about
> the new Go
> > > programming
> > > > > language from Google, which is been touted as the
> > new systems
> > > > language
> > > > > to replace C/C++.
> > > > >
> > > > > I have been exploring it, and although I found it
> > interesting
> > > > > initially, now I am not so impressed. Just for
> starters,
> > > it doesn't
> > > > > support sub-typing. I can't really see how can
> you live
> > > without
> > > > > sub-typing and inheritance in a modern programming
> > language.
> > > > >
> > > > > I honestly believe that Scala would be a great
> systems
> > > language if a
> > > > > native compiler was available for Scala. Has
> that ever
> > > crossed the
> > > > > mind of the Scala development team, or anybody
> else?
> > > > >
> > > > > - Quenio
> > > >
> > > > --
> > > > Tony Morris
> > > > http://tmorris.net/
> > > >
> > > >
> > > >
> > >
> > > --
> > > Tony Morris
> > > http://tmorris.net/
> > >
> > >
> > >
> >
> > --
> > Tony Morris
> > http://tmorris.net/
> >
> >
> >
>
> --
> Tony Morris
> http://tmorris.net/
>
>
>

Ken Bloom
Joined: 2009-09-22,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala

On Sun, 15 Nov 2009 08:56:22 +0100, David Flemström wrote:

> I, too, have been wondering this. It would be almost trivial to build a
> compiler for LLVM.
>
> The biggest obstacles I can think of would be those of: 1. Implementing
> runtime reflection (or even just runtime type info for pattern
> matching).

O'Caml and Haskell both do this already, so I can't imagine that it would
be too much of an obstacle.

> 2. Getting a native type system to behave like the Scala type system
> does (e.g. having AnyVal and AnyRef, Nothing and Null behave the same
> way they do in the nsc).

Haskell's got a pretty complicated type system implemented for
compilation to native code.

> 3. Porting over all of the libraries that depend (more or less) on Java
> code. The decision to use java.lang.String in Scala instead of an own
> String implementation might prove fatal.

Look to the .NET version of Scala to see how much library conformance is
appropriate here, and how much can be dispensed with. But another issue
here would be that .NET provides its own very rich set of object-oriented
libraries that provide a lot of functionality to Scala.NET. When you
write for the machine, neither of these libraries are available to
provide missing functionality from the scala library (if you are indeed
writing at that level of abstraction, rather than constructing a library
at that level of abstraction in Scala itself, as you would in C++).

> Some advantages a native implementation would give over the JVM: 1.
> Faster code (not necessarily, but it has a better chance of being
> faster) 2. Less memory consumption
> 3. Possibility of storing small classes with nothing but "val"s on the
> stack 4. A more rigorous base for the language (No need for
> Foo$obj$plus.class names, no need to create Java forwarders and no need
> for working around various JVM array issues etc)
>
> Problems:
> 1. How can Java dependencies be replaced? Is it possible to use VMKit to
> actually make it possible to use Java dependencies in native code? 2.
> How would you interact with other native libraries (from the C/C++
> world)?
>
> On Sunday 15 November 2009 08:37:19 Quenio dos Santos wrote:
>> Hello All,
>>
>> I don't know if you have heard the buzz about the new Go programming
>> language from Google, which is been touted as the new systems language
>> to replace C/C++.
>>
>> I have been exploring it, and although I found it interesting
>> initially,
>> now I am not so impressed. Just for starters, it doesn't support
>> sub-typing. I can't really see how can you live without sub-typing and
>> inheritance in a modern programming language.
>>
>> I honestly believe that Scala would be a great systems language if a
>> native compiler was available for Scala. Has that ever crossed the mind
>> of the Scala development team, or anybody else?
>>
>> - Quenio
>>

Naftoli Gugenheim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala
I agree. I just read Oleg's article. How exactly can one construe his point as an inherent problem with inheritance?? So a Set is not a kind of Bag, fine. Does that mean that cats are not animals?Just as Tony and others extol the virtues of functions and discount functions that don't adhere to the design principles of functional programming--e.g., avoiding state--so too, one can reap the advantages of OOP design, as long as he stays away from misusing it.

On Sun, Nov 15, 2009 at 5:13 PM, Quenio dos Santos <queniodossantos [at] gmail [dot] com> wrote:
This article you referenced is very interesting. It basically shows that you can break the contract of a super-class by changing the behavior in the sub-class. 
I don't think this common, easily-resolvable issue should be a suggestion that inheritance is evil. Even with interfaces, you can always provide an implementation that breaks the contract of the interface.
Also, in the article, the author suggests that test suite was carefully implemented by the authors of both the Bag and the Set. However, one important characteristic was not checked by the test suite: add(x);add(x);count(x) ==2. Exactly the one that failed in the foo() method of the example.
It is interesting to me that one of the few languages that actually has built-in support for checking contracts (Eiffel) was designed by Bertrand Meyer, which stated clearly in his book "Object-Oriented Software Construction" that it is just fine to use inheritance as a way to re-use code even if the super-class and the sub-class have no sub-type relationship in the real world.
Eiffel is a serious language implementation that has been around for years and is well-respected in the academic community. It has multiple inheritance, which works very similarly to traits, and it doesn't suffer from the diamond problem.

On Sun, Nov 15, 2009 at 2:27 AM, Tony Morris <tonymorris [at] gmail [dot] com> wrote:
Haskell does away with inheritance just fine. Indeed, it reaps the
benefits of having abandoned such a blatant type system flaw.
http://okmij.org/ftp/Computation/Subtyping/

Quenio dos Santos wrote:
> Hello All,
>
> I don't know if you have heard the buzz about the new Go programming
> language from Google, which is been touted as the new systems language
> to replace C/C++.
>
> I have been exploring it, and although I found it interesting
> initially, now I am not so impressed. Just for starters, it doesn't
> support sub-typing. I can't really see how can you live without
> sub-typing and inheritance in a modern programming language.
>
> I honestly believe that Scala would be a great systems language if a
> native compiler was available for Scala. Has that ever crossed the
> mind of the Scala development team, or anybody else?
>
> - Quenio

--
Tony Morris
http://tmorris.net/




Tony Morris 2
Joined: 2009-03-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala

False dichotomy.

Naftoli Gugenheim wrote:
> I agree. I just read Oleg's article. How exactly can one construe his
> point as an inherent problem with inheritance?? So a Set is not a kind
> of Bag, fine. Does that mean that cats are not animals?
> Just as Tony and others extol the virtues of functions and discount
> functions that don't adhere to the design principles of functional
> programming--e.g., avoiding state--so too, one can reap the advantages
> of OOP design, as long as he stays away from misusing it.
>
> On Sun, Nov 15, 2009 at 5:13 PM, Quenio dos Santos
> > wrote:
>
> This article you referenced is very interesting. It basically
> shows that you can break the contract of a super-class by changing
> the behavior in the sub-class.
>
> I don't think this common, easily-resolvable issue should be a
> suggestion that inheritance is evil. Even with interfaces, you can
> always provide an implementation that breaks the contract of the
> interface.
>
> Also, in the article, the author suggests that test suite was
> carefully implemented by the authors of both the Bag and the Set.
> However, one important characteristic was not checked by the test
> suite: add(x);add(x);count(x) ==2. Exactly the one that failed in
> the foo() method of the example.
>
> It is interesting to me that one of the few languages that
> actually has built-in support for checking contracts (Eiffel) was
> designed by Bertrand Meyer, which stated clearly in his book
> "Object-Oriented Software Construction
> "
> that it is just fine to use inheritance as a way to re-use code
> even if the super-class and the sub-class have no sub-type
> relationship in the real world.
>
> Eiffel is a serious language implementation that has been around
> for years and is well-respected in the academic community. It has
> multiple inheritance, which works very similarly to traits, and it
> doesn't suffer from the diamond problem.
>
>
> On Sun, Nov 15, 2009 at 2:27 AM, Tony Morris > wrote:
>
> Haskell does away with inheritance just fine. Indeed, it reaps the
> benefits of having abandoned such a blatant type system flaw.
> http://okmij.org/ftp/Computation/Subtyping/
>
> Quenio dos Santos wrote:
> > Hello All,
> >
> > I don't know if you have heard the buzz about the new Go
> programming
> > language from Google, which is been touted as the new
> systems language
> > to replace C/C++.
> >
> > I have been exploring it, and although I found it interesting
> > initially, now I am not so impressed. Just for starters, it
> doesn't
> > support sub-typing. I can't really see how can you live without
> > sub-typing and inheritance in a modern programming language.
> >
> > I honestly believe that Scala would be a great systems
> language if a
> > native compiler was available for Scala. Has that ever
> crossed the
> > mind of the Scala development team, or anybody else?
> >
> > - Quenio
>
> --
> Tony Morris
> http://tmorris.net/
>
>
>
>

John Nilsson
Joined: 2008-12-20,
User offline. Last seen 42 years 45 weeks ago.
Re: Native Compiler for Scala
Kind of an old thread, but I just read it.
I just read http://okmij.org/ftp/Computation/Subtyping/Preventing-Trouble.html where subtyping is indeed used but avoiding the troubles by essentially doing away with dynamic dispatch.
So some questions regarding that.
a. Is this really what is going on here? LSP is guranteed by avoiding dynamic dispatch?b. Is there some deeper truth to be found whereby we can safely keep dynamic dispatch but still be "certain" that LSP is followed if some more general principle is respected? c. If the answer is to do away with dynamic dispatch, then, what is it used for now, how are similar problems solved statically?
BR,John
On Sun, Nov 15, 2009 at 9:27 AM, Tony Morris <tonymorris [at] gmail [dot] com> wrote:
Haskell does away with inheritance just fine. Indeed, it reaps the
benefits of having abandoned such a blatant type system flaw.
http://okmij.org/ftp/Computation/Subtyping/

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland