tag:blogger.com,1999:blog-178174920347765771.post7140048831795003215..comments2023-10-30T09:20:21.742-07:00Comments on One Div Zero: "Fixing" Groovy?James Iryhttp://www.blogger.com/profile/02835376424060382389noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-178174920347765771.post-48176675074262992322010-01-13T08:12:56.301-08:002010-01-13T08:12:56.301-08:00Marek,
Try again.
$ cat test.cpp
class Foo {};
c...Marek,<br /><br />Try again.<br /><br />$ cat test.cpp<br />class Foo {};<br />class Bar {};<br />class Baz : public Foo, public Bar {};<br /><br />Foo* test(Bar* x) { return x; }<br /><br />int main(int argc, char** argv) {<br /> Baz* baz = new Baz();<br /> test(baz);<br /> delete(baz);<br /><br /> return 0;<br />}<br /><br />$ g++ test.cpp<br />test.cpp: In function ‘Foo* test(Bar*)’:<James Iryhttps://www.blogger.com/profile/02835376424060382389noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-8358232574740785742010-01-13T00:26:03.509-08:002010-01-13T00:26:03.509-08:00well, mabe Scala needs fixing? In old C++ days you...well, mabe Scala needs fixing? In old C++ days you'd call this a case of cross-casting: if an object is both Foo and Bar but will be passed as Foo, compiler will automatically cross-cast it to Bar if needed (or I think so, it's a long time...). WHich I think is a correct semantic for a statically typed OO language.Marek Krjhttps://www.blogger.com/profile/16877868679118775297noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-19467456327304721532009-07-23T17:13:57.820-07:002009-07-23T17:13:57.820-07:00@Baldur,
It's a bug according to Scala's ...@Baldur,<br /><br />It's a bug according to Scala's semantics which rejects something that is not a bug according to Groovy's semantics. That was pretty much the whole point of the article.James Iryhttps://www.blogger.com/profile/02835376424060382389noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-52011336426978999382009-07-22T09:58:29.441-07:002009-07-22T09:58:29.441-07:00I fail to see the point since the Scala example is...I fail to see the point since the Scala example is simply a bug. It should be:<br /><br />scala> def test(x: Bar with Foo) : Foo = x <br />test: (Bar with Foo)Foo<br /><br />scala> test(new Baz)<br />res0: Foo = Baz@37504d<br /><br />There can be no surprise that you need to specify the correct method signatures in a static typed language.Baldur Norddahlhttps://www.blogger.com/profile/17055672964445665129noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-22179352498387408802009-07-18T13:31:43.088-07:002009-07-18T13:31:43.088-07:00Wouldn't it be possible to have a configuratio...Wouldn't it be possible to have a configuration to force groovyc to act more or less aggressive, checking for 'wrongful' usage of annotated types?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-48605599094106748872009-07-16T09:44:14.978-07:002009-07-16T09:44:14.978-07:00I'm far from being a Groovy expert, but what I...I'm far from being a Groovy expert, but what I have seen in practice makes me believe it would be possible to "have our cake and eat it, too."<br /><br />Using the JetBrains IntelliJ IDEA IDE with the JetGroovy plugin, I do get warnings in the code if I try to assign an object reference to a reference of an incompatible type. At this point, the code still compiles, but the tooling Jack Froschhttps://www.blogger.com/profile/16624563551512196020noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-91123854670788224872009-07-16T09:43:44.630-07:002009-07-16T09:43:44.630-07:00Robert, it's not the static typing that preven...Robert, it's not the static typing that prevents you implementing Builders it's the static behaviour.<br /><br />If you implemented methodMissing in a statically typed language you could do Builders.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-18753257738111163402009-07-16T09:39:26.667-07:002009-07-16T09:39:26.667-07:00I certainly don't think Groovy is broken in th...I certainly don't think Groovy is broken in this respect and, as you so clearly point out, "fixing" it would break perfectly good programs.<br /><br />Type information is of very limited use in a dynamic language. Knowing the type of an object tells us next to nothing about the semantics of that object. It is, of course, very useful in Groovy to reduce the impedance mismatch with Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-90620757370015878102009-07-16T09:31:03.456-07:002009-07-16T09:31:03.456-07:00While builders aren't possible in Scala, I'...While builders aren't possible in Scala, I'm not sure I buy that they aren't possible in a statically typed language in general.<br /><br />And saying that internal DSLs aren't possible in Scala is just plain wrong.Robert Fischerhttps://www.blogger.com/profile/15576124960718643532noreply@blogger.comtag:blogger.com,1999:blog-178174920347765771.post-25425479983300658872009-07-16T08:34:53.121-07:002009-07-16T08:34:53.121-07:00More advanced use cases of metaprogramming are not...More advanced use cases of metaprogramming are not possible with a statically typed language: so things like all the Domain-Specific Languages or the Groovy builders now out there wouldn't be possible anymore if Groovy simply switched to being a statically typed language.Guillaume Laforgehttps://www.blogger.com/profile/03993980328127368671noreply@blogger.com