山水
May 5th, 2010看山是山,看水是水——
知道的少,从这山到那水走这条道就可以了,只不过这道真难走
看山不是山,看水不是水——
知道的多了,道路数不胜数,不知道从这山到那水该走哪一条道
看山还是山,看水还是水,但是山更绿,水更清——
知道的非常多了,晓得从这山到那水这条道更好走一些
Programming & Life
看山是山,看水是水——
知道的少,从这山到那水走这条道就可以了,只不过这道真难走
看山不是山,看水不是水——
知道的多了,道路数不胜数,不知道从这山到那水该走哪一条道
看山还是山,看水还是水,但是山更绿,水更清——
知道的非常多了,晓得从这山到那水这条道更好走一些
Description:
I have done an experiment to test the performance of data type conversions in actionscript 3. Create a new flex 4 based application with the code below, then compile and run it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:controls="com.wds.framework.controls.*" initialize="application1_initializeHandler(event)"> <fx:Script> <![CDATA[ import mx.containers.Canvas; import mx.core.Container; import mx.core.FlexSprite; import mx.core.IContainer; import mx.core.IUIComponent; import mx.core.UIComponent; import mx.events.FlexEvent; import mx.utils.ObjectProxy; protected function application1_initializeHandler(event:FlexEvent):void { var n:int = 1000000; var i:int = 0; var timer:int = 0; var obj:*; trace("--------------------------"); //////////////////////////////////////////////////// trace("Basic Types"); trace("-----------"); obj = {}; trace("obj = {}"); timer = getTimer(); for(i = 0;i < n;i++) { Object(obj); } trace("Object(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as Object; } trace("obj as Object",getTimer() - timer); trace(); ////////////////////////// obj = "str"; trace("obj = \"str\""); timer = getTimer(); for(i = 0;i < n;i++) { String(obj); } trace("String(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as String; } trace("obj as String",getTimer() - timer); trace(); ////////////////////////// obj = 0.5; trace("obj = 0.5"); timer = getTimer(); for(i = 0;i < n;i++) { Number(obj); } trace("Number(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as Number; } trace("obj as Number",getTimer() - timer); trace(); ////////////////////////// obj = -12; trace("obj = -12"); timer = getTimer(); for(i = 0;i < n;i++) { int(obj); } trace("int(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as int; } trace("obj as int",getTimer() - timer); trace(); ////////////////////////// obj = 12; trace("obj = 12"); timer = getTimer(); for(i = 0;i < n;i++) { uint(obj); } trace("uint(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as uint; } trace("obj as uint",getTimer() - timer); trace("-----------"); //////////////////////////////////////////////////// trace("Dynamic Classes"); trace("-----------"); obj = new Array(); trace("obj = new Array()"); timer = getTimer(); for(i = 0;i < n;i++) { Array(obj); } trace("Array(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as Array; } trace("obj as Array",getTimer() - timer); trace(); ////////////////////////// obj = new ObjectProxy(); trace("obj = new ObjectProxy()"); timer = getTimer(); for(i = 0;i < n;i++) { ObjectProxy(obj); } trace("ObjectProxy(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as ObjectProxy; } trace("obj as ObjectProxy",getTimer() - timer); trace(); ////////////////////////// obj = new MyDynamicClass(); trace("obj = new MyDynamicClass()"); timer = getTimer(); for(i = 0;i < n;i++) { MyDynamicClass(obj); } trace("MyDynamicClass(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as MyDynamicClass; } trace("obj as MyDynamicClass",getTimer() - timer); trace(); ////////////////////////// obj = new MyProxyClass(); trace("obj = new MyProxyClass()"); timer = getTimer(); for(i = 0;i < n;i++) { MyProxyClass(obj); } trace("MyProxyClass(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as MyProxyClass; } trace("obj as MyProxyClass",getTimer() - timer); trace("-----------"); //////////////////////////////////////////////////// trace("Typed Classes"); trace("-----------"); obj = new Canvas(); trace("obj = new Canvas()"); timer = getTimer(); for(i = 0;i < n;i++) { Canvas(obj); } trace("Canvas(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as Canvas; } trace("obj as Canvas",getTimer() - timer); trace(); ////////////////////////// obj = new Canvas(); trace("obj = new Canvas()"); timer = getTimer(); for(i = 0;i < n;i++) { Container(obj); } trace("Container(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as Container; } trace("obj as Container",getTimer() - timer); trace(); ////////////////////////// obj = new Canvas(); trace("obj = new Canvas()"); timer = getTimer(); for(i = 0;i < n;i++) { UIComponent(obj); } trace("UIComponent(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as UIComponent; } trace("obj as UIComponent",getTimer() - timer); trace(); ////////////////////////// obj = new Canvas(); trace("obj = new Canvas()"); timer = getTimer(); for(i = 0;i < n;i++) { Sprite(obj); } trace("Sprite(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as Sprite; } trace("obj as Sprite",getTimer() - timer); trace(); ////////////////////////// obj = new Canvas(); trace("obj = new Canvas()"); timer = getTimer(); for(i = 0;i < n;i++) { DisplayObject(obj); } trace("DisplayObject(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as DisplayObject; } trace("obj as DisplayObject",getTimer() - timer); trace(); ////////////////////////// obj = new Canvas(); trace("obj = new Canvas()"); timer = getTimer(); for(i = 0;i < n;i++) { EventDispatcher(obj); } trace("EventDispatcher(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as EventDispatcher; } trace("obj as EventDispatcher",getTimer() - timer); trace(); ////////////////////////// obj = new Canvas(); trace("obj = new Canvas()"); timer = getTimer(); for(i = 0;i < n;i++) { Object(obj); } trace("Object(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as Object; } trace("obj as Object",getTimer() - timer); trace(); ////////////////////////// obj = new Container(); trace("obj = new Container()"); timer = getTimer(); for(i = 0;i < n;i++) { Container(obj); } trace("Container(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as Container; } trace("obj as Container",getTimer() - timer); trace(); ////////////////////////// obj = new UIComponent(); trace("obj = new UIComponent()"); timer = getTimer(); for(i = 0;i < n;i++) { UIComponent(obj); } trace("UIComponent(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as UIComponent; } trace("obj as UIComponent",getTimer() - timer); trace(); ////////////////////////// obj = new FlexSprite(); trace("obj = new FlexSprite()"); timer = getTimer(); for(i = 0;i < n;i++) { FlexSprite(obj); } trace("FlexSprite(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as FlexSprite; } trace("obj as FlexSprite",getTimer() - timer); trace(); ////////////////////////// obj = new Sprite(); trace("obj = new Sprite()"); timer = getTimer(); for(i = 0;i < n;i++) { Sprite(obj); } trace("Sprite(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as Sprite; } trace("obj as Sprite",getTimer() - timer); trace("-----------"); //////////////////////////////////////////////////// trace("Interfaces"); trace("-----------"); ////////////////////////// obj = new Canvas(); trace("obj = new Canvas()"); timer = getTimer(); for(i = 0;i < n;i++) { IContainer(obj); } trace("IContainer(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as IContainer; } trace("obj as IContainer",getTimer() - timer); trace(); ////////////////////////// obj = new Canvas(); trace("obj = new Canvas()"); timer = getTimer(); for(i = 0;i < n;i++) { IUIComponent(obj); } trace("IUIComponent(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as IUIComponent; } trace("obj as IUIComponent",getTimer() - timer); trace(); ////////////////////////// obj = new Canvas(); trace("obj = new Canvas()"); timer = getTimer(); for(i = 0;i < n;i++) { IEventDispatcher(obj); } trace("IEventDispatcher(obj)",getTimer() - timer); timer = getTimer(); for(i = 0;i < n;i++) { obj as IEventDispatcher; } trace("obj as IEventDispatcher",getTimer() - timer); trace(); } ]]> </fx:Script> </s:Application> |
RESULTS:
--------------------------
Basic Types
-----------
obj = {}
Object(obj) 150
obj as Object 109
obj = "str"
String(obj) 110
obj as String 110
obj = 0.5
Number(obj) 65
obj as Number 107
obj = -12
int(obj) 67
obj as int 110
obj = 12
uint(obj) 67
obj as uint 108
-----------
Dynamic Classes
-----------
obj = new Array()
Array(obj) 1563
obj as Array 113
obj = new ObjectProxy()
ObjectProxy(obj) 126
obj as ObjectProxy 134
obj = new MyDynamicClass()
MyDynamicClass(obj) 128
obj as MyDynamicClass 138
obj = new MyProxyClass()
MyProxyClass(obj) 133
obj as MyProxyClass 135
-----------
Typed Classes
-----------
obj = new Canvas()
Canvas(obj) 131
obj as Canvas 132
obj = new Canvas()
Container(obj) 136
obj as Container 144
obj = new Canvas()
UIComponent(obj) 141
obj as UIComponent 148
obj = new Canvas()
Sprite(obj) 176
obj as Sprite 124
obj = new Canvas()
DisplayObject(obj) 167
obj as DisplayObject 122
obj = new Canvas()
EventDispatcher(obj) 170
obj as EventDispatcher 125
obj = new Canvas()
Object(obj) 150
obj as Object 108
obj = new Container()
Container(obj) 132
obj as Container 138
obj = new UIComponent()
UIComponent(obj) 134
obj as UIComponent 138
obj = new FlexSprite()
FlexSprite(obj) 133
obj as FlexSprite 134
obj = new Sprite()
Sprite(obj) 170
obj as Sprite 120
-----------
Interfaces
-----------
obj = new Canvas()
IContainer(obj) 136
obj as IContainer 147
obj = new Canvas()
IUIComponent(obj) 139
obj as IUIComponent 148
obj = new Canvas()
IEventDispatcher(obj) 120
obj as IEventDispatcher 121
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | //////////////////////////////////////////////////////////////////////////////// // DateParser.as // // An as3 implementation of the java SimpleDateFormat like class based on Flex // SDK which can be used to parse a String with specified format to as3 Date // object. // // This code is a modification version of Daniel Wabyick's as2 // SimpleDateFormatter(http://osflash.org/simpledateformatter) which // is directly adapted from Matt Kruse's Javascript class implementation. // // @author edison.guo(http://www.hydra1983.com) // @author Daniel Wabyick(http://www.fluid.com) // @author Matt Kruse (http://www.JavascriptToolbox.com) // The following notice is maintained from Matt Kruse's // original Javascript code. // // NOTICE: You may use this code for any purpose, commercial or // private, without any further permission from the author. You may // remove this notice from your final code if you wish, however it is // appreciated by the author if at least my web site address is kept. // // USAGE // ---------------------------------------------------------------------- // These functions use the same pattern letters used by the DateFormatter // class provided by Flex SDK. You can find the detailed description of // these letter in the Adobe Flex Language Reference. // Examples: // var dateString:String = "9/10/2008 GMT+0800 08:30:41"; // var parser:DateParser = new DateParser(); // parser.formatString = "M/D/Y HH:NN:SS"; // trace(parser.parse(dateString)); // //Wed Sep 10 08:30:41 GMT+0800 2008 // // ---------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// package { import mx.formatters.Formatter; import mx.utils.StringUtil; public class DateParser { private static const VALID_PATTERN_CHARS:String = "Y,M,D,A,E,H,J,K,L,N,S,Q"; public var error:String; private var _formatString:String = "YYYY-MM-DD HH:NN"; public function get formatString():String { return _formatString; } public function set formatString(value:String):void { if(value) _formatString = value; } private var _defaultInvalidFormatError:String = Formatter.defaultInvalidFormatError; public function get defaultInvalidFormatError():String { return _defaultInvalidFormatError; } public function set defaultInvalidFormatError(value:String):void { _defaultInvalidFormatError = value; } private var _defaultInvalidValueError:String = Formatter.defaultInvalidValueError; public function get defaultInvalidValueError():String { return _defaultInvalidValueError; } public function set defaultInvalidValueError(value:String):void { _defaultInvalidValueError = value; } public function parse( value:Object):Date { if (error) error = null; if(!(value is String)) { error = defaultInvalidValueError; return null; } if(!value || value == "") { error = defaultInvalidValueError; return null; } var timezoneRegEx:RegExp = /(GMT|UTC)((\+|-)\d\d\d\d(\s)?)?/ig; value = StringUtil.trim(String(value).replace(timezoneRegEx, "")); var letter:String; var nTokens:int = 0; var tokens:String = ""; var n:int = formatString.length; for (var i:int = 0; i < n; i++) { letter = formatString.charAt(i); if (VALID_PATTERN_CHARS.indexOf(letter) != -1 && letter != ",") { nTokens++; if (tokens.indexOf(letter) == -1) { tokens += letter; } else { if (letter != formatString.charAt(Math.max(i - 1, 0))) { error = defaultInvalidFormatError; return null; } } } } if (nTokens < 1) { error = defaultInvalidFormatError; return null; } var dataParser:DateStringParser = new DateStringParser( formatString, VALID_PATTERN_CHARS); return dataParser.parseValue(value); } } } import mx.formatters.DateBase; class DateStringParser { private static var digits:String = "1234567890"; private static var dayNames:Array = DateBase.dayNamesLong.concat(DateBase.dayNamesShort); private static var monthNames:Array = DateBase.monthNamesLong.concat(DateBase.monthNamesShort); public function DateStringParser(format:String, tokens:String) { super(); this.format = format; this.tokens = tokens; } private var format:String; private var tokens:String; public function parseValue(value:Object):Date { var valueString:String = String(value); var i_value:int = 0; var i_format:int = 0; var char_token:String = ""; var token:String = ""; var start:int = 0; var end:int = 0; var now:Date = new Date(); var years:Object = now.getFullYear(); var months:Object = now.getMonth() + 1; var dates:Object = now.getDate(); var days:Object = now.getDay(); var hours:Object = now.getHours(); var minutes:Object = now.getMinutes(); var seconds:Object = now.getSeconds(); var milliseconds:Object = now.getMilliseconds(); var ampm:String = ""; var max:int = 0; var min:int = 0; while(i_format < format.length) { char_token = format.charAt(i_format); if(tokens.indexOf(char_token) > -1) { start = format.indexOf(char_token); end = format.lastIndexOf(char_token); end = end >= 0 ? end + 1 : start + 1; token = format.substring(start,end); i_format = end; if(token == "YYYY" || token == "YY" || token == "Y") { if(token == "YYYY") {max = min = 4;} if(token == "YY") {max = min = 2;} if(token == "Y"){max = 4;min = 2;} years = getIntegerValue(valueString,i_value,min,max); if(isNaN(Number(years))) return null; i_value += String(years).length; years = Number(years); } else if(token == "MM" || token == "M") { months = getIntegerValue(valueString,i_value,token.length,2); if(isNaN(Number(months)) || months < 1 || months > 12) return null; i_value += String(months).length; months = Number(months); } else if(token == "MMMM" || token == "MMM") { var monthName:String = getMonthName(valueString,i_value); if(!monthName || monthName.length == 0) return null; months = getMonths(monthName); if(isNaN(Number(months)) || months < 1 || months > 12) return null; i_value += monthName.length; months = Number(months); } else if(token == "EE" || token == "E") { days = getIntegerValue(valueString,i_value,token.length,2); if(isNaN(Number(days)) || days < 1 || days > 7) return null; i_value += String(days).length; days = Number(days); } else if(token == "EEEE" || token == "EEE") { var dayName:String = getDayName(valueString,i_value); if(!dayName || dayName.length == 0) return null; days = getDays(dayName); if(isNaN(Number(days)) || days < 1 || days > 7) return null; i_value += dayName.length; days = Number(days); } else if(token == "DD" || token == "D") { dates = getIntegerValue(valueString,i_value,token.length,2); if(isNaN(Number(dates)) || dates < 1 || dates > 31) return null; i_value += String(dates).length; dates = Number(dates); } else if(token == "AA" || token == "A") { ampm = valueString.substr(i_value,2).toUpperCase(); if(ampm != "AM" && ampm != "PM") return null; i_value += 2; } else if(token == "JJ" || token == "J") { hours = getIntegerValue(valueString,i_value,token.length,2); if(isNaN(Number(hours)) || hours < 0 || hours > 23) return null; i_value += String(hours).length; hours = Number(hours); } else if(token == "HH" || token == "H") { hours = getIntegerValue(valueString,i_value,token.length,2); if(isNaN(Number(hours)) || hours < 1 || hours > 24) return null; i_value += String(hours).length; hours = Number(hours); } else if(token == "KK" || token == "K") { hours = getIntegerValue(valueString,i_value,token.length,2); if(isNaN(Number(hours)) || hours < 0 || hours > 11) return null; i_value += String(hours).length; hours = Number(hours); } else if(token == "LL" || token == "L") { hours = getIntegerValue(valueString,i_value,token.length,2); if(isNaN(Number(hours)) || hours < 1 || hours > 12) return null; i_value += String(hours).length; hours = Number(hours); } else if(token == "NN" || token == "N") { minutes = getIntegerValue(valueString,i_value,token.length,2); if(isNaN(Number(minutes)) || minutes < 0 || minutes > 59) return null; i_value += String(minutes).length; minutes = Number(minutes); } else if(token == "SS" || token == "S") { seconds = getIntegerValue(valueString,i_value,token.length,2); if(isNaN(Number(seconds)) || seconds < 0 || seconds > 59) return null; i_value += String(seconds).length; seconds = Number(seconds); } else if(token == "QQQ" || token == "QQ" || token == "Q") { milliseconds = getIntegerValue(valueString,i_value,token.length,2); if(isNaN(Number(milliseconds)) || milliseconds < 0 || milliseconds > 999) return null; i_value += String(milliseconds).length; milliseconds = Number(milliseconds); } } else { i_format ++; i_value ++; } } if (i_value != valueString.length) { return null; } if (months == 2) { var isLeapYear:Boolean = isLeapYear(Number(years)); if(isLeapYear && dates > 28) return null; if(!isLeapYear && dates > 29) return null; } if (((months == 4)||(months == 6)||(months == 9)||(months == 11)) && dates > 30) return null; if(hours < 12 && ampm == "PM") {hours = (Number(hours)) + 12;} else if(hours > 11 && ampm == "AM") {hours = (Number(hours)) - 12}; return new Date(years,(Number(months)) - 1,dates,hours,minutes,seconds,milliseconds); } public function getIntegerValue(dateString:String,index:int,min:int,max:int):Object { var valueString:String; for(var i:int = max;i >= min;i--) { valueString = dateString.substring(index,index + i); if(valueString.length < min) return NaN; if(isInteger(valueString)) return valueString; } return NaN; } private function isInteger(valueString:String):Boolean { var n:int = valueString.length; for(var i:int = 0;i < n;i++) { if(!isDigit(valueString.charAt(i))) return false; } return true; } private function isDigit(char:String):Boolean { return digits.indexOf(char) > -1; } private function getDayName(valueString:String,index:int):String { var n:int = dayNames.length; var dayName:String; for(var i:int = 0;i < n;i++) { dayName = dayNames[i]; if(valueString.substr(index,dayName.length) == dayName) return dayName; } return ""; } private function getDays(dayName:String):Number { var day:Number = dayNames.indexOf(dayName) + 1; day = day > 12? day - 12:day; day = day == 0?NaN:day; return day; } private function getMonthName(valueString:String,index:int):String { var n:int = monthNames.length; var monthName:String; for(var i:int = 0;i < n;i++) { monthName = monthNames[i]; if(valueString.substr(index,monthName.length) == monthName) return monthName; } return ""; } private function getMonths(monthName:String):Number { var month:Number = monthNames.indexOf(monthName) + 1; month = month > 12? month - 12:month; month = month == 0?NaN:month; return month; } private function isLeapYear(year:Number):Boolean { return ((year % 4 == 0) && (year % 100 != 0)) || ( year % 400 == 0); } } |
The original copy comes from InfoQ
经常被用来区分软件架构和软件设计开发的关键几点包括 伸缩性和抽象程度的增加以及作出正确设计决策意义的增强。软件架构是通过一个全局的观点,宏观的视角来理解软件系统作为一个整体如何工作。
即使这能够帮助区分软件开发和架构,它并不能帮助理解某人如何从开发提升到架构。 并且,它也不能帮助识别谁能够成为一个好的软件架构师,如果你想雇人的话你如何去寻找他们以及你是否是一个软件架构师。
要成为一个软件架构师并不是一夜之间或者一个职位的提升就能简单达到的。 这是个职责,而不是头衔。这是个进化的过程,你将会逐步得到担当这个职责所需的经验和信心。
当你寻找架构师时,需要考虑各方面的素质,他们过去的经验往往是他们有能力担当这个职责很好的判断。由于软件架构师的职责是多种多样的,所以你需要再深入了解他们在不同领域的参与度,影响力,领导力和责任感。一般来说,在大多数项目中软件架构可分为两个阶段,架构的定义,然后是它的交付。
架构的定义过程看起来非常简单明了。 你需要做的是理解需求并设计一个系统来满足需求。 但实际上并没有那么简单,根据你不同的做法,软件架构的职责之间差距很大,以及如何认真看待自己的职责而定。如下图所示,这个职责的架构定义部分,可以进一步细分成不同的元素。






对于架构的发布也是同样,对于成功的软件项目参与程度的不同,也决定了软件架构职责的不同。






不管你认为软件开发和架构之间的界限只是一个幻觉还是个巨大的鸿沟,以上强调了人们对整个软件架构中的经验水平往往有很大的差别,而这取决于他们怎么样工作以及他们如何认真地看待他们的职责。大多数开发人员不是在某一个星期一的早晨醒来就宣布自己成为一个软件架构师的。我当然也不是,我成为软件架构师的路线是一个渐进的过程。话虽如此,但很可能同样那些开发者已经做了一部分架构的工作,不论他们的职位名称是什么。
为软件系统的架构作出贡献和自己负责定义它有很大的区别,拥有持续的、跨不同领域的技能、知识和经验构成了软件架构的职责。跨越软件开发者和架构师的界限取决于你自己,但是首先你要明白你的经验水平,才能开始架构师之旅的第一站。
你可以认为Simon Brown是一个写代码的软件架构师或者理解架构的软件开发者。当他没有用.NET或Java开发软件的时候,Simon通常在做咨询,指导或者培训。 Simon还写过关于Java的书,在行业活动做过演讲,并且整合了一个叫Software Architecture for Developers的培训课程, 该课程基于他在Coding the Architecture描 述的软件架构。你可以通过e-mail 或 Twitter 找到他。
The original copy comes from Pixel Resort
The gap between the designers vocabulary and the clients knowhow can cause some problematic confusions. To alleviate this lets look at what an icon is, what a logo is and how these two things could come to be confused.
WHAT’S AN ICON?
Apart from any religious denotations an icon is a graphical representation of a concept or operation. We use icons to bridge the understanding of abstract analogies and practical use. Icons can be used to illustrate an entire application or individual operations within that application. In short, icons help us understand and recognize concepts that might otherwise be pretty hard to grasp.
I could write a very long article about the whimsical nature of icon conventions and the semiotics that guide these, but in this case it’s more relevant to look at the technical differences that is so fundamental for icon design and how these differ from logo design.
ICONS ARE NOT SCALABLE
More than often, icons are not scalable. The very idea of icons are to best convey a given message within a predetermined confined visual space. In today’s iconcentric interfaces we allow for multiple variations of the same icon. The icons that are sitting in your dock most likely have atleast 5 different states embedded, making them appear crisp in all aspects of your interaction with them. List view in OSX gives you the 16×16 pixel version while the dock uses the 256×256 pixel adaptation. These are not scalable vector versions, they are handcrafted raster masterpieces. The creator must carefully select how to best take advantage of the canvas in any given size and more than often completely recreate the icon in those sizes.
My manilla mail icon in it’s various states. Note the different layout of the elements in the smaller sizes.
ICONS ARE QUADRATIC
Icons operate within a complete square canvas. How you choose to employ that canvas is up to you, but it’s restricted to that straight edged space.
Icons are created on a neatly defined and restricted canvas
So that’s it. Icons are not scalable, they’re handcrafted raster imagery born from the desire to objectify an operation or a concept within a confined visual space. How does this differ from a logo?
WHAT’S A LOGO?
A logo is a graphical element like an ideogram and/or a carefully arranged typeface that together forms a trademark or a brand. There’s an infinite amount of ways to think about logos and logo design. Again, the important thing here is to look at the technical differences from icon design.
LOGOS ARE SCALABLE
A logo should be completely scalable. A logo is the spearhead of a company’s commercial brand or any economic or non profit entity for that matter. Therefore a logo should be replicatable across many forms of media. This has great impact on the sort of mindset you need to bring when designing logos. We’re talking strictly vectorbased output and more than often, graceful degeneration of colours all the way down to uni colours.
Logos are supposed to be scalable.
LOGOS HAVE NO BOUNDARIES
Well in theory a logo could be anything. Other than the obvious benefits of working in a format that is easily scalable and replicatable there really is very little rules compared to icon design. Icon design is very influenced by technical dimensions and the restrictions of the systems that display them. Logo design is a completely different venue. A logo could be any shape, colour or dimension – it can be waved from a 100 feet banner or tattooed on a butt cheek. It’s only constraint is that of the physical media that will display it.
WHY ARE WE CONFUSED?
Icons have taken a very prominent role in modern interfaces. This has obviously spilled over to the realm of branding where many icons serve both as application icon and branding for that entity.
Panic creates excellent software and uses their application icons as product branding
This wave of iconism™ (yes, I just invented that for this purpose) has influenced many graphic designers and a lot of the appealing aspects of the cartoony and crafty iconized style has made it’s way to modern logo design trends. Infact this style has become the posterchild for the web 2.0 movement, and such many internetbased firms have logos that uses the same visual vocabulary as icons.
Logos inspired by an Iconistic style
And while logos can certainly employ an icon-like style, and even mimic the quadratic nature of icons. Let there be no doubt, Icons and Logos are two completely separate design disciplines. It’s important to know the difference between these two things, as they inheretly seek out to fulfil two very different goals, both technically and mentally.
Below I’ve included a PSD template that supplies you with the canvas in the correct dimensions for making your own icons. If you wanna talk icon or logo design throw me an email or just have a look at my services page.
If you liked this article, why not comment and/or tweet about it. You can also hit me up on that thing called twitter