password
username
Sponsored by CakeMail, an email marketing software.
Newsletter preview

Tuesday, March 18, 2008 

Build rich, interactive applications with Adobe Flex 3

Adobe® Flex® 3 is a highly productive, open source framework for building expressive web applications that deploy consistently on major browsers, desktops, and operating systems. Learn more about the no cost Flex SDK and the Adobe Flex Builder™ software.
Download Adobe Flex Builder
 Perspective

Hot off
the Press!

jQuery in Action
New guide to the jQuery Library for client-side JavaScript
Laszlo in Action
The first developer's guide to OpenLaszlo
Flexible Rails
Build next-generation RIAs

Special!
Save 25% Enter DZJAN25 at checkout

www.manning.com


Be sure and
check out a
No Fluff Just Stuff
Java conference
coming your way!

4/04-4/06 Boston
4/04-4/06 Omaha
4/18-4/20 Chiacgo
4/18-4/20 Seattle
4/25-4/27 Reston
5/02-05/04 Denver

 
 A Developer's Perspective
 Next section
Alex Lucas is a Java and .NET enthusiast currently working as a Web Developer in Tucson, Arizona. He also maintains the callingshotgun.net website, home of his programming blog and personal projects.

Lines Of Code - Dispelling The Myths
By Alexander Lucas

You see posts related to Lines Of Code (LOC) everywhere on programming blogs. People discussing it as a metric of project size, or of programmer productivity, often drawing conclusions in absolutist tones such as “fewer lines of code means less bugs”. I’m writing today to dispute the idea that anything related to LOC is absolute. And I’m going to do it one myth at a time.

LOC As A Metric of Accomplishment or Project Size

This one is old, and most experienced programmers now officially reject it outright. But still, I feel it worth repeating: The number of LOC you write in a single day is worthless as a metric of what you accomplished that day. After all- If someone wrote a 1000 line class in a single day, and you wrote the same class in 500 lines (and maybe tossed in a little extra functionality while you were at it), who was more productive?

As a metric of project size, it makes a little more sense, but just barely- The Wikipedia article on LOC mentions that “Many useful comparisons involve only the order of magnitude of lines of code in a project.” That at least makes a little sense. One can reasonably assume that the same set of programmers, using the same language, will be able to accomplish more with 10000 lines of code than with 1000.

Editors' note: The lines below may be wrapped and on more than the lines stated due to our template.

Ambiguity: Too Many Ways To Count

The next issue is this: How do you COUNT lines of code? That same Wikipedia article linked above has an interesting example:

for (i=0; i < 100; ++i) printf("hello"); 
/* How many lines of code is this? */

How many lines is that? One for the line? Two for logical seperation of forloop and print statement? What if you wrap the line in curly braces, one on each line, and move the comment to it’s own line, so it looks more like

for (i=0; i < 100; ++i)
{
/* How many lines of code is this? */
printf("hello");
}

Did you see that? I just took one line of code, and turned it into 5! Things get so much more confusing than stylistic issues like this, though. What about libraries? What about frameworks? Jeff Atwood wrote a post a couple of months ago wherein he mentioned that the original version of Basecamp had been written in only 600 lines of code. Given that Basecamp was written using Ruby on Rails, which handles all sorts of crazy things for you, I think the more honest metric would have to be the 600 lines of basecamp, plus however large the RoR framework is, plus the code RoR generated for them when they started the project. Money says it’s more than 600 lines.

I’ll give you another example. Currently, the amount of code I’ve written for Migratr is 5000 lines and change. However, Migratr uses FlickrNet, a popular .NET library for interacting with the Flickr API. FlickrNet, if you download the source, is more than 12,371 lines of code (according to the unix util “wc”). I’ve also incorporated a few other libraries, all of which are linked in Migratr’s “about” page. Why? Because I didn’t want to write those 12,000 lines. Someone already had, and they did a fantastic job of it, and I didn’t see any point in re-inventing the wheel. So the total code involved in Migratr is, at this point, more than 17,000 lines. I’ve written 5,000 of them, and I’m the sole developer of Migratr. But I wouldn’t dream of saying “I built this application that interacts with a whole slew of online photo services and migrates all your photos and does all this neat stuff, and it was only 5,000 lines!” No. MY contribution was 5000 lines, but Migratr depends on a lot more than that.

The point being, where do you draw the line? Is Migratr a 5000+ LOC project? or 17,000+? Do you only count LOC if you have access to the source of the library you’re using? Do you only count the code written for your specific project? Could I export Migratr’s backend as a library and let someone write

public void migrate(String filepath)
{
ImportFromSource(Services.Flickr, filepath);
exportToDestination(Services.SmugMug, filepath);
}

Did you see that? My whole project was just replaced! Some twerp in a garage somewhere just re-wrote Migratr in 5 lines of code! It doesn’t matter that it depended on my 5,000 line library, which depends on (among others) 12,000 lines of the Flickrnet library. You only saw 5 lines. It was only 5 lines.
But clearly, since 5,000 is more than 5, I can at least say that I was more productive.

The relationship between line count and bug count only goes so far

The idea that “Less lines of code mean less bugs” is some sort of universal absolute is the biggest of all the LOC myths. In a desperate effort to nullify your “oh snap, time for a flamewar” reflex, I’m going to add a couple of disclaimers before I get into this. Any reference I make to a programming language is not an attack on that programming language, just an attack on the abuse of that language. Also, I realize that reducing the amount of code required for a specific task can help reduce the bug count, but only so far. I’m saying there’s a limit to this. Here’s the line I want to draw for you.

Reducing the code involved in a task will only help reduce the bug count IF THE PROCESS MAKES THE CODE MORE READABLE. Past that, you’re probably creating lines of code that do more than one thing per line, and thus increasing the number of bugs possible per line of code.

Perl programmers are especially frightening in this regard. I really love PERL and use it instead of shell scripting languages such as BASH whenever possible, but there’s something in the PERL culture that demands it’s programmers to try and do something in the fewest number of characters possible. There’s even a name for this as a sport- It’s referred to as “Perl Golf”.

Really quick, can you tell me what this is?

-pl s!.!y$IVCXL426(-:$XLMCDIVX$dfor$$_.=5x$&*8%29628;
$$$_=$_!egfor-4e3..y/iul-}/-$+ /%s''$';*_=eval

I’ll give you a hint- It’s not a cat walking across my keyboard. If that was your first guess, though, we’re at least on the same page. This was the winning entry in a game of Perl Golf: The problem was to write a Roman Numeral Calculator in the fewest characters possible. Submissions can be found here. Now, this is an amazing piece of code. The person who wrote it is clearly very skilled. The fact that Perl makes code like that possible is pretty impressive. The problem here is that people write code like this outside of PERL golf, and think to themselves, “it’s only one line, so it must have fewer bugs than a 50 line solution”. Really? Because if I had to debug one, I’d have definitely gone with the 50 line solution. And don’t tell me that that one line of code worked on the first, second, or 5th try. The 50+ line solutions might have, but not that catwalk.
Writing unmaintanable code does not reduce the bug count for a project. A friend of mine coined a term for code like that- “Write-Only Code”- a takeoff on the permissions you can set with chmod. Think about it: Readable, writeable, and executable. Shouldn’t code be all three?

Another quick example:

(0/:l)(_+_)

The first time I saw this snippet, I thought someone was, via emoticons, trying to re-enact the facial expression one wore when seeing “Goatse” for the first time. It’s not actually a story told by emoticon. It’s a piece of scala code that sums the elements in a list. And I just don’t see it as having been easier to write than a forloop. It’s definitely not as maintainable. This piece of code, actually, prompted a conversation with a friend about holding a “code or emoticon” contest, but we really couldn’t come up with any serious contenders to this one. Maybe some Perl Golfers could throw their hat in the ring?

I want to state too, that for this section, I’m well aware that I didn’t provide buggy one-liners. I provided working one-liners. This is because I was trying to emphasize, the point isn’t if it works or not. The point is if you can tell by looking at it what it should do. If you can’t, it’s unmaintainable. If it’s unmaintanable, then even if it works the first time, it’ll produce a slew of bugs as soon as anyone tries to modify it.

So, in essence - stop paying attention to Lines of Code. They’re impossible to count in any useful way. They’re a crappy metric of project size or personal accomplishment. And they don’t control how many bugs your code has. You do.

Until next time,
Alexander Lucas
http://www.callingshotgun.net

 
 DZ Top Links
 
 DZone Top Links
 Next section
 Back to top
most clicked this week from dzone.com

dzone

Most-clicked links this week

 
 Popular at JL
 
 Popular at Javalobby
 Next section
 Back to top
A recap of some of the most popular and active Javalobby.org discussions this week.

Microsoft wants to improve Eclipse

Seems Microsoft is trying to show a kinder, gentler side to Open Source and Java development communities. In the past they made overtures to improve PHP on Windows server. They also sat down and collaborated with JBoss and now they plan on supporting Eclipse.Microsoft plans on assisting the Eclipse SWT team to enable Java developers to create applications that look and feel like Windows Vista. In addition, they plan on supporting Windows Presentation Foundation (WPF) application development with Eclipse SWT.

SailFin: When Java EE Met SIP

SIP (Session Initiation Protocol) technology is behind many of today's popular services, such as VoIP, instant messaging, and web conferencing. Underpinning SIP is the SIP Servlet, initially defined in JSR-116 and, since then, updated in JSR-289. The latter defines a standard application programming model to mix SIP Servlets and Java EE components. The open source project SailFin adds a SIP Servlet technology extension to the GlassFish Application Server. Here we interview the main developers involved in this project.

What Would You Add to Eclipse 4.0?

Eclipse 4.0 was covered last Wednesday at an interesting presentation during EclipseCon. The core principles behind Eclipse 4.0 will be web enablement, and decreasing complexity. However, it will be a lot more than just bringing RCP to the web, which the RAP project already does to a certain degree.

Hudson's so Groovy

Having used Cruise Control for almost 4 years, when I started looking at Hudson last week, I was impressed seeing how easy it was to configure and get it up and running in just a few minutes. It also has several plugins available, and if you don't find one you can quickly write one as well.

The new Maven/Eclipse integration - Part 1

Creating a new Maven project in EclipseA new and greatly improved version of the Maven 2 Eclipse plugin has just come out. In a series of short articles, I'll be looking at what's new, and how to get the most out of this new version. In this first installment, we will look at how to create a new Maven project from within Eclipse.
 White Papers & Announcements
 
 Product Announcements
 Next section
 Back to top
Product and service announcements for Java developers.

JIDE Software releases JIDE Icon Set for Java/Swing developers

March 20, 2008 We are pleased to announce JIDE Icon Set –beautiful icons for your Java/Swing applications. JIDE Icon Set

Wicket 1.2.7: the final maintenance release

The Wicket team announces the last maintenance release of Wicket 1.2: Wicket 1.2.7. This release marks the end-of-life for the non-Apache product branch. This release fixes the remaining issues for Wicket 1.2. For future support we ask you to upgrade to Apache Wicket 1.3 or newer. This release of the Wicket project is not endorsed or approved by the Apache Software Foundation. The Apache Software Foundation is in no way affiliated with this release.

Chronos 0.2.1 beta: Database Desktop Client for Oracle and Microsoft SQL Server

Chronos is a free cross platform database tool. It currently supports Oracle and MSSQL (Sybase) and includes highlighting of Primary and Foreign keys as a major new feature in this release.

The Summer of Code and 'Open Source' Conferences

2008 is looking like a good year for open source aficionados. Sun today announced the agenda for its second annual CommunityOne event, which will showcase a range of open source Java projects such as Netbeans, Glassfish, OpenJDK and Web 2.0 topics. Google, on the other hand has provided details for its 2008 'Summer of Code' program that offers student developers stipends to write code for various open source projects.

Karora Cooee 1.1: Improved Compatibility Across All Major Browsers

The Karora group (http://www.karora.org) has released version 1.1 of their Java-based AJAX framework. This release includes new components and several bug fixes aimed at improving browser compatibility and stability.
 Your Account
 
 Your Account
 Next section
 Back to top
Manage your account info for this and other Javalobby publications.
Manage your Javalobby membership details

Click on the following links to:


 Contact Info
 Next section
 Back to top
Here's how to reach us, we love to hear from you.
Email us
Send news items to editor@javalobby.org
Send questions, complaints, or suggestions to feedback@javalobby.org
Send advertising inquiries to advertise@javalobby.org
 
Call us
Our number is (919) 678-0300. We'd love to hear from you!

 Legal
 Back to top
The fine print we'd rather avoid completely.
Feel free to redistribute this newsletter in part or in full to your friends.

Javalobby News is a service mark of DZone, Inc.
Copyright ©2001-2008 DZone, Inc.

Thank you for your continued support of Javalobby and DZone. If you prefer not to receive the Javalobby weekly newsletter, send an e-mail to ***-jlnews@javalobby.org and please ensure the actual email address to be removed is present.
DZone, Inc., 113 Legault Drive, Cary NC 27513 USA