by Bozho | Jun 30, 2011 | Aggregated, Software
Recently I was introduced to a project that’s already 4 months in development. After a day of coding I realized there’s something wrong with the session and transaction management. Then I found something that I’ve never used and didn’t quite know when it should be used – the EntityManager was injected into DAO objects via @PersistenceContext(type=PersistenceContextType.EXTENDED) First thing to do – google. Found this spring forum discussion, which made it clearer, but not quite. Then I started debugging and realized that the application is de-facto using the session-per-application anti-pattern. Not only that, but each DAO got its own entity manager (and underlying session) instance. An important note here – I say “entity manager and underlying session”, because Hibernate simply wraps its Session with an implementation of the standard EntityManager interface. So it makes a little difference whether we talk about entity manager or session. What happens? PerssitenceContextType.EXTENDED means that you, rather than spring, are in charge of managing your session. All spring does is create it on startup and close it on shutdown. The other option (which is the default – PerssitenceContextType.TRANSACTION) lets spring’s transaction managers create the entity manager (and session) for each request, start a transaction, and when you are finished – commit the transaction and close the session. This is called session and transaction management, and it is one of the most important things to do in a spring & JPA project. It should be done right almost from the start, so the next time you do such a project, spend extra days to get this right. But what is wrong with the above situation? Here...
by Bozho | Jun 27, 2011 | Aggregated, Software
My old laptop broke (3.5 years in service already), so I had to get a new one. I thought it would be easy – I went to an online store, picked some nice configuration (core i7, 8G RAM), and went to a real store to buy it. The price was around 700 euro. The brand was DELL, with an option for a Lenovo IdeaPad. It was when they opened the box when my disappointment started. I have never been picky in terms of quality of materials, but what was in front of me was a complete piece of crap. The keyboard was quite wobbly, and clumsily installed. There was a num-pad on a 15.6″ laptop. And it looked fragile. I was about to go for the IdeaPad, but a review from a friend showed that after 2 months the laptop has started failing … physically. Since I’m a developer, I have a couple of requirements: the best CPU and lots of RAM – it will get old in 3 years anyway good keyboard – stable and easy to use. No num-pad. 15.6″ – I will be moving it around from time to time (so no 17″) but I will be developing on in after all, so nothing less matted display Battery life and cooling are things that were optional – I’ve lived a long time with battery life of 2-3 hours, and my previous laptop was HP, so it had cooling problems, but apart form the noise it wasn’t an issue for these 3+ years. Much to my surprise this combination is impossible to find. Matted displays are only...
by Bozho | Jun 25, 2011 | Aggregated, Software
Ever since I started working full-time, I’ve been wearing slippers at work. Just because it is way more comfortable than staying with your shoes on all day long. Sounds weird? It shouldn’t, because it is a habit driven only by comfort and does not contradict any formal or informal rules at the usual software development company. I doubt there’s a software company with dress-code for developers. But there aren’t many people that afford that much comfort. Why? It looks strange and it is disrespectful – you are at work, not on holiday in a hotel. Others are trying to be dressed smartly and you are wearing slippers – what are you trying to demonstrate? And your feet smell! From these I can only take the last one as reasonable. If anything causes discomfort to your colleagues you shouldn’t do it. If this is not the case – go ahead and wear slippers at work. You’ll like it. The more general point here is that software development is (or at least we’d like it to be) creative and requires working conditions that are “above average”. Google seem to have realized that – they provide very cosy working environment. Joel Spolsky is also an advocate for pleasant workspace. Ever since I started working full-time, I’ve been wearing slippers at work. Just because it is way more comfortable than staying with your shoes on all day long. Sounds weird? It shouldn’t, because it is a habit driven only by comfort and does not contradict any formal or informal rules at the usual software development company. I doubt there’s a software company with...
by Bozho | Jun 21, 2011 | Aggregated, Software
How should you decide when to use trailing slashes with pretty URLs? In my opinion you should never use them. Why? Because a trailing slash denotes a directory, while the lack of it denotes a file/resource. So http://example.com/item/view/123 instead of http://example.com/item/view/123/. And certainly http://example.com/view?itemId=123 instead of http://example.com/view/?itemId=123. If these represented the directory structure of the web server it would be more straightforward, but with pretty URLs the content is dynamic and often can’t be bound to a directory structure. This article explains the matter in more details. Note however that it advocates retaining the trailing slash, but it doesn’t focus on pretty urls in particular. Yes, you should retain the trailing slash for your index page and for any directories, but that’s it. The rest are resources and so they should not have the slash. The main point is that you must be consistent. From the practical point of view it is not that wrong to retain the slash (although it contradicts the directory structure logic), but have it for every resource, and have all your links conform to that choice. What about SEO and 404 problems? With pretty urls the web server doesn’t handle redirects, so you have to handle them yourselves. You must accept both versions otherwise you may lose traffic and users might get 404s. But search engines treat the slash and the no-slash page as different resources and thus you may lose SEO “points”. So you must do 301 (Permanent) redirects from the slash to the no-slash url. How exactly depends on the framework and server you use. How should you decide when to use...
by Bozho | Jun 6, 2011 | Aggregated, Software
(This isn’t going to be a rant. I’ll try to figure out why the problems with the facebook graph API exist) The other day an article got popular on dzone. It indicated the same problems that me and some colleagues of mine have have been experiencing, and confirmed my suspicion – it’s not just me – the facebook graph API is bad. Guess which is the longest method in the welshare codebase (my startup project where I’m using the graph API extensively). It’s called postToMessage and obtains all the data I need to display the a facebook message. All code analysis tools that I use report problems with it: “Cyclomatic Complexity is 37 (max allowed is 7); NCSS for this method is 78 (max allowed is 50);”. And this is the only method that violates all these. I could split it to reduce the cyclomatic complexity a bit, but the code will still be bad. Why? Because the facebook API forces the code that is using it to do “ugly” things in order to get everything it needs. Here’s a (incomplete) list of what is currently wrong with the facebook API: It’s a mess. For example there is the Post object which should contain everything about a wall post. But it is really tedious to extract information from it. See the table I computed in a previous posting. In short – anything can be in any field It changes constantly. For a few days it just doesn’t fetch comments for some posts, for example. At some point you got the number of likes, another time you don’t. Not only...
Recent Comments