View Full Version : Bug: Compiler Error
neves
June 2nd, 2007, 10:50 PM
Why bugs keep following me?
Open a new .fla, go to the first frame and put the follow code:
stop()
(this as MovieClip).play()
We know that AS can be written without semicolon (and I prefer that, since Iīm a Ruby developer), but the above example, we must use semicolon after stop
This works:
stop();
(this as MovieClip).play()
Itīs obviously a parse error from the compiler. This works too:
stop()
var foo = (this as MovieClip).play()
FizixMan
June 3rd, 2007, 12:44 AM
Coincidentally, these work:
stop()
MovieClip(this).play()
stop()
this.play()
stop()
MovieClip(this as MovieClip).play()
stop()
Object(this as MovieClip).play()
stop()
play()
Just use a semi-colon or avoid completely obtuse code.
dthought
June 3rd, 2007, 09:50 AM
It is best practice in Flash to use semicolons. Just because you are familiar with Ruby doesn't mean you should try to shoehorn its practices into Flash.
In the same way, you can't always shoehorn English words into other languages just by adding a different spoken accent.
Again, not a bug but bad user code. Sheesh. :P
Breen
June 3rd, 2007, 09:52 AM
Again, not a bug but bad user code. Sheesh. :P
I don't see how this is "bad" user code. I admit it's not really usefull nor is it efficient. But in any case, it SHOULD work.
neves
June 3rd, 2007, 10:49 AM
I don't see how this is "bad" user code. I admit it's not really usefull nor is it efficient. But in any case, it SHOULD work.
Totally agree with Breen, if the compiler accept "not use of semicolon", it should accept always, thatīs logic. Yes, thatīs a compiler bug.
And the code is just an example, the real code is (parent as MovieClip).play()
How can I submit to Adobe Team?
senocular
June 3rd, 2007, 02:05 PM
It seems the parens are evaluated with all white space prior to the determination of command endings allowing actions like
stop
();
to still work (and there may be better use cases). This, of course, breaks with your example since it expects the return value of stop to be a function call with the argument parent as MovieClip.
I will log it as a bug, but I am not entirely sure it will be considered as one.
(This behavior also existed in AS2)
Rossman
June 3rd, 2007, 02:28 PM
Totally agree with Breen, if the compiler accept "not use of semicolon", it should accept always, thatīs logic. Yes, thatīs a compiler bug.
Yes and no. It is a compiler bug, but not what you think - the bug is that the compiler will not detect missing semi-colons in certain cases. (Not that it should allow missing semi-colons in all cases)
Actionscript dictates that semi-colons terminate every statement/line, just because another language doesn't do that is irrelevant.
neves
June 3rd, 2007, 04:28 PM
var foo //works
(this as MovieClip).play()
var foo = 10//doesnīt works
(this as MovieClip).play()
IMHO the compiler should do the follow:
if it find a end of line, the command is done, unless it ends with an "open command" like:
this.
play()
or this
foo(
bar(2, 3)
)
On the above example, the correct behavior should be:
stop() // ok
stop(
)// ok
stop
() // invalid
See? It was just a behavior choice madded by the Adobe Team, but it has a better choice.
Rossman
June 3rd, 2007, 04:37 PM
Yeah, that's your opinion alright.
In my opinion:
var foo // shouldn't work, if it does this is a compiler bug
(this as MovieClip).play()
but:
var foo; // should work
(this as MovieClip).play();
Personally I have no problems with the choice Adobe made, because I understand that some languages require certain syntax and others don't.
FizixMan
June 3rd, 2007, 05:23 PM
In my opinion, put in semi-colons. :P
Like Rossman said:
Actionscript dictates that semi-colons terminate every statement/line, just because another language doesn't do that is irrelevant.
I feel that the ability to leave out semi-colons is just to assist those graphics artists who need to put in a small tiny script but have no background in programming.
neves
June 3rd, 2007, 06:12 PM
I feel that the ability to leave out semi-colons is just to assist those graphics artists who need to put in a small tiny script but have no background in programming.
I agree with the first statement, but say that semicolons are for old school programmers that doesnīt realize that you donīt need semicolons :) New line is already an "end of command" separator. See languages like Python and Ruby :)
If you didnīt agree, put yourself in the following situation. Imagine that never had exists semicolon, in the hole programming life. If tomorrow languages starts to use semicolon, what would you think about it? Sincerely!
Rossman
June 3rd, 2007, 06:36 PM
Newline is a terrible statement delimiter. Just because Python and Ruby uses it, doesn't make it right, or good.
Many, many languages use semi-colons and there isn't anything wrong with it. Either adapt or don't use Actionscript, but to waste the Flash development team's time with this....? Crazy.
Let's put this in a different perspective
If newline was a good delimiter, all our text would be like this
It doesn't seem that practical to me
Sorry if you young kids can't handle using good syntax
Let's put this in a different perspective. I think this is much easier to read. Compared to the above it's definitely preferable. Sorry if you young kids can't handle using good syntax.
neves
June 3rd, 2007, 07:17 PM
Please, donīt tell me that a code that everyone write like this: (with/or without semicolon, doesnīt matter, each command are on a new line)
var total:Number = 0
for each (var property:XML in myXML.item)
{
var q:int = Number(property.@quantity)
var p:Number = Number(property.price)
var itemTotal:Number = q * p
total += itemTotal
trace(q + " " + property.menuName + " $" + itemTotal.toFixed(2))
}
trace("Total: $", total.toFixed(2))
you prefer to write like this:
var total:Number = 0; for each (var property:XML in myXML.item) { var q:int = Number(property.@quantity); var p:Number = Number(property.price); var itemTotal:Number = q * p; total += itemTotal; trace(q + " " + property.menuName + " $" + itemTotal.toFixed(2))} trace("Total: $", total.toFixed(2));
Thanks to semicolon, we can write code on only one line :) Thanks god for semicolon :)
In true, Iīm a multi language programming, and donīt care about semicolon. But Iīm a teacher too, and 90% of my students have problems of forgetting semicolons at end of line. But EVERY ONE automatically understand that one command per line is fine :) So, why the need of semicolon, they ask me?
Rossman
June 3rd, 2007, 08:13 PM
and 90% of my students have problems of forgetting semicolons at end of line.
Then you should dock them points, it's not exactly the hardest concept they will encounter ;)
So, why the need of semicolon, they ask me?
Why? Because that's how Actionscript works. Plain and simple ;) They would have to learn that discipline in a language with a better compiler, like C (and it's variants), Java, etc. which actually enforces the rules better.
Also, I wasn't saying that people *should* code everything on one line, but there with a specific delimiter (unlike newline) you can if need be.
Understanding the details of a languages syntax is something a good programmer should just do.
FizixMan
June 3rd, 2007, 08:22 PM
In true, Iīm a multi language programming, and donīt care about semicolon. But Iīm a teacher too, and 90% of my students have problems of forgetting semicolons at end of line. But EVERY ONE automatically understand that one command per line is fine :) So, why the need of semicolon, they ask me?
function test(param1:String, param2:Number, param3:Array, param4:Object, param5:Object, param6:Object, param7:Object):String
{
//Logging statement
trace("Test called!"
+ " param1: " + param1
+ " param2: " + param2
+ " param3.length: " + param3.length
+ " param4: " + param4
+ " param5: " + param5
+ " param6: " + param6
+ " param7: " + param7
);
//Logging statement 2
trace("Test called!")
trace("param1: " + param1)
trace("param2: " + param2)
trace("param3.length: " + param3.length)
trace("param4: " + param4)
trace("param5: " + param5)
trace("param6: " + param6)
trace("param7: " + param7)
//Logging statement 3
trace("Test called!" + " param1: " + param1 + " param2: " + param2 + " param3.length: " + param3.length + " param4: " + param4 + " param5: " + param5 + " param6: " + param6 + " param7: " + param7);
return param1;
}
They all work. But I'll tell you why I don't like the newline as a code-line separator. Because it's ambiguous. In the case above, for "logging statement 1" the new line doesn't cause the compiler to read each line as a separate action. In "logging statement 2", the new line creates separate actions.
Whereas if you use semi-colons exclusively, it becomes explicit. There is no ambiguity. You see a semi-colon, you know it's the end of that particular action. It doesn't matter where it is. And you can see why we would want to split up a logging action like that when you compare it to "logging statement 3".
If it were up to me, I'd lobby Adobe to ditch any and all leniency in their compiler. Though I do understand why they keep it accessible. As troublesome as it is, your students should get into the habit of using semi-colons. If 90% of them are having trouble remembering semi-colons, then they definitely have a ways to go -- just because it doesn't seem intuitive, doesn't mean it's ok to be a lazy programmer. And you of all people should understand that ambiguity has no place in a language. The more explicit, the better.
When I was first learning Java, I had a hard time with the semi-colon as well. But I stuck at it, and now it's second nature and I wouldn't have it any other way.
senocular
June 3rd, 2007, 08:56 PM
Bottom line. Use the semicolon.
neves
June 4th, 2007, 03:01 AM
Thanks FizixMan, finally someone with a really good point of view :)
Here goes two solutions used by Ruby that clearly show how semicolon is really useless.
// just terminate your line with an operator, this makes clearly that the statement is not ended
trace("Test called!" +
" param1: " + param1 +
" param2: " + param2 +
" param3.length: " + param3.length +
" param4: " + param4 +
" param5: " + param5 +
" param6: " + param6 +
" param7: " + param7
)
But if you really want to start your line with plus operador, do that:
// just terminate your line with back slash,
//to say that the command is not done yet.
//Just the opposite meanning of semicolon for the rest of code
// here, I use pipe because the backslash doesn't show up
trace("Test called!" |
+ " param1: " + param1 |
+ " param2: " + param2 |
+ " param3.length: " + param3.length |
+ " param4: " + param4 |
+ " param5: " + param5 |
+ " param6: " + param6 |
+ " param7: " + param7
Do you find it ugly? Weird? Change it for a semicolon and you will know what I mean.
Since the above code, usually represents 10% of a program, you use special chars only for that sittuations. But semicolon is used just the opposite. 90% of code, you use it at the end of line, to show that the command has finished (even if the end of line has already said it).
The true is that there are languages that don't use semicolons, and are so verbose and easy to read as the others.
Have you seen that you ident your code, to make clearly that it was not finished? Python uses identation too as a scope delimiter :)
I think this thread is over now :) But if you like a good "round table" like me, use my email: marcos.neves at gmail
FizixMan
June 4th, 2007, 07:42 AM
Identation as a scope delimiter? *shudders*
I'm sticking to my guns in that whitespace is too ambiguous to be used as a syntax construct. And in terms of Actionscript, I think Senocular said it best.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.