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...
by Bozho | May 14, 2011 | Aggregated, Software
JPA and domain-driven design don’t mix well. In fact, JPA “entities” are representatives of the anemic data model that Fowler warns against. I have already discussed DDD in the light of JPA and dependency injection, so I won’t go into much details here whether anemic data model is bad or not (for the record: I don’t think it’s bad). But for the times you need to inject dependencies into entities standards don’t give you a hand. The only option is @Configurable, which requires aspectj weaving, which is “black magic” to me. So why you can’t inject dependencies into entities? Because they are created by you and not by a dependency injection framework. Well, here’s a weird idea. What if JPA 3 had EntityManager.createEntity(Foo.class) so that your entities are managed all the time? Then you’ll be able to inject dependencies different than other entities (which is already handled by JPA through associations). How will it work? JPA will require a DependencyManager which will provide the dependencies, handle their lifecycle, etc. CDI will be the default dependency manager of course, but any framework (spring, guice, etc) can plug-in their implementation whenever you em.create(..) your entity it will have its dependencies set – as if the entity is created by your DI framework this would mean that the “transient” state of entities will not exist (if you choose the create() method, that is) But… detached entities, or the cases when you need to create the entities where you should not have access to the entity manager (in a controller for example) are the most important thing. And I can’t give a satisfactory...
by Bozho | Apr 30, 2011 | Aggregated, Software
The usual choice for a collation in MySQL is utf8_general_ci (or whataver_ci). ci means “case insensitive” (there are also the _cs collations). All is fine with that, but if you are storing and then comparing Base64-encoded data, you may have a hidden issue. Base64 encoded data is case-sensitive, but the comparison with _ci collations is case-insensitive. So you are storing some base64 and then try to query for it: user1 base64: A543rFgTregW user2 base64: A543rFGtregw When you SELECT * FROM table WHERE base64column="..." you can get the incorrect user. I agree this is rare (as you should rarely query for binary data, no matter the representation), but it can waste a lot of time researching when it happens (it hasn’t happened to me, luckily). The solution is to use VARBINARY. The usual choice for a collation in MySQL is utf8_general_ci (or whataver_ci). ci means “case insensitive” (there are also the _cs collations). All is fine with that, but if you are storing and then comparing Base64-encoded data, you may have a hidden issue. Base64 encoded data is case-sensitive, but the comparison with _ci collations is case-insensitive. So you are storing some base64 and then try to query for it: user1 base64: A543rFgTregW user2 base64: A543rFGtregw When you SELECT * FROM table WHERE base64column="..." you can get the incorrect user. I agree this is rare (as you should rarely query for binary data, no matter the representation), but it can waste a lot of time researching when it happens (it hasn’t happened to me, luckily). The solution is to use...
Recent Comments