среда, 30 октября 2013 г.

Code complete. Complete.

Just have finished reading Code Complete by Steve McConnell. This book blew up my mind. It contains a lot information about programming as a collection of  activities. The most useful idea for me was that we program for people first, computers second. Some useful thoughts i wrote out in my recent post "Programming quotes".

The last chapter contains the book list that a developer should read. Here it is:

суббота, 26 октября 2013 г.

Java 7. Find yourself what's new?

During the reading of Code Complete 2e I've come across the grep example. This utility helps you to find files matching your search criteria.
If you have a javadoc and you want to find out what's new then you can use the following example:

duglas@duglas-ThinkStation /usr/share/doc/openjdk-7-doc/api $ grep -R -l --include="*.html"   "<dd>1.7</dd>" . > /home/duglas/j.txt



This command will find all files that have been changed or added to the JDK 1.7. Moreover it allows you not only to rely on the what's new file but to explore the changes to the JDK documentation by yourself.

пятница, 25 октября 2013 г.

Spring Portlet MVC 3 on WebSphere Portal 7 cookbook

Here are my personal experience of Spring Portlet MVC 3 on WebSphere Portal 7.
  1. Spring profiles feature is not working in portlet environment.
  2. If your portlet use session for anonymous user, then you can enable it with container-runtime-option feature in portlet.xml like this:
         <container-runtime-option>
            <name>com.ibm.portal.public.session</name>
            <value>true</value>
        </container-runtime-option>
  3. Using client side aggregation and file upload doesn't work together. Switch you page to server side aggregation mode.
  4. When you first time add the event processing feature to portlets and deploy them to portal then you better switch the client side aggregation to server side aggregation. If you don't do this, then you cannot setup wires between your portlets.
  5. If you want your spring portlet to work in client side aggregation, then in your "form:form" tag set attribute htmlEscape="false".
  6. If you use Spring JDBC on WebSphere Portal  then  set connection extractor on your jdbc template like this:
    <bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor" />. This is especially useful if you need to work with special database types and\or stored procedures.
  7. Spring JDBC. Use jndi to create the datasource like this in application context:
    <jee:jndi-lookup id="myDataSource" jndi-name="jdbc/myds" cache="true" resource-ref="true" lookup-on-startup="false" proxy-interface="javax.sql.DataSource" />
  8. If you use JNDI resources in portlet then declare them in ibm-web-bnd.xml file like this:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-bnd
        xmlns="http://websphere.ibm.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd"
        version="1.0">
        <virtual-host name="default_host" />
        <resource-ref name="jdbc/mydb" binding-name="jdbc/mydb" />
    </web-bnd>
    Also don't forget to declare it in web.xml:
     <resource-ref>
        <res-ref-name>jdbc/mydb</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
        <mapped-name>jdbc/mydb</mapped-name>
      </resource-ref>
  9. When declare portlet.xml use the following declaration:
    <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
        version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
            http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
        id="myportlet.war">.
    Take a look at id attribute. This is how WebSphere Portal distinguishes your war files on portal.
  10. When work with AJAX use @ResourceMapping annotation extensively.
  11. Use spring portlet mvc mock objects for unit testing your controllers.
  12. Use @ExceptionHandler annotation to process exceptions in controller.
  13. Some other interesting information can be found http://www.ibm.com/developerworks/websphere/techjournal/0609_alcott/0609_alcott.html .
Update 24.11.2013:
When using @ResourceMapping  method you can return string, that will map to the jsp, so you can conveniently serve jsp content.

суббота, 12 октября 2013 г.

Programming quotes

Minimizing complexity is a key to writing high-quality code.

If you treat modifications as opportunities to tighten up the original design of the program, the quality improves.

A long parameter list is a warning that the abstraction of the routine interface has not been well thought out.

Program changes are a fact of life both during initial development and after initial release.

Ideas to manage your manager:
Plant ideas for what  you want to do, and then wait for your manager to have a brainstorm (your idea) about doing what you want to do.

Educate your manager about the right way to do things. This is an ongoing job because managers are often promoted, transfered, or fired.

Focus on your manager's interests, doing what he or she really wants you to do, and don't distract you manager with unnecessary implementation details. (Think of it as "encapsulation" of your job.)

Refuse to do what your manager tells you, and insist on doing your job the right way.

Find another job.

Code as if whoever maintains your program is a violent psychopath who knows where you live. -- Anonymous.

One key to effective  programming is learning to make mistakes quickly, learning from them each time. Making a mistake is no sin. Failing to learn from a mistake is. 

Code complete.2e.