Another one of these by type rather than instanceof or if-else. Joshua Bloch seems to have the answer: "If a typesafe enum class has methods whose behavior varies significantly from one class constant to another, you should use a separate private nested class or anonymous inner class for each constant. This allows each constant to have its own implementation of each such method, and automatically invokes the correct implementation. The alternative is to structure each such method as a multi-way branch that behaves differently depending on the constant on which it's invoked. This alternative is ugly, error prone, and likely to provide performance that is inferior to that of the virtual machine's automatic method dispatching."
Object Input Classes "Note – The readResolve method is not invoked on the object until the object is fully constructed, so any references to this object in its object graph will not be updated to the new object nominated by readResolve. However, during the serialization of an object with the writeReplace method, all references to the original object in the replacement object’s object graph are replaced with references to the replacement object. Therefore in cases where an object being serialized nominates a replacement object whose object graph has a reference to the original object, deserialization will result in an incorrect graph of objects. Furthermore, if the reference types of the object being read (nominated by writeReplace) and the original object are not compatible, the construction of the object graph will raise a ClassCastException."
Exploring Enums: The Wait Is Finally Over "Spare the serialization: Enum serialization isn't like the normal one you have seen. The process by which enum constants are serialized cannot be customized. Any class-specific writeObject and writeReplace methods defined by enum types are ignored during serialization. Similarly, any serialPersistentFields or serialVersionUID field declarations are also ignored - all enum types have a fixed serialVersionUID of 0L. Again, this shouldn't concern you too much. Let the language take care of the specifics."
Thursday, July 28, 2005
Wednesday, July 27, 2005
Pre-Conditions and Post-Conditions
Rules based routing "The basic idea is you expose a DroolsComponent at some service/interface/operation endpoint in ServiceMix then let it perform rules based routing, or other actions as required.
You can deploy a DroolsComponent with a rule base which will be fired when it is invoked. The rule base is then in complete control over messge dispatching."
JBI Routing "...a component can give the container some hints by specifying the service, interface and/or operation to invoke and then let the container choose which physical service endpoint to invoke using some choosing algorithm (maybe using rules or policy driven metadata). Remember there may be many services available for a specific service, interface and operation names."
This is almost the exact same idea that I had on a previous project. The routing of a document was done based on it's metadata as well as system being configured for specific outcomes. For example, you could configure it such that all documents should be turned into HTML for example.
Via Rules based routing in JBI using Drools in ServiceMix.
You can deploy a DroolsComponent with a rule base which will be fired when it is invoked. The rule base is then in complete control over messge dispatching."
JBI Routing "...a component can give the container some hints by specifying the service, interface and/or operation to invoke and then let the container choose which physical service endpoint to invoke using some choosing algorithm (maybe using rules or policy driven metadata). Remember there may be many services available for a specific service, interface and operation names."
This is almost the exact same idea that I had on a previous project. The routing of a document was done based on it's metadata as well as system being configured for specific outcomes. For example, you could configure it such that all documents should be turned into HTML for example.
Via Rules based routing in JBI using Drools in ServiceMix.
Tuesday, July 26, 2005
Whuffie and Defeasible Inference
Whuffie "Many community-oriented websites are experimenting with Whuffie-like concepts of reputation management (Slashdot's karma system, for example, or eBay's feedback ratings). Others look further ahead, at the "next generation" of the web - known as the Semantic Web.
One of the key challenges in developing the Semantic Web is in fact Whuffie, although you won't hear it called by that name.
Built of assertations about facts, the Semantic Web is basically distributed metadata. If one party says "Water is Wet" while another claims "Water isn't Wet", problems are encountered. At this point, Whuffie plays a role: which party is trusted more by others whom I already trust?
One of the key researchers in this area is Jennifer Golbeck, who is performing research on Trust in the Semantic Web"
This seems to imply that the Semantic Web offers non-monotonic, defeasible inference. Maybe it's just not a very clear example. A good run down is Non-Monotonic Logic (Nixon and Tweety are given examples, but not Clyde).
One of the key challenges in developing the Semantic Web is in fact Whuffie, although you won't hear it called by that name.
Built of assertations about facts, the Semantic Web is basically distributed metadata. If one party says "Water is Wet" while another claims "Water isn't Wet", problems are encountered. At this point, Whuffie plays a role: which party is trusted more by others whom I already trust?
One of the key researchers in this area is Jennifer Golbeck, who is performing research on Trust in the Semantic Web"
This seems to imply that the Semantic Web offers non-monotonic, defeasible inference. Maybe it's just not a very clear example. A good run down is Non-Monotonic Logic (Nixon and Tweety are given examples, but not Clyde).
Esquilax
Dynamic Typing in C# "The effect is pseudo-dynamic typing—dynamic style programming on top of a statically typed language. The introduction of pseudo-dynamic typing in C# raises the possibility that it may become pervasive as a scripting language, stealing much thunder away from Python, Perl and Ruby."
Links to: Static Typing Where Possible, Dynamic Typing When Needed: The End of the Cold War Between Programming Languages.
Links to: Static Typing Where Possible, Dynamic Typing When Needed: The End of the Cold War Between Programming Languages.
APIs on REST
* XINS is a technology used to define, create and invoke remote APIs. XINS is specification-oriented. When API specifications are written (in XML), XINS will transform them to HTML-based documentation and Java code for both the client- and the server-side. The communication is based on HTTP.
* Axis 2.0 Support for REST "Axis2 can be configured as REST Cantainer and can be used to send and receive restful web services requests and responses. The REST Web Services can be access in two ways, using HTTP GET and POST."
* REST vs API "The starting point is usually that somebody has an API that is intended to shield the developer from the inner workings of SOAP and perhaps another protocol or three. The person is thinking about adding REST support (generally in the form of removing the requirement for a SOAP envelope and adding support for additional HTTP methods). What can go wrong?"
* Axis 2.0 Support for REST "Axis2 can be configured as REST Cantainer and can be used to send and receive restful web services requests and responses. The REST Web Services can be access in two ways, using HTTP GET and POST."
* REST vs API "The starting point is usually that somebody has an API that is intended to shield the developer from the inner workings of SOAP and perhaps another protocol or three. The person is thinking about adding REST support (generally in the form of removing the requirement for a SOAP envelope and adding support for additional HTTP methods). What can go wrong?"
Monday, July 18, 2005
Pasta Preference
Ravioli code "The opposite of spaghetti code, where too many small objects that rely on many other small objects are created."
See also spaghetti code.
See also spaghetti code.
Thursday, July 14, 2005
Intel Macs
Speed of Apple Intel dev systems impress developers "Developers are renting the $999 hardware from Apple for a period of 18 months in order to get a head start in porting their applications to run on the Intel version of Mac OS X.
"It's fast," said one developer source of Mac OS X running on Intel's Pentium processors. "Faster than [Mac OS X] on my Dual 2GHz Power Mac G5." In addition to booting Windows XP at blazing speeds, the included version of Mac OS X for Intel takes "as little as 10 seconds" to boot to the Desktop from when the Apple logo first displays on screen." Via Slashdot. Transition kit is available here.
WebObjects 5.3 Which is part of XCode, which is part of the OS.
"It's fast," said one developer source of Mac OS X running on Intel's Pentium processors. "Faster than [Mac OS X] on my Dual 2GHz Power Mac G5." In addition to booting Windows XP at blazing speeds, the included version of Mac OS X for Intel takes "as little as 10 seconds" to boot to the Desktop from when the Apple logo first displays on screen." Via Slashdot. Transition kit is available here.
WebObjects 5.3 Which is part of XCode, which is part of the OS.
Wednesday, July 13, 2005
Less Code
Started the first go of using generics in JRDF. It uses Java's collections pretty heavily so there's quite a lot of work to be done. Many good things happened, mostly it's less code - casting went away (of course) and things like add became type safe. It makes a lot more sense to add/remove an org.jrdf.graph.ObjectNode to a Bag rather than an java.lang.Object.
One thing I have yet to do (and see if it's even possible) is to see whether things like addAll, containsAll, etc can be made to use more specific variants (Alternative, Bag, etc) rather than Collection. From what I've gathered so far it may not be possible for backwards compatibility reasons. It seems like what I want (and what Java generics needs apparently) is variant types.
Tom has some comments on 0.3.4 too.
Update: In some instances (pun intended) there's more code: How do I generically create objects and arrays? and How do I perform a runtime type check whose target type is a type parameter? "For a type check at runtime we must explicitly provide runtime type information so that we can perform the type check and cast by means of reflection. The type information is best supplied by means of a Class object."
One thing I have yet to do (and see if it's even possible) is to see whether things like addAll, containsAll, etc can be made to use more specific variants (Alternative, Bag, etc) rather than Collection. From what I've gathered so far it may not be possible for backwards compatibility reasons. It seems like what I want (and what Java generics needs apparently) is variant types.
Tom has some comments on 0.3.4 too.
Update: In some instances (pun intended) there's more code: How do I generically create objects and arrays? and How do I perform a runtime type check whose target type is a type parameter? "For a type check at runtime we must explicitly provide runtime type information so that we can perform the type check and cast by means of reflection. The type information is best supplied by means of a Class object."
JRDF 0.3.4
JRDF Comes with the port of Sesame's RIO parser to JRDF, the start of a SPARQL parser and remote querying, bug fixes and other small changes. This is the last version for Java 1.4. The next version will use some of the new 5.0 features like Generics for RDF collections (seems to make sense) and the much touted concurrency libraries.
Tuesday, July 12, 2005
Oracle Releases Database with RDF Support
Oracle supports RDF Danny points to the fact that Oracle 10g now supports.
First announced about a year ago.
First announced about a year ago.
Monday, July 11, 2005
Objectifying the Web
REST versus Object-Orientation (and a little python) "From my perspective, the concepts of Object Orientation (OO) and REST are comparable. They both seek to identify "things" that correspond to something you can about and interact with as a unit. In OO we call it an object. In REST we call it a resource. Both OO and REST allow some form of abstraction. You can replace one object with another of the same class or of the same type without changing how client code interacts with the object. The type is a common abstraction that represents any suitable object equally well."
REST and Object Orientation via OWL "So the most important aspect of RESTful programming as Benjamin points out is that now all objects are universally nameable and universally accessible. A few simple verbs allow us to create, delete and change the state of these resources. Access Control Lists allow fine tuning of responsibilities for a resource. And OWL gives us the Object Oriented conceptual structure to predict and understand the content of these resources and how they relate to others."
People seem to forget that method calls in Java or whatever can be considered message passing. What could be more OO than REST? GET isn't analogous to "getFoo" or "getBar" on a JavaBean object. The semantics behind GET/POST/PUT/DELETE is better thought of as how you are changing the object (related to Create Retrieve Update Delete (CRUD)). What could be more RESTful than OO?
The Dining Philosophers in REST "...it's trivial to encapsulate transactions into a single atomic exchange, and exposing those encapsulations as first class entities is generally a pretty good idea. And it certainly fits with the REST model of the world. MUCH more so, in fact, than RPC, as it forces one to aggregate those operations in the server design rather than leaving it open to the client to abuse. In fact, I'd even say that doing so is critical to the ability to build workable distributed systems."
Also related "Using RDF to improve Object-First Development".
REST and Object Orientation via OWL "So the most important aspect of RESTful programming as Benjamin points out is that now all objects are universally nameable and universally accessible. A few simple verbs allow us to create, delete and change the state of these resources. Access Control Lists allow fine tuning of responsibilities for a resource. And OWL gives us the Object Oriented conceptual structure to predict and understand the content of these resources and how they relate to others."
People seem to forget that method calls in Java or whatever can be considered message passing. What could be more OO than REST? GET isn't analogous to "getFoo" or "getBar" on a JavaBean object. The semantics behind GET/POST/PUT/DELETE is better thought of as how you are changing the object (related to Create Retrieve Update Delete (CRUD)). What could be more RESTful than OO?
The Dining Philosophers in REST "...it's trivial to encapsulate transactions into a single atomic exchange, and exposing those encapsulations as first class entities is generally a pretty good idea. And it certainly fits with the REST model of the world. MUCH more so, in fact, than RPC, as it forces one to aggregate those operations in the server design rather than leaving it open to the client to abuse. In fact, I'd even say that doing so is critical to the ability to build workable distributed systems."
Also related "Using RDF to improve Object-First Development".
Free Expression of Ideas
* Even if you think you can beat Waldo, you can't beat Einstein "For example to ping a peer on my local wireless network the best latency (as measured by running batch of pings) is around 2ms but my average latency is 100ms over a negligible distance compared to the speed of light. In the average case on this network the binary protocol is a mere 14% faster than SOAP - certainly not tens of times faster."
* Speed of Light Fallacy "If you consider these numbers, you will see that the speed-of-light argument is a fallacy. Dealing with the speed-of-light limitation is achieved by minimizing the number of messages that are exchanged, and by maximizing the amount of data sent with each message, regardless of the transfer technology."
* Generics Considered Harmful "The complexity of Java has been turbocharged to what seems to me relatively small benefit. I don't see that the value is there to justify the cost. Not that we can change things, but I think we should at least view it as an demonstration proof of the value of an explicit complexity budget against which features must be justified. Without such a budget, it feels like the JSR process ran far ahead, without a step back to ask “Is this feature really necessary”. It seemed to just be understood that it was necessary."
* Generics Considered Harmful? Nope. "For a few library designers, who now want to create generic types (they still have the option of creating old style types), life just got more complicated. However, for all their clients, life got easier. Easier is good."
* Speed of Light Fallacy "If you consider these numbers, you will see that the speed-of-light argument is a fallacy. Dealing with the speed-of-light limitation is achieved by minimizing the number of messages that are exchanged, and by maximizing the amount of data sent with each message, regardless of the transfer technology."
* Generics Considered Harmful "The complexity of Java has been turbocharged to what seems to me relatively small benefit. I don't see that the value is there to justify the cost. Not that we can change things, but I think we should at least view it as an demonstration proof of the value of an explicit complexity budget against which features must be justified. Without such a budget, it feels like the JSR process ran far ahead, without a step back to ask “Is this feature really necessary”. It seemed to just be understood that it was necessary."
* Generics Considered Harmful? Nope. "For a few library designers, who now want to create generic types (they still have the option of creating old style types), life just got more complicated. However, for all their clients, life got easier. Easier is good."
Sunday, July 10, 2005
Visual Representation of Build Status
Automated Continuous Integration and the Ambient Orb™ Forget manually controlled Lava Lamps (as currently used at work) or plain light bulbs (note the use of 3 colours and semantics for various "on" positions).
Via Other UIs and Google searching (because it appeared so obvious).
Programmable via a serial port. More information is available on the developer page.
Via Other UIs and Google searching (because it appeared so obvious).
Programmable via a serial port. More information is available on the developer page.
Querying for Hierachies
Storing Hierarchical Data in a Database "Whether you want to build your own forum, publish the messages from a mailing list on your Website, or write your own cms: there will be a moment that you’ll want to store hierarchical data in a database. And, unless you’re using a XML-like database, tables aren’t hierarchical; they’re just a flat list. You’ll have to find a way to translate the hierarchy in a flat file."
"If you want to display the tree using a table with left and right values, you’ll first have to identify the nodes that you want to retrieve. For example, if you want the ‘Fruit’ subtree, you’ll have to select only the nodes with a left value between 2 and 11. In SQL, that would be:
SELECT * FROM tree WHERE lft BETWEEN 2 AND 11;"
It struct me how complicated either of these solutions are.
In iTQL it would be using walk:
"select $subject
...
where walk($subject <rdfs:subClassOf> <food:fruit>
and $subject <rdfs:subClassOf> $object);
Or in Sesame's SeRQL (concrete example here):
"SELECT DISTINCT _fruit
FROM _fruit serql:directSubClassOf <food:fruit>"
They aren't quite the same query - Sesame is inferring new statements and walk is not. In designing iTQL we were always deciding between magical predicates or functions (like walk) and sometimes slavishly sticking to triple patterns. Combining the walk and trans operations using a predicate, like in SeRQL, seems like a good approach to take.
Also, interesting in a fairly recent Sesame release are the ANY and ALL, EXISTS and MINUS features.
"If you want to display the tree using a table with left and right values, you’ll first have to identify the nodes that you want to retrieve. For example, if you want the ‘Fruit’ subtree, you’ll have to select only the nodes with a left value between 2 and 11. In SQL, that would be:
SELECT * FROM tree WHERE lft BETWEEN 2 AND 11;"
It struct me how complicated either of these solutions are.
In iTQL it would be using walk:
"select $subject
...
where walk($subject <rdfs:subClassOf> <food:fruit>
and $subject <rdfs:subClassOf> $object);
Or in Sesame's SeRQL (concrete example here):
"SELECT DISTINCT _fruit
FROM _fruit serql:directSubClassOf <food:fruit>"
They aren't quite the same query - Sesame is inferring new statements and walk is not. In designing iTQL we were always deciding between magical predicates or functions (like walk) and sometimes slavishly sticking to triple patterns. Combining the walk and trans operations using a predicate, like in SeRQL, seems like a good approach to take.
Also, interesting in a fairly recent Sesame release are the ANY and ALL, EXISTS and MINUS features.
Tuesday, July 05, 2005
The Singleton and Double Checked Locking
The "Double-Checked Locking is Broken" Declaration "If the singleton you are creating is static (i.e., there will only be one Helper created), as opposed to a property of another object (e.g., there will be one Helper for each Foo object, there is a simple and elegant solution.
Just define the singleton as a static field in a separate class. The semantics of Java guarantee that the field will not be initialized until the field is referenced, and that any thread which accesses the field will see all of the writes resulting from initializing that field.
class HelperSingleton {
static Helper singleton = new Helper();
}"
I've had this happen in real life many times, where people expect DCL to work. It doesn't no matter how hard you try (and I've had seen some really smart people try).
There is no way around it except for Java 1.5.
With something like Spring and PicoContainer, though, the Singleton pattern is fairly inherent - a configuration option for an object rather than something you specify in code.
Just define the singleton as a static field in a separate class. The semantics of Java guarantee that the field will not be initialized until the field is referenced, and that any thread which accesses the field will see all of the writes resulting from initializing that field.
class HelperSingleton {
static Helper singleton = new Helper();
}"
I've had this happen in real life many times, where people expect DCL to work. It doesn't no matter how hard you try (and I've had seen some really smart people try).
There is no way around it except for Java 1.5.
With something like Spring and PicoContainer, though, the Singleton pattern is fairly inherent - a configuration option for an object rather than something you specify in code.
Apple eXtending RSS
RSS inventor slams Apple's podcast approach "Extending a standard is not, in and of itself, a bad idea. The "X" in "XML" does continue to stand for "Extensible." Conceivably, Apple could have made an open proposition for an extension to media RSS that supports the iTunes catalog, stated Louis, and RSS developers could have worked with them to polish a standard prior to iTunes 4.9's release. But by redefining the meaning of at least two principal RSS tags, by Winer's count, Apple may be, in Louis' opinion, trying too hard to re-invent the wheel just so the final product can be theirs and theirs alone. The situation is reminiscent, said Louis, of the browser wars of the 1990s "where basically you could develop your own tags that could work on your own browser, but then there was no guarantee that the community would support those.""
Friday, July 01, 2005
Cringley on Web Two Point Oh
Accessories Make the Nerd "...the gray web is filled with data that we can search, perhaps, but can't understand. Imagine using an English-language search engine to search a Persian-language web site. The way out of this, to a new dawn where visible, invisible, and gray data alike are available to us, is through Web 2.0 (sometimes called or confused with the so-called "semantic web"), where we will use metadata (primarily XML) to advertise our needs and disposals to the world.
This is a huge leap for anything as established as the Web, to say that we are going to add an overlay of metadata so that you can not only share with the world a picture of your car, but also set terms under which you'd sell that car."
"There are several problems with this concept, not the least of which is the Tower of Babel effect in which every metadata tagger can use his or her own tagging system, none of which are necessarily readable by the others. Joe sees no problem in that because computers are really good at lifting and carrying, and mapping a thousand tag formats to each other isn't all that much harder than mapping a few. But I see people as being inherently lazy, and Yahoo and Google and all the other big web companies as being inherently greedy and unwilling to give up their businesses so easily."
"Here is what Web 2.0 WILL be, in my view: a new way of structuring Internet businesses around published APIs, Application Programming Interfaces. New companies will spring up that simply glue web-based APIs together...Web 2.0 will be staffed by two different kinds of entrepreneurs -- those who provide staunch web services exposed through APIs (Amazon, eBay, Google, and a bunch more), and those who glue those services together and make some sort of useful abstraction service."
This is a huge leap for anything as established as the Web, to say that we are going to add an overlay of metadata so that you can not only share with the world a picture of your car, but also set terms under which you'd sell that car."
"There are several problems with this concept, not the least of which is the Tower of Babel effect in which every metadata tagger can use his or her own tagging system, none of which are necessarily readable by the others. Joe sees no problem in that because computers are really good at lifting and carrying, and mapping a thousand tag formats to each other isn't all that much harder than mapping a few. But I see people as being inherently lazy, and Yahoo and Google and all the other big web companies as being inherently greedy and unwilling to give up their businesses so easily."
"Here is what Web 2.0 WILL be, in my view: a new way of structuring Internet businesses around published APIs, Application Programming Interfaces. New companies will spring up that simply glue web-based APIs together...Web 2.0 will be staffed by two different kinds of entrepreneurs -- those who provide staunch web services exposed through APIs (Amazon, eBay, Google, and a bunch more), and those who glue those services together and make some sort of useful abstraction service."
Subscribe to:
Posts (Atom)