java-v-objective-c

There are a number of articles online that claim that neither Objective-C nor Java is better than the other, they’re just different. Well in terms of the mechanics and elegance of the language, I don’t agree– Java is the front-runner. Objective-C feels pretty archaic by comparison, and I suppose it truly is, being only a thin layer on top of standard ANSI C. Here are my top 10 gripes with Objective-C:

1. Lack of abstract/virtual classes and methods. Sometimes I want to ensure that a base class is never instantiated itself, other times I want to be sure that a subclass of a base class implements a particular method. In the case of the former, this is simply not possible– Objective-C has no concept of abstract classes. In the case of the latter, this is only achievable using protocols (i.e. similar to a Java interface) which seems slightly awkward- it requires considerably more code and bother than would be required of an abstract method in Java.

2. Lack of namespace support: It seems a bit silly that object types are prefaced with a Hungarian notation-like two characters indicating their source. The lack of namespaces also drastically increases the probability of naming collisions.

3. Header files… Groan. Defining an interface for every class is such a pain and requires so many more lines of code than are necessary. I find myself dreading every time I require a new class because of this and the fact that XCode’s code completion features are pitiful compared to Eclipse’s.

4. Managing memory: how I miss garbage collection.

5. Pointers: it is exceedingly rare that I would ever want or need to know the memory address of a variable, so why not abstract this information away? It’s easy to forget an * or @ and it can be difficult to debug problems relating to this.

6. Poor logging. NSLog is pretty poor and I haven’t been able to find anything like log4j for Objective-C.

7. Delegation, delelgation and more delegation. Objective-C makes huge use of the concept of delegation and I find that this can lead to spaghetti like code that can be difficult to follow.

8. Compiler reporting: Cryptic error messages and the poor logging described in 7 can make for challenging debugging.

9. Unit testing: OCUnit and OCMock are fairly immature compared to jUnit and jMock. And furthermore, a number of Cocoa classes include real work in their “constructors.” For instance, NSUrlConnection actually opens an HTTP connection and interacts online in its initWithRequest:delegate: method. The problem this creates is that object creation is tied to real work. This makes dependency injection difficult because we can’t separate the creation of the object from the logic, which would be required in order to substitute a test stub with test logic in its place. Dang. For more on this, see Misko Hevery’s great article on unit testing, object creation and logic.

10. No private methods. I often find myself in the position of using private methods within a class to define the specification of a procedure within that class… e.g.

loadSomeData();
doSomethingToData();
sendDataSomewhereElse();

These would all be private methods with the detail abstracted away. Unfortunately such methods need to be defined as part a class’s (public) interface even if only used within that class. Argh.

That’s it so far.. Feel free to add your own gripes in the comments.

1 Comment, Written on July 7th, 2010 , All, Dev & Test, Tech

simon3000-150px

Simon 3000 is a modern day take on the classic Simon game from the 1980s that lets you compete against your Facebook friends and other players nearby. It’s a contemporary Simon with social and location-based features.

It’s just launched into the iPhone App Store and you can check it out here.

Enjoy!

Leave A Comment, Written on May 10th, 2010 , All, Mobile, Tech

latte-art-651_s6ny3k74

Working from home occasionally makes you get a little stir crazy, so it’s good to get out every now and then to interact with the real world. Bouncing around the coffee shops of London’s east end serves this purpose well for me, and so I end up drinking many a flat white ’round these parts. Here’s a list of my favourites for working away from home, in no particular order:

  • The Eatery – Perched right on Whitechapel Road at the bottom of Brick Lane, this place is quite unassuming and has some of the best croissants I’ve had in London. The prices are also cheap– my usual Americano and a croissant costs a mere £2.20. Independent readers take note: journalist Johann Hari can be spotted here thumbing through an enormous stack of newspapers on occassional weekday mornings.
  • Cafe 1001 – The cheesecake here is excellent. The largest of this bunch, Cafe 1001 still manages to maintain a cosy atmosphere. As this venue is also used as a nightclub, the cleanliness leaves something to be desired but it’s a pretty fair trade for the great vibe. Comfortable sofas and dim lights define the atmosphere. This place is often packed with students and media folk tapping away at their MacBooks.
  • Coffee @ – If drinking your coffee surrounded by fashion students with a backing soundtrack of electroclash is your thing, then Coffee @ is for you. I find it a little difficult to concentrate here with the high music and conversation volume levels, but it does have a certain charm. A wide range of coffees and fairly decent sandwiches keep you satiated. This place is small, but has enough seating to ensure there’s always a free spot.
  • Nude Espresso – I end up at Nude more than any other place, though it can be a bit hit and miss. The serving sizes of coffees are very small, though of good quality. The real stand-out product for me are the sandwiches– truly scrumptious! Pastries and muffins are also toothsome, though it needs to be said that this is the most expensive place on this list. Don’t expect any change back from a fiver for a coffee and a pastry. Note that they turn off their wifi inbetween 12 and 2PM for the lunch rush.
  • Albion – Also one of my favourite places for weekend brunch, Albion is great for coffee and a snack. Coffee is served in an attractive red metal pot and tea in a wool cosy. Breakfasts are very tasty and this place is popular during the week with the digital nomad crowd. You can spot groups from many of the nearby tech companies camping out for midweek meetings. There is usually a bit of a queue at weekends but if your group isn’t large then you’re usually seated within 15 minutes. Weekdays are considerably quieter and require no queueing. This place is more than just a coffee shop and serves a traditional British menu throughout the day. I love it!
  • Honourable mention: Present – Present is a fairly new clothing store and coffee shop that’s recently popped up at the top of Shoreditch High Street. The coffee is fantastic and was just last week voted best coffee in London by TimeOut magazine. So why is it only getting an honourable mention here? Because there is no space to work or even have a seat. But if you want to have a fantastic flat white while browsing the latest menswear trends, you could do no better.
  • 2 Comments, Written on February 26th, 2010 , All, Food

I recently switched to Chrome as my primary web browser because I was becoming increasingly frustrated with how resource hungry Firefox is. FF would regularly consume more than 1GB of RAM and problems with one web page would occassionally take out the entire browser. Chrome’s unique process model ensures that this never happens, and it consumes considerably less RAM than Firefox.

chrome-v-firefox-002

That said, Chrome is feature-poor when compared to FF and it is not without its flaws. And so here I present a list of the things I miss most about Firefox:

  1. A wide selection of extensions/plugins. I rely heavily on Firefox plugins like FireBug, HttpFox, ElasticFox and S3Organiser for debugging websites and managing resources in the cloud. Chrome only introduced extensions at the end of last year and currently there are not many available, though thankfully this will change over time.
  2. RSS support. Chrome simply isn’t there yet. I was a bit surprised to learn that Chrome does not have a feature for auto-detecting and subscribing to RSS feeds, nor does it even display RSS content in an easily digestible format. It’s funny to think that Firefox is better integrated with Google Reader than Google’s own Chrome.
  3. A design consistent with Windows / manageable toolbars. Google has applied their own unchangeable design ethos to Chrome that is a departure from the typical Windows app. For one, tabs are where the title bar normally appears and there is no menu bar in Chrome. I can understand why Google did this, wanting to maximise space and put the most important information at the top, but I think this lack of consistency with other Windows apps makes Chrome appear a little cludgy and can lead to momentary confusion when working at rapid speed, switching through windows quickly. Ultimately, it would be nice to be able to customise the top-most toolbar area as you can with other browsers.
  4. Windows that size correctly. I’ve tried various fixes for this with no success under Windows 7. For the life of me I cannot get Chrome to open a new window in a maximised state after the initial start of Chrome. Instead, new windows after the first open at a greatly reduced width which results in me having to maximise them myself before any serious browsing.
  5. Comprehensive bookmark support. I am a serial bookmarker. I bookmark hundreds of web pages each month and thus require a fairly extensive system for managing them that consists of organising them into folders, tagging them and adding descriptions. Unfortunately Chrome at this point only allows you to organise bookmarks into folders, and this is going to make them difficult for me to recall in future. Particularly, I need tags so that I can apply more than one nested dimension of categorisation to my bookmarks. It would also help if Chrome’s Bookmark Manager had more sortable columns of data for bookmarks like FF does.

Firefox is clearly a much more mature browser and Chrome has a fair bit of catching up to do in terms of feature support, but Google is no doubt hard at work trying to pick up the slack. In the mean time, Chrome does perform infinitely better than FF and that is enough for me to continue to use it as my primary browser.

Leave A Comment, Written on February 23rd, 2010 , All, Tech

W3 AR3 T3H GOOGLE BORG. W3 PWNZ J00.

For some time now I’ve been comparing my usual search queries using this Google vs Bing tool, and the frank truth is that for a lot of the things that I search for, Bing gives me more accurate results that are more relevant to me than Google. This is likely only to improve when Wolfram Alpha is incorporated into Bing, but even now I can’t deny that Bing is the best default search engine for many of my queries.

But I haven’t switched, and I won’t. Google is still my default home page in every browser I use. There’s one simple reason for it– my online behaviours have become so enmeshed with Google that any sort of divorce is quite simply not an option. So what serves as the ball-and-chain? iGoogle and Google Apps, which have become products that drive me continually back to Google’s economic engine: Search.

Many years ago I began using Google Apps as a matter of curiosity and convenience. It started with Gmail, and some time later followed with Google Reader, Google Maps, Google Calendar, and Google Docs. Now I have become so dependent on all of them that they effectively act as an impetus to continue to use good old iGoogle as my home page, even if better search results are out there to be had. Giving up easy and immediate access to my all-important iGoogle + Google Gadget-based Apps dashboard is simply unfathomable. The plain truth is that I am no longer simply a regular user of Google Search but rather a hooked user of the Google Platform, of which Search is only a part, and for me to give up my dependency on the platform would be a huge task.

The introduction of social features into Google products only tightened their grip on me. With the arrival of Google Talk/Chat in 2005 I was suddenly able to interact with my Gmail contacts in the immediate form of instant messages. Google almost overnight took on characteristics of a social network, and I found myself with yet another compelling reason to have Gmail and hence Google itself open on my desktop at all times. Even the fact that Google Talk uses open protocols and that I could use any XMPP client with it is not enough to dissuade me. And midway through last year Google introduced social features into Reader. The nefarious Google Grip tightened fruther. Social features tend to make products especially sticky for the simple reason that everyone wants to be where their friends are, and the cost of switching tends to be high (e.g. building up a whole new network of contacts in a new product).

Two things are set to draw my relationship with Google even closer. One is the emergence of Android. I have avoided adopting an Android handset for the same reason that I have in past shunned the iPhone: poor feature set. But this is set to change this year. Android will finally see handsets with good quality cameras, zippy processors and all the other high-end features we’ve come to expect. And because of Android’s fantastic integration with Google apps, these new devices will only serve to further the Google platform’s importance and dominance.

picardchromeborgThe other, of course, is the coming of Chrome OS. As Google Apps already acts as a sort of social and professional productivity platform, an operating system that supports and increasingly intregrates the products of the platform makes perfect sense, and yet will further indenture us to Google. Then, like the hive mind stretching its tentacles into the consciousnesses of all its Borg followers, so too will Google’s reach extend out to all of us via our mobile and desktop operating systems, with Search at its core.

So even if Google Search isn’t the stand-out it once was, ultimately Google and me look set to be partners for the longhaul. iGoogle & Google Apps have effectively bound me to using Google Search. Google’s operating systems will cement this relationship further. If Bing could match the ease and convenience of iGoogle + Google Apps with similar products, then they’d still have the enormous barriers of social software change to overcome. You’re fighting a tough battle, Microsoft.

2 Comments, Written on February 3rd, 2010 , All, Ruminations, Social Software, Tech

abba-the-winner-takes-it-all-19801

There’s been some discussion recently in the blogosphere about how the business of social software is becoming more and more of a winner-takes-all proposition. It’s at least partially true as everyone wants to be where their friends are and social software products are not perfectly replaceable like Coke and Pepsi. The cost of switching from a Facebook to a Bebo is much higher than simply changing your mind at a vending machine. You grow a social network on one platform over the course of months and years, and it can be a daunting task to embark on a wholesale switch.

Surely this is why Facebook blocks the other players from accessing their API, including Google. The resultant portability of data would make the barrier to switching infinitely less daunting. Thus it seems that there can be only one key player in each major social market, to every other competitors’ detraction.

But does this issue extend to niche social software offerings? At first it might seem true. In the location-based services arena, for instance, it may seem that there can be only one Loopt, or Whrrl, or BrightKite for the same reasons that Facebook is so far ahead of all other players in the broader consumer social sphere. But technologies like OpenSocial, Facebook Connect, Google Friend Connect, MySpaceID, OpenID and oAuth mean that this does not have to be the case. In fact, it is hardly a necessity to even build social features into your products anymore when your products can piggy-back on the platforms of the existing major networks. Thus it seems likely that the winners in the niche market spaces will be ones that eschew building their own propriety networks in favour of augmenting existing networks. If you can bring your service to existing networks rather than having to build your own network then you overcome one of the great barriers to user adoption of social apps: building a trusted network of friends and contacts within the system.

Leave A Comment, Written on January 27th, 2010 , Uncategorized

Whenever I revert to coding in PHP after an extended sprint in Java, I inevitably find myself somewhat frustrated by some of the shortcomings of PHP. Most of these have to do with how much less maintainable a large code-base becomes in PHP as opposed to Java. Recently, I wanted to quickly whip up a few webapps and decided to try working with the Symony PHP framework to see how quickly I could generate a webapp compared to using Struts 2 in Java.

java-v-php

I found Symfony to be a very effective and well-thought out framework. It was easy to learn and yes, it was not long before I had a functional web app online.

My issues are not with Symfony, but with PHP itself. First off is the plethora of static functions that PHP has on offer. Most of these would be encapsulated as methods of objects in Java (for instance instead of string.equals(otherString) in Java one would use in PHP the static method str_cmp(string, otherString)). This lack of encapsulation and the huge number of global methods makes for a very messy and expansive domain in which to work. Ultimately, I suppose this is a vestige of PHP’s procedural roots.

The lack of namespaces is another gripe, which further adds to the murky domain space of a PHP project. It’s not easy to see how objects relate to each other in terms of an organisational hierarchy in PHP, whereas this is a necessity in Java.

I also find awkward that in PHP you are in the postion of having to import files in order to gain additional functionality rather than importing classes. While technically these two things might not be so different, conceptually they are. An imported file can have functions and variables defined with no association to an object that effectively become global in scope on import. Static classes can have the same effect in Java, but I think most Java programmers have by now learned to avoid using static objects for the most part. The default behavior in Java is to use instances of classes whereas in PHP the default behaviour for many still seems to be to use collections of functions and function libraries.

I also find that PHP feels really quite verbose. All my PHP templates look rather ugly with echo statements littered everywhere. It’s not nearly as elegant as Freemarker.

With all other factors such as scalability, support, and resilience aside, I think PHP works great for small- to mid-sized web apps where maintainability of the code base is not a top priority. But for large, complex, long-life webapps, It seems to me that using a Java framework may be more appropriate in no small part because the quality and maintainability of the code will be considerably higher. This is not to say that you can’t create quality, maintainable apps in PHP, but that it is easier and more natural to do so in Java, where types are static, code encapsulation is paramount, and namespaces rule the roost.

17 Comments, Written on January 18th, 2010 , Dev & Test, Tech

falling_share_price
It’s amazing how Google’s product announcements can instantaneously shake up the landscape of a market. When Google announced Google Maps Navigation at the end of October, the share prices of Garmin and TomTom crashed by 16% and 21% respectively. And since then they’ve only gotten worse.

Just yesterday, Google did it again by announcing high-level details of a new property service to be integrated into Google Maps. This would allow estate agents and private individuals to list properties for free, while companies like Rightmove continue to charge agents hundreds of pounds a month in fees. Furthermore, most of these services are closed to private home sellers. Needless to say, Rightmove’s share price tumbled 10% yesterday.

So what’s Google’s next target? It’s probably an industry you don’t want to be in.

Leave A Comment, Written on December 4th, 2009 , Ruminations, Tech

I’m currently running several web apps from one Tomcat instance and they share several libraries that require log4j logging, Sitemesh, for instance. For this reason, I removed log4j.jar from each of my webapp’s “lib” folders and placed it instead in “${catalina.home}/lib” (note that I’m using Tomcat 6. This would be “${catalina.home}/common/lib” in earlier Tomcat versions)

I didn’t realise that this would create a a myriad of problems. What I found was that in my test environment, logging for all webapps ended up going to the log file for one particular webapp, while in my staging environment logging for all webapps went to the log file for a totally different webapp.

It took some time, but ultimately I got to the bottom of it. Apparently log4j does not play nice when the same log4j.jar is being used by multiple webapps. Configuring the rootLogger for one webapp appears to overwrite rootLogger settings for another webapp if log4j.jar is shared. Since each of my webapps was configuring the rootLogger to append to a different particular file, this meant that all logging ended up in only one file.

To circumvent the issue, log4j.jar must be place in each individual webapp’s “lib” folder in addition to Tomcat’s common library folder. Additionally, your web apps must be configured to use their own class loaders before using the parent class loader. This was my stumbling block. Your Tomcat context containers need to be set up something like:

<Context>
     <loader delegate=“false”/>
</Context>

If delegate is set to true then each webapp loads the common log4j.jar in favour of its own log4j.jar, giving rise to the problem.

1 Comment, Written on September 2nd, 2009 , Dev & Test, Tech

Matt Raible has a post here discussing how to use Sitemesh to decorate multiple webapps. When applying this to various Struts 2 webapps that use Freemarker, I found the process required a little further fine tuning. I’ve outlined the steps I’ve taken to get this working here.

One key issue to keep in mind is that the struts 2 sitemesh filter that comes with Struts 2 cannot refer to decorators in other webapps. This isn’t documented anywhere and certainly tripped me up.

  1. Configure a web app to host the decorators. This should have a web.xml that includes something like the following:
    <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
           
    <servlet>
        <servlet-name>sitemesh-freemarker</servlet-name>
        <servlet-class>com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet</servlet-class>
            <init-param>
                    <param-name>TemplatePath</param-name>
                    <param-value>/</param-value>
            </init-param>
            <init-param>
                    <param-name>default_encoding</param-name>
                    <param-value>ISO-8859-1</param-value>
            </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
           
    <servlet-mapping>
        <servlet-name>sitemesh-freemarker</servlet-name>
        <url-pattern>*.ftl</url-pattern>
    </servlet-mapping>

    Note that this webapp is thus set up basically just to use Freemarker and Sitemesh together as outlined here.

  2. Struts 2 web apps that will use the shared decorators in some other webapp must NOT use the struts2-sitemesh PageFilter that comes with Struts 2, but instead use the PageFilter that comes with the regular sitemesh distribution:
  3. <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
    </filter>
    <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
  4. Struts 2 web apps point to decorators in the host webapp, as outlined in MR’s post:
    <decorators>
        <excludes>
            <pattern>/styles/*</pattern>
            <pattern>/scripts/*</pattern>
            <pattern>/images/*</pattern>
            <pattern>/index.html</pattern>
            <pattern>/admBase/*</pattern>
            <pattern>/jforum.page?module=admBase*</pattern>
        </excludes>
     
        <!– load decorator from a different web-app deployed in the server –>
        <decorator name=“layout” webapp=“yourWebApp” page=“/WEB-INF/decorators/YourDecorator.ftl”>
            <pattern>/*</pattern>
        </decorator>

    </decorators>

  5. crossContext must be set to true for all your webapps. (Your context elements will no doubt look considerably different, especially if you’re loading webapps from server.xml rather than individual context files)
  6. <Context reloadable=“false” crossContext=“true”>
            <Loader delegate=“true”/>
    </Context>

    And you should be good to go.

1 Comment, Written on July 14th, 2009 , Dev & Test, Tech

richardrauser.com is proudly powered by WordPress and the Theme Adventure by Eric Schwarz
Entries (RSS) and Comments (RSS).

richardrauser.com