tag:blogger.com,1999:blog-37404288.post7242740203443442529..comments2023-11-02T14:40:18.756+01:00Comments on JP Moresmau's Programming Blog: A simple functional structure in JavaJP Moresmauhttp://www.blogger.com/profile/09964251063221757176noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-37404288.post-79558436323660172892007-11-10T13:40:00.000+01:002007-11-10T13:40:00.000+01:00As for equals part, I have seen some years ago see...As for equals part, I have seen some years ago seen a trick in DDJ, which may do the job.<BR/><BR/>public boolean equals( b) {<BR/> return this.blindlyEquals( b) && b.blindlyEquals( this);<BR/>}<BR/><BR/>where simpleMindedEquals is implemented as in your post (equal fields => true)<BR/><BR/>You get reflexivity and transivity for free so to say.<BR/><BR/>Hope this helps.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-37404288.post-76254094142129574252007-10-31T20:44:00.000+01:002007-10-31T20:44:00.000+01:00I take everything I said back if that's generated ...I take everything I said back if that's generated code. :]Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-37404288.post-29246630985843864012007-10-31T17:50:00.000+01:002007-10-31T17:50:00.000+01:00Sorry, you're not bitchy, it's good to have reacti...Sorry, you're not bitchy, it's good to have reactions!! What may not be clear in the post is that the code here is generated by my converter from the functional code to Java. Hence the absence of spaces, the aggressive use of final, etc... But yes since the converter generates source files (I didn't want to dive into .class format right now) I could generate prettier output. Thanks!JP Moresmauhttps://www.blogger.com/profile/09964251063221757176noreply@blogger.comtag:blogger.com,1999:blog-37404288.post-83295940075522443422007-10-31T17:03:00.000+01:002007-10-31T17:03:00.000+01:00The last sniplet:1. we know what package Object is...The last sniplet:<BR/>1. we know what package Object is in, and you defined Simple earlier so no need to type in the full class names.<BR/>2. There's nothing wrong with indenting with 1/2/3/4/10 spaces or tabs, but you have to put spaces around binary operators (==, =, +, -, etc.).<BR/>3. no need to declare "o" final. You're not referencing it from inside of an embedded anonymous class.<BR/><BR/>public boolean equals(Object o) {<BR/> if (this == o) {<BR/> return true;<BR/> }<BR/> if (o instanceof Simple) {<BR/> Simple co = (Simple) o;<BR/> if (!this.data.equals(co.data)) { <BR/> return false;<BR/> }<BR/> if (this.port != co.port) {<BR/> return false;<BR/> }<BR/> return true;<BR/> }<BR/> return false;<BR/>}<BR/><BR/>I'm sorry, I don't mean to be bitchy.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-37404288.post-1815142991096289612007-10-31T08:42:00.000+01:002007-10-31T08:42:00.000+01:00And there's not even generics yet (-: ... Seriousl...And there's not even generics yet (-: ... Seriously, apart from the fact that the code show 1 space instead of tabs and in a couple of places doesn't go to a new line to have return false, I don't see what's so horrible about it.JP Moresmauhttps://www.blogger.com/profile/09964251063221757176noreply@blogger.comtag:blogger.com,1999:blog-37404288.post-60859475018503402202007-10-30T18:41:00.000+01:002007-10-30T18:41:00.000+01:00Don't want to sound too negative and off topic, bu...Don't want to sound too negative and off topic, but the coding style (formating) is horrible. The code is totally unreadable. Just couldn't continue reading... Sorry.Anonymousnoreply@blogger.com