What did you learn today?

| 5 Comments | 1 TrackBack

I can't believe I didn't know this one... Actually, I think I did know it, but I've been coding with a certain style for so long that it influenced my view of syntax requirements.. For example, did you know that you can write code that looks like this...

x = String.

            fromCharCode(123);

trace(x);  // {

... and it works just fine? The above behaves just like x = String.fromCharCode. The extra spaces, line feeds, tabs, etc, are all ignored around the dot operator.

Similarly,

var a:Array =  new Array("1", "2", "3");

trace(a.   join("."));

... traces "1.2.3" to the output window, just as expected.

I don't recall encountering this before in my years of programming. I might've, but haven't thought about it or just glazed over it. I've always omitted any sort of spaces around the . operator (and the -> operator in C++) as a habit (example: Class.method, not Class    .   method). It somewhat surprised me to find out that whitespace like this is ignored.. and not just by ActionScript. Java, C# and C++ all behave similarly. However, ColdFusion will generate a syntax error - 'The variable StructTest. ends with a "." character. You must supply an additional structure key or delete the "." character.'

I'm not recommending that you space your code like I have above, but it's interesting to note that you can if you want to. It's easy to envision situations where having that type of freedom is useful, but I think it would pollute code readability if used liberally.

Learn something new every day....

1 TrackBack

TrackBack URL: http://www.darronschall.com/mt/mt-tb.cgi/6

After seeing Darron Schall's white space revelation the other day, I thought I would share something else common to most programming languages. In Actionscript logical expressions are evaluated executing the least amount of comparisons necessary to eva... Read More

5 Comments

It can actually be a nice way to break long lines of chained method calls (although my style is to break *before* the . or -> selector rather than after it).

I've seen code that uses a style something like this as a matter of course (not in AS but I'll use your AS code as an example):

trace ( a . join ( "." ) ) ;

I really don't like that - I think both the function call operator and the selector should be "bound" to something without the space so this is more palatable to me:

trace( a
.join( "." )
);

I used to break up long SQL statements into several lines, especially for Stored Procedures.

Hi,

I encountered same thing several times in past. But the very first time, i wondered but after testing i found it works. An thought, since . is like an operator it behaves like other operators.

Regards,
Abdul

All good 'till MM will publish their next flash player (or next-next flash player) which will not support this kind of practice. same thing as the Case Sensetive issue.
don't ya think?

Neat, just hope people don't start thinking it's PHP :p (wish they would switch to + for concatenation! :/)

Leave a comment



About this Entry

This page contains a single entry by darron published on April 28, 2004 1:02 PM.

Alright, it's compiler naming time... was the previous entry in this blog.

Announcing FlashBelt conference is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Archives

OpenID accepted here Learn more about OpenID
Powered by Movable Type 5.02