Puzzles: Informative alternatives for Java developers

Reading in my currrent favorate time-beater book when commuting I stumbled across the following:

\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0020\u0020\u0020
\u0063\u006c\u0061\u0073\u0073\u0020\u0055\u0067\u006c\u0079
\u007b\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0020\u0020
\u0020\u0020\u0020\u0020\u0073\u0074\u0061\u0074\u0069\u0063
\u0076\u006f\u0069\u0064\u0020\u006d\u0061\u0069\u006e\u0028
\u0053\u0074\u0072\u0069\u006e\u0067\u005b\u005d\u0020\u0020
\u0020\u0020\u0020\u0020\u0061\u0072\u0067\u0073\u0029\u007b
\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074
\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u0020
\u0022\u0048\u0065\u006c\u006c\u006f\u0020\u0077\u0022\u002b
\u0022\u006f\u0072\u006c\u0064\u0022\u0029\u003b\u007d\u007d

Guess what is this?*

Java Puzzles is one of these great book you can read when travelling short distances. It keeps you fit in the language basics and is fun to read. I also like the fact that being an  IT book for once and doesn’t require a computer to work it through. This is from a newer edition of Java Puzzlers Joshua Bloch and Neal Gafters book on traps, pitfalls and corner cases in the Java programming language.

* A Java Hello world in Unicode, due to Java’s native Unicode support this is completely legal.

Posted in Distractions, java | Comments closed

UX and App Design at Google – Takeaways

Yesterday I was at an interesting UX knowledgeshare event where Simon Raess spoke about user experience and application design at Google. Google being an engineering company at heart they arguably only put in the recent years more weight on Ux and Design. Also nowadays Google employs only 200 designers. Being an engineer myself, I expected to get some new insights from another perspective.

The talk was built around the first principle of Googles corporate philosophy “Focus on the user and all else will follow”. Being the first principle it is the most important one, and prioritised in favor of other conflicting aspects when making a product. Among other things, this means that the first thougth when starting with a product is not how to make money but what do users want.

The execution of this philosophy was explained with an outline how the product process works.
Focus on the user

Specifically for UX and design there are 4 interation phases Google follows:

1 Define                 4 Validate
2 Research            3 Design

The first thing is the definition of the product, and gathering of ideas. This comes from various sources, like their 20% time, Market Needs, and others.

After there’s a clear product idea the research phase starts. Research here does most importantly mean: Going out to the user, talk to the user and get feedback. So very early in the process of creating a product Google already starts to gather feedback for a rough idea. It is important to get feedback from a representative group of users, the type of users that should use the product in the end. Later in the research phase they create abstract personas. Personas are a way to classify typical user groups with their interest, habits, jobs, daily activities, emotions etc.

The next phase is the Design phase, where the actual design happens in the following sequence: Information Architecture, Layout/Workflow, Interaction Model, Visual Design. The design and research phase is lead by a designer and a researcher which are in tight collaboration. The design and research goes over many interations until feedback from users start to get positive.

Only when the feedback from users is positive detail planning starts. Finally the Design is validated by users and Google employees when the product is first internally launched.

Some tools they use to gather user feedback are: eye tracking, Labs, before and after experience questions.

Quite interesting to me was: no single line of code is written until detail design is finished. However engineers are involved during the design process but it was not so clear to what level and for what tasks. For me it would have been interesting to get some more information on the collaboration between engineers and designers in the process. Other than that, great talk!

Posted in Uncategorized, Web2.0 | Tagged , , | Comments closed

A Programmer’s New Year’s Resolution for 2010: Learning Scala

In a world of constant change and ever increasing speed of innovation as a programmer, you might sit back and think about how to prepare for those changes and increase your career options. You might also look forward to a mental distraction from the daily Java/Ruby/PHP routine, or your inner geek is just looking for the next big thing.

So without further ado and fanboy-ing here’s why I want to do it.

Scala
I first heard of Scala about an year ago in an article in the German Java Magazin. What caught my attention was that it was designed by a) a Swiss researcher (awakening to my national pride ;) ) and b) that Martin Odersky wrote the reference compiler for Java 1.5, and c) that the Twitter (messaging) backend at that time had just moved to Scala.

Scala is a general purpose programming language, statically typed and integrates features of object-oriented and functional languages.

Some properties Scala offers:

  • Runs on JVM: Scala is byte code compatible with Java and can therefore be used in combination with existing Java Libraries.
  • Combines functional with oo: Scala can take advantage of best of both worlds
  • Eases concurrency, scalablility: A certain amount of functional programming is inevitable, if multicore computers should be used efficiently.
  • Reduces code size by 2-4 compared to Java: Less code tends to require less work writing and maintaining it and also tends to have fewer defaults.
  • Particular use cases include Complex XML Processing, Concurrent programming, DSL

Within the TIOBE index Scala is at #33. There’s a lot of controversy if scala will be the next big thing. Some very well rounded arguments pro and contra. But as an old saying goes in German “Probieren geht über studieren” I choose to set off trying it myself for a private project or two. Stay tuned for the learning scala series.

Posted in Distractions, programming languages | Tagged | Comments closed

The old-school Objective C is approaching top 10

From time to time I check the index of the most popular programming languages by tiobe, check out how popular the old-school Objective-C is becoming!

Given that this language is very old school, it makes me wonder what would have happended to the Appshop and Apple if they opened the Shop for Java, PHP or Python?

Posted in mobile development, programming languages | Comments closed

MegaTrend #9: Cross-platform Mobile Development

In a recent article by InfoWorld Cross Platform mobile development was mentioned as one of the top 10 emerging enterprise technologies.

Until about 1 years ago the options for cross-platform mobile development were

  • doing platform specific native builds for Symbian, WinMo, Blackberry, UIQ, etc. or
  • Java development with specific twists per handset / handset group or
  • WAP/XHTML Mobile Web Site

One of the biggest pains faced by mobile developers was – and still is – device fragmentation. However, with the iPhone a lot of developers turned to develop natively for just one platform because of the tremendous ease and improvements it brought to about every aspect of mobile development:
distribution, ui – experience, not treating apps as third class citicents, monetarization options and needed targeting of devices to reach a critical mass. Now, Apple succeed to generate more than 2 billion downloads with less than 2% market share, truly amazing.

In the same year, autom 2007 Android came out with a SDK which promised even a better world for mobile developers. Due to its nature Android had a slower start, but is definitely emerging as one of the big platforms for the future.

Also in the same year Sun open-source released their LWUIT framework for J2ME development. LWUIT is a GUI framework to target not only Smartphones but also Featurephones of the last few years that support J2Me.

And with the iPhone being such a success of course the other players started to move as well and brought along their own SDK to develop compelling UI’s: Flash Lite (Adobe), WebOS (RIM), Bada (Samsung), Memo (Nokia), Widgets (many), JavaFX (Sun). Last but not least the J2ME spec leads finally settled on a MIDP 3.0 spec and the MSA standard which is pretty cool if it would be adapted by many players.

So instead of fragmentation being reduced, over the years, it has actually being increased. What has changed to the good are that some platforms like the iPhone, Android and maybe others offer now a fairly consistent set of handsets that are fairly wide distributed, so that selecting / specializing on one/two platform became an option for the mobile developer.

However also in the last few years mobile browsers have greatly improved and WebKit became a quasi browser standard. Also manufactures are starting to build javascript extensions to expose phone features like location, multimedia etc. One could argue that given this trend and the forces behind (Google, HTML 5, … ) should give the mobile web sites a good chance of a revival pretty soon. The problem however is, that even though with modern browsers those sites will not be that ugly anymore, users expectations for UI’s have increased as well. Another problem is discovery of mobile web sites. Even though there are 100’000 apps in the app shop, this numer is nothing in compare to the number of possible websites out there.

So what are the new possibilites for cross platform development now, 1 year later?

  • Widgets. W3C standard (no handsets yet though), or JIL (by Vodafone, Verizon, SoftBank and China Mobile): JIL defines a widget standard and more that 350 APIs to access to phone features, and this will be implemented on a lot of handsets in 2010/2011 (already in the oPhone from China Mobile or in the H1 from Samsung for instance).
  • CrossPlatform SDK Frameworks, players include PhoneGap, Rhomobile, and Appcelerator Titanium

The interesting thing about the cross platform SDK’s is that they supposly allow you to create real native looking apps with a uniform technology which is HTML/CSS/JS or Ruby in the case of Rhomobile. So instead of going the long curve of learing Objective-C and then porting the thing to Java for Android you can a) work with a well known web technology and b) have a single code base. Very promising, if they all will live up the promisses the future will show. If anybody has experience  using those SDK’s I would be very interested in opinions and comparisons.

Posted in mobile development | Tagged | Comments closed

Obfuscation Bugs in J2ME Apps

Does this sound familiar to you?

It really did drive me crazy. Bug only appeared in a certain phone model with a certain version of the app. Not in emulator, not in other phones, not with other version of the app and just 2 weeks ago – without major change in the app – all was running good in this certain phone. Of course I did not remember one crucial thing that happended in these 2 weeks: I upgraded my IDE NB from 6.1 to 6.7.1.

Shouldn’t matter you say? Not in J2ME development. In J2ME developmpent as a rule everything matters, I mean every little tiny seemingly irrelevant thingy you can imagine. So also an IDE change *did* matter.

The reason I found after about 2 hours of WTF’s: with 6.7.1 the proguard obfuscator changed and apparently introduced some bugs. Without obfuscating the app was running all smooth on this partucular phone. Fun thing is that I actually already had this problem once with an earier version of proguard, made a note and forgot about it.

I know about the location where the errors occured and am guessing its one of the errors that has been fixed in version 4.4. After I upgraded from proguard 4.2 to 4.4 all good again. I really want to remember this the next time I encounter such a nasty bug. I hope this post helps me with it, and hopefully it is also useful for some of you guys.

Posted in mobile development | Tagged , | Comments closed

FB Series: Difference between IFrame and Connect Apps

Writing about specifics on iFrame apps in Facebook development was on my list for quite some time. So now despite a lack of time, let’s just get out with the essential message:

When writing iFrame Apps, think of it like a Connect App. It is essentially the same.

I made the long way round trying to find out what are the specifics of a iFrame app in the Facebook Wiki, Forums, and Google. The Facebook Docs is very unclear about the concrete iFrame functionalities from my point of view. Start reading the Facebook docs substituting Connect with IFrame and you find it way easiert to get along, I found.

The only difference between a iFrame and a Facebook app are the size restrictments of 760px and some friend exchange functions, you probably will not be able to use as an app living inside FB. The other things are the same, since as an iFrame app you are technically another site living on a different server so all the cross-channel communication techniques and security models apply just like for an Connect app.

Also I would stay away from using XFBML whenever possible. XFBML works by parsing your HTML at runtime via Javascript and injecting iframes within your iframe when encountering a XFBML tag. When trying to use the XFBML language for display of Friend Selector, Permission dialogs etc. it tore my site apart and was generally unacceptable slow. I found that this architecture is probably not ready yet for production and it makes your site really slow at times.

Posted in facebook | Tagged | Comments closed

Lessons learned trusting Code Generators

To give you a short answer beforehand: Do not do it! But let me tell you my experience:

I started using Jersey back in 2007 when it was at version 0.4. Netbeans however already had a plugin to get you started on the fast track by generating REST Webservices out of Entity Classes, which you can also generate out of an existing db schema. At that time I was only starting learning JPA and was happy that the Netbeans Code Generators took care of most of my Entity Access Code. In retrospective I should have made the effort of learning everything JPA beforehand and not gradually as I worked along. Usually I actually would have done that, but the Code Generators tricked me into not doing it: It just seemed too simple to bother.

Here is what Netbeans generated to get an object by primary key:


Foo result = (Foo )service.createQuery("Select e from Foo e where e.id = :id").setParameter("id", id).getSingleResult();

Compared to:

Foo result = (Foo )service.find(Foo.class, id);

Problem with first approach besides being the obvious bloathed version: this will likely not be an easy cache hit wheras the second method, depending on your persistence provider will likely go a direct way to find the object within an identity map in the second level cache.

No big deal you might say just change the Query to a Finder method. Unfortunately its not just done with this because the getSingleResult also throws an unchecked NotFoundException when the Entity was not found, opposed to returning null in the finder method. In the generated code this exception was catched, wrapped and rethrown as a checked one. Nice so in some parts of my code was building logic upon those rethrown Exceptions when an entity was not found. So changing the way to retrieve an object had a long tail unfortunately.

Besides that the bigger problem is the design of an efficient and effective object domain model. I am speaking about fetch definitions, caching strategies, lazy / eager loading, and all that. At that time I was frankly just overloaded with a lot of other work beside the JPA stuff so I basically thought that the defaults that Netbeans generated might just work out well. Well no no no.

Another example are the Web Services Generators in Netbeans 6.7. As it turned out, the plugin developers have sometimes simplified-out methods as with the Facebook Service: There is no batching. You probably won’t write a Facebook application without using the batching support.

It feels to me that nowadays many IDE’s and tools come out with the message that they will do all the work for you. What you have to do is just some simple plumbing: enter an API key here, connect to your datebase there and you are done. My experience however is, even for a quick learning curve (and not learning by a bad example), it is better not to trust those generators in the first place and only use them if you can easily spot wrong code and correct such pieces yourself.

Posted in java | Tagged , , | Comments closed

Website deployments: Plain old Ant

In the last entry I was mentioning several solutions for managing web site deployments and packaging for php webapps. Since with PHP there is usually no build process already at development time this has often to be established especially for test & production – and yes there needs to be a build process if you do serious php web development.

Despite Sprocket or similar tools I decided to go for the plain old ANT approach. Why? It was the most practical tool, you have full control of what you are doing and the other tools did not quite what I wanted.

One part of this ant solution was to configure production setting in several source files. I rediscovered just how powerful and really simple this great tool is. Once you get used to is configure,combine,pack and deploy your php/js/html/css is a piece of cake:

Here some excerpts
In order to have just one source file I defined some custom preprocessor variables in my various files:

//@@prod@@ $config['base_dir']="";
/*@@dev@@*/ $config['base_dir']="Foo/";
<!--@@js-dev-start@@ -->
<script type="text/javascript" src="assets/js/jquery.plugin1.js"></script>
<script type='text/javascript' src='assets/js/jquery.plugin2.js'></script>
<script type="text/javascript" src="assets/js/jquery.plugin3.js"></script>
<script type="text/javascript" src="assets/js/jquery.plugin4.js"></script>
<script type="text/javascript" src="assets/js/jquery.plugin5.js"></script>
<!-- @@js-dev-end@@ -->
<!-- @@js-prod-start@@ <script type="text/javascript" src="assets/js/jsbuild.js"></script> @@js-prod-end@@ -->

then in ant this looks as follows:

<echo message="Configuring PHP config for production" />
  <replaceregexp byline="true" flags="m">
            <regexp pattern="^.*@@dev@@.*$"/>
            <substitution expression=""/>
            <fileset dir="${build.dir}" >
                <include name="php/config/*.php"/>
            </fileset>
        </replaceregexp> 
        <replaceregexp byline="true" flags="m">
            <regexp pattern="^.*@@prod@@(.*)$"/>
            <substitution expression="\1"/>
            <fileset dir="${build.dir}" >
                <include name="php/config/*.php"/>
            </fileset>
        </replaceregexp>

And for the javascript in my php – view files

<echo message="Configuring referenced Javascript for production" />
<replaceregexp flags="sg">
            <regexp pattern="@@js-dev-start@@[^\@]*@@js-dev-end@@"/>
            <substitution expression=""/>
            <fileset dir="${build.dir}/php/view" >
                <include name="**/*.php"/>
            </fileset>
        </replaceregexp>
        <replaceregexp byline="true"  flags="m">
            <regexp pattern="^.*@@js-prod-start@@(.*)@@js-prod-end@@.*$"/>
            <substitution expression="\1"/>
            <fileset dir="${build.dir}/php/view" >
                <include name="**/*.php"/>
            </fileset>
        </replaceregexp>

Applying the concat task for js and css concatenation and apply java to invoke the yuicompressor and you’re done.

Posted in javascript, php, Web2.0 | Tagged , , | Comments closed