rc3.org

Strong opinions, weakly held

Tag: software development (page 6 of 16)

Java coding style, accessor methods, and IDEs

Last week I was asked to answer a question about our code base and wound up with the wrong answer for what I think are interesting reasons. Thus, a few thoughts on the power of IDEs, the importance of coding standards, and a problem with the way Java handles accessor methods.

The application I work on queries an external datasource and then does stuff with the incoming data to provide a variety of results. I often get questions about how, exactly, we’re using that external data to make decisions. The incoming data is copied into Java classes which are persisted in the database using Hibernate.

My usual approach to answering these types of questions is to open Eclipse, find the appropriate accessor method for the value in question, and then use the fantastic “Find References” function to locate all the places in our code where we use that value. (It’s Command-Shift-G on your keyboard if you’re a Mac user.) If someone asked where a certain value originates, I start by pulling up all of the references to to the setter method. If someone asks how the value is being used, I find all of the references to the getter. Sometimes the sleuthing involves navigating through the code by finding a method that calls an accessor, then finding all the places that method is called, and so on.

For all of the hassle associated with building Java applications, the power of Java IDEs almost makes it worth it. I find it easy to be productive using TextMate to work on Ruby on Rails applications, but I always miss features like “Find References” and “Open Declaration” that are found in Eclipse. Eclipse, IntelliJ IDEA, and other Java IDEs build a semantic model of Java code that makes it very easy to manage your code that aren’t available when using other languages and editors. Any developer who’s avoided a bug because their IDE told them a local variable is never referenced anywhere knows exactly what I’m talking about.

Anyway, I had trouble figuring out how our code worked because I was investigating a feature written by another developer. The get method in question didn’t have any usages in our code base, and I assumed that while the value was being stored in the database, it was not incorporated into our business logic. I was asked to look again, and deeper inspection revealed that the member variable associated with the accessor I was searching for was accessed directly in other methods in its class.

When people talk about coding standards, this sort of thing is a bigger deal than bracket placement or tab size. My habit is to always use accessor methods if they’re available, whereas this other developer’s habit was to use the instance variables within the class. It’s probably better to do it one way or the other, or at least to have a clear understanding of why you might use one or the other in a given situation. The fact that we didn’t cost us a little wasted time, and could have been worse had I not reinvestigated and made sure that things were working as expected and not the way I thought they were.

This also underscores a drawback of the way Java handles accessor methods. Because accessors are regular methods, there are no easy ways to pull up all of the references to a particular variable that includes both references to the instance variable and to the accessors. It seems like Ruby accessors would lend themselves better to a more consistent approach. I’d also be curious to know whether the accessor implementation in C# leads to better tools.

Building distributable Web applications

My current project involves building a commercial Java Web application. For years I’ve built Web applications (using Java and a number of other platforms) to deploy on our own servers. Building something that’s suitable for distribution is a horse of a different color. I thought I’d write up my experiences for other people who are taking on similar tasks.

  • Distribution format – Usually Java applications are distributed as WAR or EAR files, but many people also package their Java Web applications with a servlet container to run them to make things easier.
  • Open source licenses – My application uses a number of open source libraries, and I had to go through and make sure that all of the libraries were distributable without much fuss.
  • Configuration – What’s the best way to set up database connections and other configuration parameters?
  • Deployment platform – In theory, Java Web applications should work with any servlet container, but the devil is always in the details. Many Java applications seem to be distributed with a servlet container as well. What’s the best approach?

Look for separate posts dealing with each of those issues.

I’m sure other considerations will arise as well, but those are the first few that have cropped up as I’ve started working on this.

Embarking on this process makes it clear why PHP has become the dominant platform for writing distributable Web applications. Regardless of its strengths and weaknesses as a development platform, its deployment story is hard to beat.

There are no real questions when it comes to distribution format. You archive the files and put them up for download. The end user downloads the archive, expands it, and puts the files in the directory where they want the application to appear.

As far as licenses go, many PHP applications have no external dependencies. PHP provides all of the functionality you need for most applications, and PHP developers have never really taken to using libraries to make things easier. Java developers tend to use tons of third party libraries, and Ruby on Rails applications often depend on dozens of Gems. PHP developers use what’s available as part of PHP and that’s it. PEAR is out there, but it isn’t terribly popular. I assume that’s because so many PHP applications are deployed on shared hosting. It’s just not worth the risk to bring in dependencies if you don’t have to.

Configuring a PHP application usually involves editing one heavily commented PHP file. Most people consider that to be inelegant, but it’s hard to argue with the simplicity.

PHP is ubiquitous, so there’s not much to worry about in terms of deployment. You just need Apache with PHP support.

When you look at those factors as compared to Java or Ruby, it’s easy to see why PHP maintains its massive popularity over other development platforms, and why we see explosive growth among applications built using PHP, like Drupal, WordPress, and MediaWiki. For all its drawbacks, PHP has evolved in a world where simple deployment and configuration are both hugely important, and that has given PHP some powerful advantages that other platforms aren’t even trying to compete with.

Keep your eye on the scoreboard

Lately I’ve taken to playing Words With Friends, a Scrabble game for the iPhone. One of the first things I learned from playing against good players is that Scrabble is not about showing off your good vocabulary, it’s about turning the tiles you draw into points. A two letter word that nets you 31 points because you dropped a Q onto a triple letter score to make the used-only-in-Scrabble word “QI” is better than busting out a 6 letter word nobody’s ever heard of that nets 18 points.

I thought about that when I read Rands’ interview with Marco Arment about Instapaper, and being a one-man software development shop. Here’s what Arment says about making it as a sole proprietor:

The biggest design decision I’ve made is more of a continuous philosophy: do as few extremely time-consuming features as possible. As a result, Instapaper is a collection of a bunch of very easy things and only a handful of semi-hard things.

This philosophy sounds simple, but it isn’t: geeks like us are always tempted to implement very complex, never-ending features because they’re academically or algorithmically interesting, or because they can add massive value if done well, such as speech or handwriting recognition, recommendation engines, or natural-language processing.

Both are nice reminders that efficiency is one of the keys to success.

Be sure to read the explanation of how the Instapaper bookmarklet works, as well. It’s a marvel.

2011 Skill of the Year

I’ve set upon the idea of picking up a new skill this year. Over the past couple of years I’ve let my Ruby on Rails skills atrophy as I haven’t been working on any Rails applications professionally, and the Rails world changes too quickly to keep up with if you aren’t immersed in it every day. Instead I’ve been using a lot of Java, PHP, HTML, CSS, and SQL, with a dash of client-side JavaScript when needed. In 2011, it’s time to pick up something new or take a new look at something old. Here are the options I considered.

Ruby on Rails is something I already know, or at least knew, and I’m sure I could pick it back up quickly. However, I still don’t have a good Ruby on Rails project on the horizon, and so it would be just as much a pain to keep as it has been. I wouldn’t mind having a new Rails project to work on, but until one comes along, I’m going to leave it alone. I would consider working on my Ruby skills, but it’s hard to use Ruby for general purpose scripts at work because our servers all run Red Hat Enterprise Linux, which uses some old version of Ruby and is apparently impossible to upgrade. Ruby on Rails, I love you, but it’s a pass for 2011.

I am intrigued by big data projects. I’d love to dig into Hadoop or other tools that can be used to manipulate large data sets, but at the same time, I already work with some fairly big data sets at work and find that I can mine the data out of them that I need with SQL. In other words, while this area intrigues me, I don’t have any interesting problems to solve right now. Without that, it becomes tough to get motivated to really dig in and learn this stuff.

Another option is to learn a new (to me) programming language, like Clojure or Scala. Doing so would be great in terms of mental stimulation, but probably less great in terms of practical application. We’re not going to start using either of them at work this year, so I’d probably spend months learning one of them and then forget nearly everything I’d learned before I ever got to turn back to them for practical reasons.

Android or iOS are other options. Mobile development is huge right now, and I have a lot of ideas for apps I’d like to build. I could probably pick up Android development fairly easily since I already know Java. The only reason not to do it is that I am not a great user interface designer, and the best mobile apps are triumphs of interface design. I certainly have time to become a solid mobile developer, but without someone else’s design to implement, I think I’d just be unsatisfied with the results of my work. I may still try to pick up some mobile development skills, but they’re not going to be my primary focus this year.

The choice I settled on is JavaScript and Node.js. I already know JavaScript, but I wouldn’t consider myself a strong JavaScript programmer. I can generally solve the problems I’m asked to solve in JavaScript, but I find myself using a lot of libraries that there’s no way I could write on my own, and it’s easy to get lost in complex scripts. Not only is Node.js interesting in its own right, but learning about it gives a good chance to learn pure JavaScript as opposed to JavaScript simply as a way to manipulate Web pages. I’ve said before that HTML, CSS, JavaScript, and SQL are the most transferrable skills for Web developers. JavaScript is the weakest of those skills for me, and I need to get better at it. That’s the plan for 2011.

Apple open sources their Java implementation

First Apple deprecated their Java implementation. Now they’ve released it as open source:

Oracle and Apple today announced the OpenJDK project for Mac OS X. Apple will contribute most of the key components, tools and technology required for a Java SE 7 implementation on Mac OS X, including a 32-bit and 64-bit HotSpot-based Java virtual machine, class libraries, a networking stack and the foundation for a new graphical client. OpenJDK will make Apple’s Java technology available to open source developers so they can access and contribute to the effort.

The question that remains for me is whether Apple will continue to contribute code to OpenJDK. (Hopefully they will.)

This, combined with the fact that Apple is no longer going to ship Flash on OS X, seems to signal that Apple isn’t interested in being responsible for shipping updates for other people’s runtimes any more. You can certainly run Java or Flash on your Mac if you like, but the vendor is responsible for making sure that your runtime is patched and secure.

Marco Arment on the Mac App Store

Marco Arment makes the point that the Mac App Store is for developers who aren’t already developing Mac apps. This was the point I was trying to get at the other day when I said:

I can see a future where a sizable percentage of Mac users only use applications that they installed through the Mac App Store.

There are a lot of people who buy Macs, go to the Apple Store and take some classes, and never bother to install anything on their Mac that wasn’t there when they bought it. Maybe they buy a productivity application so they can do word processing, and that’s it.

The App Store is a way to deliver applications to those people, and like Marco, I think it’s going to be very successful in that regard. Anyway, go read his post, The Mac App Store isn’t for today’s Mac developers.

Your password should not be “password”

Today I got to look at the user table in an application with passwords stored as plain text. Out of around 7100 users, over 170 have the password “password.” Around 10 other users had heard that your passwords should contain letters and numbers, and thoughtfully chose the password “password1.” Needless to say, this application should probably store hashes of the passwords rather than storing them in plain text and also use some basic test of strength for the passwords that requires more than just lower case letters. What the experience left me with, though, was a burning desire to thwart users who specifically want to use the word “password” or any variation thereof as a password. I even want to create a special error message just for them, just to let them know that their combination of laziness and cleverness is not appreciated.

Here’s a regular expression that matches many, many variations on the word password:

/^p[a4@][s5][s5]w[o0]rd(\d*|\W*)$/i

You too can stamp out the blight of your users using “password” as their password.

Update: Accounted for people who substitute the letter “s” with the number “5.”

Update: Now “p@ssword” is not allowed, either.

Matt Raible on Java frameworks

Matt Raible takes on the argument that the age of Java Frameworks is over. One interesting aspect of the Java ecosystem is that there’s always some new thing out there that we’re supposed to be migrating to. And they’re nearly all just terrible in terms of productivity. Now apparently, we’re supposed to be looking at Java EE 6. I don’t even know what that is, but I’m sure it’s awful. In the meantime, I continue to plug along with Spring and Hibernate, using them in the simplest way I can.

Here’s a snippet from a post on migrating from Spring to Java EE:

Does it all make sense now? Do you know how to solve every problem? Probably not, but when it comes right down to it, using Java EE can be even simpler than using Spring, and take much less time. You just have to find the right guides and the right documentation (which is admittedly a severe sore-spot of Java EE; the documentation is still a work in progress, but is getting much better, save blogs like this one.) You have to turn to a vendor like JBoss, or IBM in order to get the use-case driven documentation you need, and they do have documentation, it’s just a matter of finding it.

Where do I sign up?

How Oracle is consolidating control of Java

Apache committer Jon Stevens says it’s time for the Apache Software Foundation to consider dumping its Java projects. Paul Querna says that developing open source software in Java is a trap because there will be no Java implementations other than the one offered by Oracle.

The piece of news that is triggering this reaction is that IBM has announced it is going to work with Oracle on the OpenJDK implementation and will no longer contribute to Apache Harmony, an effort to create an open source, compliant implementation of Java. In announcing that change, IBM said that they were abandoning Harmony because they believed that Oracle was never going to give them the test tools necessary to certify that Harmony was a fully compatible implementation of Java. This announcement, along with Oracle’s lawsuit against Google, makes it clear that Oracle is not going to support third party implementations of Java. They’re going to discourage them.

As a practical matter for people in the business of developing applications using Java, I don’t think this changes all that much. I use Java every day and I’ve never given any thought to Apache Harmony or the Java Community Process. If this move were to discourage open source activity on the Java platform, it will hurt developers down the road, but my guess is that nearly all open source Jave development is done using the official version of the JDK. That’s not likely to change anytime soon.

At one time, I thought a lot of Java developers would shift to Ruby on Rails. I no longer think that’s the case. We won’t see a mass migration to PHP at this point, either. I suppose we could see people moving to Scala and other languages, but they’re still niche players. So I think Java is going to continue to be what it already is. No longer the belle of the ball, but still the platform businesses use to build their Web applications.

Update: Just read Steven O’Grady’s blog post on this topic.

The cultural implications of forking

Anil Dash writes about the culture of forking in the open source world, and how the introduction of Git changed that culture. Before Git, forking could just as well have been called secession. After Git, forking is seen as a healthy form of participation.

What I find interesting about this is that Linus Torvalds didn’t set out to change the culture of open source software when he created Git. He was trying to efficiently manage the work being done on the Linux kernel.

Linux kernel development is (or at least was) handled differently than most other large projects. Linus approves all of the code changes that go into the official kernel releases. Below him, there are a number of lieutenants who each have their own branches and their own approval process. In order for your code to make it into the official kernel, your change has to be accepted into one of those other branches. Below those, there can be any number of other branches as well.

In order to support this style of work, a source code management system was needed that would make it easy to push changes in all directions. The lower level branches need to easily pick up all of the changes that are accepted into the official branch, and people at the lower levels needed a way to push their changes up the chain to whatever branch was used to create their branch. Furthermore, nobody wanted to be dependent on a single centralized server that would host all of this work.

As it turns out, Git satisfied a lot of other people’s needs as well, but originally it was created to scratch a very specific itch.

Older posts Newer posts

© 2024 rc3.org

Theme by Anders NorenUp ↑