Return-Path: X-Original-To: apmail-incubator-clerezza-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-clerezza-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E57794E86 for ; Thu, 7 Jul 2011 22:14:41 +0000 (UTC) Received: (qmail 72239 invoked by uid 500); 7 Jul 2011 22:14:41 -0000 Delivered-To: apmail-incubator-clerezza-dev-archive@incubator.apache.org Received: (qmail 71797 invoked by uid 500); 7 Jul 2011 22:14:41 -0000 Mailing-List: contact clerezza-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: clerezza-dev@incubator.apache.org Delivered-To: mailing list clerezza-dev@incubator.apache.org Received: (qmail 71779 invoked by uid 99); 7 Jul 2011 22:14:40 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jul 2011 22:14:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jul 2011 22:14:38 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id DD3864C96B for ; Thu, 7 Jul 2011 22:14:16 +0000 (UTC) Date: Thu, 7 Jul 2011 22:14:16 +0000 (UTC) From: "Henry Story (JIRA)" To: clerezza-dev@incubator.apache.org Message-ID: <894731062.9356.1310076856902.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Created] (CLEREZZA-596) Replace LiteralBuilder with EzLiteral MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org Replace LiteralBuilder with EzLiteral ------------------------------------- Key: CLEREZZA-596 URL: https://issues.apache.org/jira/browse/CLEREZZA-596 Project: Clerezza Issue Type: Improvement Reporter: Henry Story In package org.apache.clerezza.rdf.scala.utils the following classes are defined class LiteralBuilder(val lexicalForm: String) { def lang(lang: String) = new PlainLiteralImpl(lexicalForm, new Language(lang)) def ^^(dataType: UriRef) = new TypedLiteralImpl(lexicalForm, dataType) } class LiteralBuilder(val lexicalForm: String) { def uri = new UriRef(string) } This then also comes with the following implicit transformations implicit def string2litBuilder(str: String) = new TcIndependentConversions.LiteralBuilder(str) implicit def string2uriRefBuilder(str: String) = new TcIndependentConversions.UriRefBuilder(str) implicit def string2lit(str: String) = litFactory.createTypedLiteral(str) I propose reducing the classes needed down to one and one implicit. implicit def string2lit(str: String) = new EzLiteral(str) class EzLiteral(lexicalForm: String) extends TypedLiteralImpl(lexicalForm,XSD.string) { def lang(lang: String) = new PlainLiteralImpl(lexicalForm, new Language(lang)) def ^^(typ: UriRef) = new TypedLiteralImpl(lexicalForm, typ) def uri = new UriRef(lexicalForm) } Advantages: + halving of number of classes + 3 times fewer implicits: implicits should be avoided. They are particularly useful when one needs to add methods to code one does not control. But adding them indiscriminately makes code look magical, and then could be difficult to debug. When one controls the classes one should make methods (functions) explicit. + functional: the concept of a Builder is very much a concept of OO programming for objects that have changing state. But here there is no changing state: the objects are immutable already. Functional programming works with methods that take an immutable object and return another immutable object. Here we go from a function on a string to a some other thing: other types of literals. see CLEREZZA-595 for details on how literals can be thought of as functions from strings to abstract objects. -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira