views:

99

answers:

2

I am very familiar with JavaScript and am now having a play with Flex for the first time. Obviously it's a strange felling as JavaScript and ActionScript are as they would say here in Southeast Asia "same same but different". The one thing that's getting to me (as with all static languages) is the verbosity. Are there any shorthand tricks that can slim down the following common code:

 package com.mate.extensions {

  public class HTTPResponse
  {

   public var data:String;  
   public var responseURL:String;
   public var responseHeaders:Array:
   public var status:Number;

   public function HTTPResponse(data:String, responseURL:String, responseHeaders:Array, status:Number):void {
    this.data = data;
    this.responseURL = responseURL;
    this.responseHeaders = responseHeaders;
    this.status = status;
   }
  }

 }
+3  A: 

I guess it's a matter of what you're used to; I came to AS3 from Java, and to me, that code looks perfectly reasonable. :)

Honestly, I don't think you can trim this down substantially without taking a big hit in either readability or functionality. (Of course, now that I've said that, I look forward to somebody smarter than me proving me wrong.) In fact, it may actually be too terse; making your internal fields publicly accessible is generally considered bad form and an invitation to headaches down the road. Though one of the lovely things about AS3 is that because of how getters and setters are handled, you can switch from public fields to accessor-controlled private fields without needing to make any changes to code that uses this object.

BlairHippo
+1  A: 

If your concern is verbosity versus coding standards, you could throw the whole HTTPResponse class away and replace it with an Object.

var httpResponse:Object = { data: data, responseURL: responseURL, responseHeaders: responseHeaders, status: status };

But in that case you would miss the compile time types checking and code reusability.

The great thing with ActionScript is that it's same same & different.

Peiniau