JaroslavTulach: /* Drawbacks */ - 2016-06-20 07:13:36

Drawbacks

←Older revision Revision as of 07:13, 20 June 2016
Line 99: Line 99:
Result of build() method cannot be assigned to src. Expecting {{truffle|com/oracle/truffle/api/source|Source}} got {{JDK|java/lang|Void}}
Result of build() method cannot be assigned to src. Expecting {{truffle|com/oracle/truffle/api/source|Source}} got {{JDK|java/lang|Void}}
This is a perfect indication that something is wrong. However the fix (e.g. one has to call '''mimetype''' method first) isn't completely obvious from the error message. [[Good]] [[Javadoc]] on the [[builder]] [[factory]] method or the '''build()''' method itself can fix that - however this is not as [[clueless]] solution is we might want.
This is a perfect indication that something is wrong. However the fix (e.g. one has to call '''mimetype''' method first) isn't completely obvious from the error message. [[Good]] [[Javadoc]] on the [[builder]] [[factory]] method or the '''build()''' method itself can fix that - however this is not as [[clueless]] solution is we might want.
 +
 +
Check [[ResistingBuilder]] to see a possible way to improve the [[ChameleonBuilder]] pattern.

JaroslavTulach: /* Drawbacks */ - 2016-06-20 07:12:09

Drawbacks

←Older revision Revision as of 07:12, 20 June 2016
Line 87: Line 87:
-
Sometimes it makes sense to mix the [[BuilderUnfinished]] pattern with [[BuilderWithConditionalException]]. Then you end up with a [[builder]] with two generic types. That doesn't support [[cluelessness]] either - in general [[clueless]] programmers are scared by generics. On the other hand, in the typical usage, the generics aren't visible:
+
Sometimes it makes sense to mix the [[ChameleonBuilder]] pattern with [[BuilderWithConditionalException]]. Then you end up with a [[builder]] with two generic types. That doesn't support [[cluelessness]] either - in general [[clueless]] programmers are scared by generics. On the other hand, in the typical usage, the generics aren't visible:
<source lang="java">
<source lang="java">

JaroslavTulach: BuilderUnfinished moved to ChameleonBuilder: Chameleon is more sexy than unfinished encounter - 2016-06-16 09:36:24

BuilderUnfinished moved to ChameleonBuilder: Chameleon is more sexy than unfinished encounter

←Older revision Revision as of 09:36, 16 June 2016

JaroslavTulach: /* Drawbacks */ - 2016-06-16 09:25:00

Drawbacks

←Older revision Revision as of 09:25, 16 June 2016
Line 98: Line 98:
The other problem is error reporting. The classical error is:
The other problem is error reporting. The classical error is:
Result of build() method cannot be assigned to src. Expecting {{truffle|com/oracle/truffle/api/source|Source}} got {{JDK|java/lang|Void}}
Result of build() method cannot be assigned to src. Expecting {{truffle|com/oracle/truffle/api/source|Source}} got {{JDK|java/lang|Void}}
-
This is a perfect indication that something is wrong. However the fix (e.g. one has to call '''mimetype''' method) first isn't completely obvious from the error message. [[Good]] [[Javadoc]] on the [[builder]] [[factory]] method or the '''build()''' method itself can fix that - however this is not as [[clueless]] solution is we might want.
+
This is a perfect indication that something is wrong. However the fix (e.g. one has to call '''mimetype''' method first) isn't completely obvious from the error message. [[Good]] [[Javadoc]] on the [[builder]] [[factory]] method or the '''build()''' method itself can fix that - however this is not as [[clueless]] solution is we might want.

JaroslavTulach: /* Drawbacks */ - 2016-06-16 09:24:26

Drawbacks

←Older revision Revision as of 09:24, 16 June 2016
Line 97: Line 97:
The other problem is error reporting. The classical error is:
The other problem is error reporting. The classical error is:
-
Result of build() method cannot be assigned to src. Expecting ({{truffle|com/oracle/truffle/api/source|Source}} got {{JDK|java/lang|Void}}
+
Result of build() method cannot be assigned to src. Expecting {{truffle|com/oracle/truffle/api/source|Source}} got {{JDK|java/lang|Void}}
This is a perfect indication that something is wrong. However the fix (e.g. one has to call '''mimetype''' method) first isn't completely obvious from the error message. [[Good]] [[Javadoc]] on the [[builder]] [[factory]] method or the '''build()''' method itself can fix that - however this is not as [[clueless]] solution is we might want.
This is a perfect indication that something is wrong. However the fix (e.g. one has to call '''mimetype''' method) first isn't completely obvious from the error message. [[Good]] [[Javadoc]] on the [[builder]] [[factory]] method or the '''build()''' method itself can fix that - however this is not as [[clueless]] solution is we might want.

JaroslavTulach: /* Drawbacks */ - 2016-06-16 09:23:28

Drawbacks

←Older revision Revision as of 09:23, 16 June 2016
Line 84: Line 84:
=== Drawbacks ===
=== Drawbacks ===
-
There can be only a single return type in [[Java]]. As such this [[APIDesignPatterns|API pattern]] only works for a single ''essential'' [[builder]] property. One starts in the {{JDK|java/lang|Void}}-state and once it is set one changes the return type to the real one ({{truffle|com/oracle/truffle/api/source|Source}} in the previous case). This trick cannot be repeated more than once.
+
There can be only a single return type in [[Java]]. As such this [[APIDesignPatterns|API pattern]] only works for a single ''essential'' [[builder]] property. One starts in the {{JDK|java/lang|Void}}-state and once any important attribute is set one changes the return type to the real one ({{truffle|com/oracle/truffle/api/source|Source}} in the previous case). This trick cannot be repeated more than once.

JaroslavTulach: /* Drawbacks */ - 2016-06-16 09:22:16

Drawbacks

←Older revision Revision as of 09:22, 16 June 2016
Line 89: Line 89:
Sometimes it makes sense to mix the [[BuilderUnfinished]] pattern with [[BuilderWithConditionalException]]. Then you end up with a [[builder]] with two generic types. That doesn't support [[cluelessness]] either - in general [[clueless]] programmers are scared by generics. On the other hand, in the typical usage, the generics aren't visible:
Sometimes it makes sense to mix the [[BuilderUnfinished]] pattern with [[BuilderWithConditionalException]]. Then you end up with a [[builder]] with two generic types. That doesn't support [[cluelessness]] either - in general [[clueless]] programmers are scared by generics. On the other hand, in the typical usage, the generics aren't visible:
-
<source lang="lang">
+
<source lang="java">
Source src = Builder.newFromText("function hello() { print 'Hello'; }").
Source src = Builder.newFromText("function hello() { print 'Hello'; }").
name("hello.js").
name("hello.js").

JaroslavTulach: /* Initially Initialized */ - 2016-06-16 09:21:13

Initially Initialized

←Older revision Revision as of 09:21, 16 June 2016
Line 73: Line 73:
<source lang="java">
<source lang="java">
 +
// define as
public static Builder<Source> fromFile({{JDK|java/io|File}} file) { /* ... */ }
public static Builder<Source> fromFile({{JDK|java/io|File}} file) { /* ... */ }

JaroslavTulach: /* Initially Initialized */ - 2016-06-16 09:20:47

Initially Initialized

←Older revision Revision as of 09:20, 16 June 2016
Line 73: Line 73:
<source lang="java">
<source lang="java">
-
public static Builder<Source> fromFile({{JDK|java/io|File}} file) { /* ... */ }
+
public static Builder<Source> fromFile({{JDK|java/io|File}} file) { /* ... */ }
-
// use it as
+
// use it as
-
Source src = Builder.fromFile(new File("c:\\x.js")).build();
+
Source src = Builder.fromFile(new File("c:\\x.js")).build();
</source>
</source>

JaroslavTulach at 09:20, 16 June 2016 - 2016-06-16 09:20:16

←Older revision Revision as of 09:20, 16 June 2016
Line 67: Line 67:
The type information is really compile time only information - e.g. it gets [[erasure|erased]] during execution. Thus the performance of this [[APIDesignPatterns|API Design Pattern]] is the same of plain builder - but rather on relying on runtime [[exception]]s saying something is missing - it co-operates with [[Javac]] to give the users early edit time/compile time error indications.
The type information is really compile time only information - e.g. it gets [[erasure|erased]] during execution. Thus the performance of this [[APIDesignPatterns|API Design Pattern]] is the same of plain builder - but rather on relying on runtime [[exception]]s saying something is missing - it co-operates with [[Javac]] to give the users early edit time/compile time error indications.
 +
 +
=== Initially Initialized ===
 +
 +
Of course, there can be other factory methods that can create the [[builder]] in a state that is already initialized. For example, if we create a {{truffle|com/oracle/truffle/api/source|Source}} from a real file on disk, we can ask the [[OS]] to guess the MIME type for us:
 +
 +
<source lang="java">
 +
public static Builder<Source> fromFile({{JDK|java/io|File}} file) { /* ... */ }
 +
 +
// use it as
 +
Source src = Builder.fromFile(new File("c:\\x.js")).build();
 +
</source>
 +
 +
There can be a mixture of such ''finished'' or ''unfinished'' [[builder]] factory methods in the same class.
=== Drawbacks ===
=== Drawbacks ===
There can be only a single return type in [[Java]]. As such this [[APIDesignPatterns|API pattern]] only works for a single ''essential'' [[builder]] property. One starts in the {{JDK|java/lang|Void}}-state and once it is set one changes the return type to the real one ({{truffle|com/oracle/truffle/api/source|Source}} in the previous case). This trick cannot be repeated more than once.
There can be only a single return type in [[Java]]. As such this [[APIDesignPatterns|API pattern]] only works for a single ''essential'' [[builder]] property. One starts in the {{JDK|java/lang|Void}}-state and once it is set one changes the return type to the real one ({{truffle|com/oracle/truffle/api/source|Source}} in the previous case). This trick cannot be repeated more than once.
 +
 +
 +
Sometimes it makes sense to mix the [[BuilderUnfinished]] pattern with [[BuilderWithConditionalException]]. Then you end up with a [[builder]] with two generic types. That doesn't support [[cluelessness]] either - in general [[clueless]] programmers are scared by generics. On the other hand, in the typical usage, the generics aren't visible:
 +
 +
<source lang="lang">
 +
Source src = Builder.newFromText("function hello() { print 'Hello'; }").
 +
name("hello.js").
 +
mimeType("text/javascript").
 +
build();
 +
</source>
The other problem is error reporting. The classical error is:
The other problem is error reporting. The classical error is:
Result of build() method cannot be assigned to src. Expecting ({{truffle|com/oracle/truffle/api/source|Source}} got {{JDK|java/lang|Void}}
Result of build() method cannot be assigned to src. Expecting ({{truffle|com/oracle/truffle/api/source|Source}} got {{JDK|java/lang|Void}}
This is a perfect indication that something is wrong. However the fix (e.g. one has to call '''mimetype''' method) first isn't completely obvious from the error message. [[Good]] [[Javadoc]] on the [[builder]] [[factory]] method or the '''build()''' method itself can fix that - however this is not as [[clueless]] solution is we might want.
This is a perfect indication that something is wrong. However the fix (e.g. one has to call '''mimetype''' method) first isn't completely obvious from the error message. [[Good]] [[Javadoc]] on the [[builder]] [[factory]] method or the '''build()''' method itself can fix that - however this is not as [[clueless]] solution is we might want.
-
 
-