Skip to main content

Craftsmanship

It was a busy month, all work no play... more about polishing, both code and UI, to make a better product.

1. Code Polishing

In the current Java Spring project, there are a few things worth mentioning.



1. Service layer for MVC.


My previous projects are mostly architected under MVC pattern. There is nothing wrong about that. However, when the logic gets more complexed, handling all the logic in the controller layer would not be as clean and efficient. Another layer named Service for better data access and logic control is used in the our project. http://stackoverflow.com/questions/5702391/mvcs-model-view-controller-service


The controller would not be handling too many logics, instead, it only handles routing and  parameter passing. Most logics will be handled in the service layer.


2. Exception handling vs error codes


In the beginning, I didn’t do any exception handling in the service layer, neither do I create many exception handlers in the controller layer.After reviewing my peers codes, I realize that it is more elegant to throw exception than returning error code. http://stackoverflow.com/questions/253314/exceptions-or-error-codes


In the project, we used exception handling in the service layer to return exceptions which are inherited from IOException. I found the logic clearer after shifting to the exception handling idea in my codes.


3. Bad thing about lazy fetch type

In hibernate, it specifies the lazy fetch type, which is intended to reduce database memory access for relationships such as @OneToOne, @OneToMany,  @ManyToMany ,etc.
In the following blog post, the author stated some good explanations about the difference of each fetch type. http://howtoprogramwithjava.com/hibernate-eager-vs-lazy-fetch-type/


FetchType.LAZY = Doesn’t load the relationships unless explicitly “asked for” via getter
FetchType.EAGER = Loads ALL relationships”


However, lazy can be very troublesome in some circumstances. I had a lot of null pointer exceptions when trying to get lazy type relationship entities. I've got to manually parse these relationship entities into Map before sending them to the view, which makes the code very dirty.

For instance, in the following code, I want to get all users and their associated roles. Simply get the user list array won't return the roles because of the lazy issue. But I still need to display the associated role information in the view. I've got to use the ugly way to parse the role list into strings before sending to the view. If you know any better approaches, please let me know. Thanks!
    public List<Map<String,String>> getUserList(){
        List<Map<String,String>> userList = new ArrayList<>();
        List<DashboardUser> allDashboardUsers = Lists.newArrayList(userDao.findAll());
        for (DashboardUser dashboardUser : allDashboardUsers) {
            Map<String, String> aMap = new HashMap<>();
            aMap.put("id",dashboardUser.getId().toString());
            aMap.put("email",dashboardUser.getEmail());
            aMap.put("username",dashboardUser.getUserName());
            String roles ="";
            for(Role role:dashboardUser.getRoles()){
                roles+="/"+role.getName();
            }
            aMap.put("roles",roles);
            userList.add(aMap);
        }
        return userList;
    }
2. UI polishing


Switch to angular.js.

Previously, the project is developed under jQuery. The views are not structurally organised, until it becomes quite a messy.The team decided to use angular because it’s clean and structured. After one week's polishing, the codes become much more beautiful, both in the front end and the backend.


I may write another blog about angular when the project gets more polished.

3. Project management


1. We tried to explore the scrum 
meeting(http://en.wikipedia.org/wiki/Scrum_(software_development)) inside the small team. It works quite good. The basic scrum workflow consists of sprint planning, daily scrum meeting and end review meeting.  

The daily scrum meeting is not hard to follow. We started the meeting at 9:45am for <=15 minutes everyday at the same location asking the following questions:

“1. The basic What have you done since yesterday?
2. What are you planning to do today?
3. Any impediments/stumbling blocks? “
The tasks will be noted down by the scrum master and posted on a public wall. It makes every one involved and aware of the progress.

2. Github feature branch

Previously, we develop the features under our own develop branches and make pull requests to the origin develop branch when a new feature was added. However, that’s not a good design. The new feature commits are mixed with the develop branch and you can hardly distinguish which features are added by whom in a structural manner.

Thanks Peng jun and Xu Fan for sharing this. 

http://danielkummer.github.io/git-flow-cheatsheet/

Another tip for using github is to use git stash for saving unfinished changes in the current branch before switching to another local branch.

Comments

Popular posts from this blog

InnovFest 2015

I attended the innovFest 2015 event. It was quite eye opening. Besides the booth, some topics in the forums also interested me. The first topic I joined was the Kopi Chat with Yossi Vardi, a famous Israeli entrepreneur and investor. He is straightforward and humorous. When talking about the most important reason why people wake up with a great idea but ended up sleeping without executing anything, he collected answers from the audiences. One answer pretty much fitted his appetite-- "People fear about losing faces". He shared his opinion with the quotes from Theodore Roosevelt, “It is not the critic who counts; not the man who points out how the strong man stumbles, or where the doer of deeds could have done them better. The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood; who strives valiantly; who errs, who comes short again and again, because there is no effort without error and shortcoming; but who does actually st...

Time Goes By, So Fast

It's been a week since the last blog entry, time goes by so fast. This week's highlights: 1. Rethought about career development. http://www.douban.com/note/276145923/ 2. Treated my friends a traditional Shaoxing meal. 3. Started to learn Ruby on Rails. http://guides.rubyonrails.org/getting_started.html 4. Started to read the book "Simple and Usable Web, Mobile, and Interaction Design" by Giles Colborne. 5. Recorded some vocals. http://site.douban.com/shaohuan 6. Watched this Ted speech:  http://www.ted.com/talks/angela_lee_duckworth_the_key_to_success_grit.html 7. Followed Ahbei(founder of Douban) on Zhihu(Chinese version of Quora). 8. " 我认为世界上不存在一流的人才,世界上只有存在一流的人才一定是学习能力,谦虚,把自己当平凡的人" --马云(Jack Ma)

About Memory

Today, I went for an Evernote Sharing event in an incubator named Blk71. The event is more on user feedbacks and marketing. There are three thoughts to be highlighted. 1. Attending this kind of entrepreneur events is a very good approach for reaching out more contacts. Many people who have their own businesses or plan to build their own startups will come and attend this kind of events.There is one entrepreneur who shared his experience of how he used Evernote to design his own app. He got the chance to advertise his own app while sharing the experience. Another software developer shared how his company integrated Evernote's public API. He indeed shared a lot more on his own product rather than Evernote. During the break, I talked with two entrepreneurs. One is a NUS computer engineering alumni. He is now running his own retailing company on baby products. It works well as there weren't competitors in Singapore when he first started his business. Though there is no relations...