14 Jan 2008

Just couldn't resist, mate.

From time to time I read a tutorial trying to educate myself on programming, which is just my hobby so I'd like it to be nice and easy. I've read some java tutorials, skimmed through some C++' ones lately, seen some Scala's, Python's and so on. I am not calling myself an expert on that, I am far from that. I am just a average human.

I am trying to push myself through one of tutorials on ActionScript 3. It's name is ActionScript 3.0 for developers and designers – Part 1: Creating a preloader. I've just wonder whether that's me or there is actually something wrong with this article. I hesitated a little, but couldn't resist to write about it so you may judge it yourself.

First thing, Jamie Kosoy is using code convention that makes my hair go gray. Below is the sample.

private function _onProgressBarComplete($evt:Event = null):void
{
_isLoadComplete = true;

progress_mc.removeEventListener(Event.ENTER_FRAME,_onProgressEnterFrame); _animateOut();
};
private function _animateOut():void
{
gotoAndPlay("OUT");
addEventListener(AnimationEvent.ANIMATE_OUT, _onPreloaderOut,false,0,true);
};
I am almost sure this is not the recommended style for ActionScript 3. What the heck is with those $ and _ ?! Are those really that useful to understand code? You know what? When I read this source code I wondered whether those might some special variables, I had to check AS docs to clear it is just a convention. One thing it leads to is to ask useless question: what do those character mean? You have to be pretty sure that there will be questions about tertiary operator as well, and this _animateOut() function call on the of the line!

And the flow of article kills me of. Instead of going from start of program it goes the other way. You see on method there, another here. I know Jamie is senior developer and probably most of developers will understand this cliploader he is presenting. Including myself, but it is hard to read it this way.

Concluding I think this article should be revised to my liking! :))) That is:
  • make all the special characters from variables go away (this would let me concentrate on the problem tackled in the article and not on wondering what those underscores and dollar sings might mean),
  • rewrite the article so that it goes from top to bottom (this would present it the way source code is read - from application start. For this very clipLoader I would start from the code that actually loads the content and would drill down to details of passing the event to the timeline objects).
I am sure I will learn a lot from the article, but this could be even better experience for me. And how do you think?

2 comments:

  1. I hope there's nothing wrong with the article! :)

    To respond to your criticisms:

    1) The _ and $ are naming conventions specific to my code style. It wasn't in the scope of the article to describe the conventions I use. They help clarify arguments passed to a function ($) and private variables (_) from public. This becomes very clear with the source.

    2) The flow of the article aims to step through what's happening on the screen at any given point and describe the basic code block that represents that specific piece of functionality. I'd argue this is a much easier read, creating clarity rather than confusion.

    ReplyDelete
  2. There is nothing wrong with the article. It is just our preference for naming conventions and source reading do differ.

    1) I dare to say that using a convention without clarifying it can make the code less readable for newbies (like me) in a way that meaning of _ and $ are not know. And _ especially is harming readability of the variables' names (typotrap).

    2) This flow is just opposite to what I prefer :). I like to go from application start code, because this way I can follow it more clearly - I see variables from initialization to using them in function calls.

    All in all article is certainly worth reading and the code is worth even more. Thanks for your hard work!

    ReplyDelete