3 ms·
While reading that pile of code I couldn't help parsing it as Java, although syntactically it could be a wide variety of languages. Are there any other languag
by miguelpais 16y ago
While reading that pile of code I couldn't help parsing it as Java, although syntactically it could be a wide variety of languages.
Are there any other languages' libraries with complicated designs like that one or is this a problem specific to Java?
Just to give an example, this is a snippet of code I had to write dozens of times in a college project using the javax.xml.soap library to create a simple soap message with a tag on it:
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage soapMessage = mf.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPBody soapBody = soapEnvelope.getBody();
Name name = soapEnvelope.createName("HelloWorld", "hw", "");
SOAPElement element = soapBody.addChildElement(name);
element.addTextNode( "hello text message" );
It's not exactly the same issue has in the example on the blog post, but I think it also represents something that could be a lot simpler/shorter.
- eru 16y agoWould this work? SOAPEnvelope soapEnvelope = MessageFactory.newInstance().createMessage().getSOAPPart().getEnvelope(); SOAPBody soapBody = soapEnvelope.getBody(); Name name = soapEnvelope.createName("HelloWorld", "hw", ""); soapBody.addChildElement(name);.addTextNode( "hello text message" );
- miguelpais 16y agoDid the library design get any less bloated that way? I don't think the last line would work...
- eru 16y agoYes and yes.
- silvestrov 16y agoIt is specific to the "enterprisy" java libraries. You can easily use java without this kind of garbage, just keep away from JavaBeans, SOAP, xml config files, etc and code directly to a simple java server sitting behind a reverse proxy such as Nginx, Lighttpd, etc.
- shughes 16y agoIf you always repeat the same steps, why can't you abstract them into a single method that takes name and text as arguments. You shouldn't ever have to repeat the same set of steps in multiple locations.
- miguelpais 16y agoWell, of course, and I ended up doing that. But that's not the point, is it? The guy in the blog post could also abstract all those lines in some method and it wouldn't make that OO design with factories and contexts any less bloated.
- ww520 16y agoThat speaks of a bad library and API design, not the language. Plus XML is a verbose technology in general.