InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Adobe Flex Coding Convention Document Triggered Discussions

Posted by Moxie Zhang on May 08, 2008

Sections
Development
Topics
Java ,
Rich Internet Apps
Tags
Flex

On April 18, 2008, Adobe released its Flex SDK coding conventions and best practices. Adobe's Flex Team explained that the new conventions, “. . . lay out the coding standards for writing open-source Flex framework components in ActionScript 3 (AS3). Adhering to these standards makes the source code look consistent, well-organized, and professional.”

Nevertheless, the release has triggered debate among developers in the Flex RIA community. For example, Keith Petters, doesn't like what he sees as a “flex fixation” expressed in the code convention document. He comments, “The one thing that bugs me is that this is termed a Flex document. There is virtually nothing Flex-specific in there. It's all straight AS3 coding conventions. I wish Adobe would get off its Flex fixation and acknowledge the existence of AS3 as a stand-alone language.” Igor Costa responds, “You're right, Keith, when you say that; but, the document as well is only for Flex 4 SDK code guide for ActionScript classes placed on the SDK as well, not the language at all.”

Perhaps, the most active discussions relate to the detailed suggestions on how code should be formatted. As Tom Lee at TL on PL said, “I think it would have been useful for them to offer some sort of rationale behind the recommendations, not just ‘do this, not that' mandates.” For example, Lee takes particular exception with the suggestion to “use Array literals rather than new Array().” He comments:

Isn't "new Array()" more consistent with the way every other kind of object is instantiated? "[]" is a shorthand syntax. I have found shorthand generally to be avoided, because it requires a deeper familiarity with a language than a generalist programmer would possess. I raise the same objection to the recommendations for using Object literals, RegExp literals, and so forth. Consistency is key.

Igor Costa also questions whether the coding conventions and best practices contain some unnecessary dictates. For example, he asks: “Don't put any spaces before or after the left bracket or before the right bracket. Do this: a[0] Not this: a[ 0 ]. Blank spaces are really necessary to worry about it?”

At the same time, Tony Fendall believes consistency and good habits count. He says:

Personally, I agree with the suggested conventions. Yes, you can argue that white spaces are not directly important to the function of the code, but working in code that looks consistent across all classes and functions is much nicer than code where each contributor has his or her own style. The benefits make the task of building a few small habits well worth the effort.

Another discussion focuses on the use of integer and unsigned integer. The coding convention document suggests using int for integers, even if they can't be negative. Use uint only for RGB colors, bit masks, and other non-numeric values. “What's the point in having a uint if you're only going to use it for things other than unsigned integers?” Keith Petters asks.

Pixel Burner observes, “I've noticed that a lot of coders use uint religiously. However, I've read a few articles that suggest that uint can be 200-400 percent slower than the int data type. So, I pretty much never use uint.” Burner also referred to a recent article in Gskinner that specifically talked about the use uint. The article concluded after a coding test:

Avoid uint, unless you have a really good reason for forcing the type. Use ints where they make sense, but don't agonize over the performance implications of int versus Number. Default to Number whenever you aren't sure. Most importantly, don't take things for granted - test and benchmark wherever you can - you might be surprised by the results!

Nevertheless, Sho Kuwamoto of Adobe, strongly suggests avoiding ints in ActionScript, using it only:

    1. When you want to save memory. (although this should impact you only when you have tons of numbers to store)
    2. When you want to force an integral value (e.g., var i: int = j / 2)
    3. To reduce the chance of bugs as you map integral values from client side to server side. (e.g., int fields in value objects).

From all the discussion, one thing is certain. Coding convention involves a whole lot more than just format and maintainability.

No comments

Watch Thread Reply

Educational Content

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.

Beauty Is in the Eye of the Beholder

Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.

Architecting Visa for Massive Scale and Continuous Innovation

John Davies examines Visa’s architecture and shows how enterprises have architected complex integrations incorporating Hadoop, memcached, Ruby on Rails, and others to deliver innovative solutions.

Max Protect: Scalability and Caching at ESPN.com

Sean Comerford unveils ESPN.com’s architecture, what components are used and why, and the current changes the website goes through.

The Seven Deadly Sins of Enterprise Agile Adoption

Are there repeated patterns of failure on Enterprise Agile Enablement efforts? Sanjiv and Arlen discuss Seven Deadly Sins to avoid when adopting Agile in an enterprise.

Questions for an Enterprise Architect

Erik Dörnenburg answers: What is Enterprise and Evolutionary Architecture?, discussing 4 issues: Turning strategy into execution, Ensuring conformance, Where do the architects sit? Buying or building?

Wrap Your SQL Head Around Riak MapReduce

Sean Cribbs explains what Map-Reduce and Riak are, why and how to use Map-Reduce with Riak, and how to convert SQL queries into their Map-Reduce equivalents.