Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Best Practices

Reply
 
Thread Tools Rate Thread Display Modes
Old 03-04-2012, 03:22 AM   #11
drkstr
Flexpert
 
drkstr's Avatar
 
Join Date: Sep 2006
Location: Seattle, WA: USA
Posts: 1,587
Default

Quote:
Originally Posted by Xegnma View Post
I you really want to make your code readable by other programmers I strongly suggest you pick up the book "Clean Code: A Handbook of Agile Software Craftsmanship" by Robert C. Martin.
^ Second!
drkstr is offline   Reply With Quote
Old 03-09-2012, 04:10 AM   #12
Mazoonist
Site Contributor
 
Mazoonist's Avatar
 
Join Date: Jun 2006
Posts: 3,160
Send a message via AIM to Mazoonist
Default

Thanks for the tip. I'll have to check out that book!
__________________
My Tutorials * My Website
Mazoonist is offline   Reply With Quote
Old 06-17-2012, 04:59 PM   #13
OhAlexO
Cloud Strife's Agent
 
Join Date: Jun 2012
Location: Iowa
Posts: 3
Default

I'm fairly new with Actionscript but I believe that's why my answer may be of some use. As others have said neither is really right or wrong but when it comes to readability putting the curly brace on the next line helps me out more than you'd think.

Code is already confusing enough especially for those just starting out, and putting a curly brace on the next line seems more appropriate when going back through and reading my code.
OhAlexO is offline   Reply With Quote
Old 11-14-2012, 07:59 PM   #14
totem415
Registered User
 
Join Date: Nov 2009
Posts: 2
Default Spreading Your Code Out Vertically Makes it Harder to Read

if (x == 1)
{
trace ("hello");
}
else
{
trace ("goodbye");
}
// Seriously?

vs:

if (x == 1){
trace ("hello");
} else {
trace ("goodbye");
}
// Ahh. Better!

The downside of making a new line for each curly brace is that you often can't see the entire function you're working on on-screen. For me this makes it much harder to understand the logic.

I started programming in 1993 on a 14" monitor and the idea of spreading your code out vertically like that to make it "easier to understand" is just impractical. I can never see enough of my code on-screen, even today with 24" and 30" monitors . . . especially when you're running the debugger.

So I vote for cuddling your curly braces across the board to condense your code . . . so you can actually see more of it! I have no trouble whatsoever understanding the logic that way.

Comparing it to titling rules in typography is totally off the mark because titles are designed to grab your attention. Do people write entire books following the typographic rules for titles on the cover of a book? No . . . unless they're picture books or for kids. Why is that?

If you're an amateur and you need to exaggerate the logic to make it easier for spoon-feeding it to your self, that's fine. But please don't act like that's the standard for the all of the big boys.

$0.02

-Roger Crist
totem415 is offline   Reply With Quote
Old 11-14-2012, 08:56 PM   #15
Barna Biro
Senior Member
 
Barna Biro's Avatar
 
Join Date: Nov 2009
Location: LU, Switzerland
Posts: 1,406
Default

@totem415: Actually, your example I'd personally write like:

ActionScript Code:
trace(x == 1 ? "hello" : "goodbye");
When you have a single line between the opening and closing brackets, I also prefer to usually not put each bracket on a separate line... but if the body is any longer, I prefer having it clearly visible than writing "glued blocks".

Writing short / compact code is not everything...
I value clean and easy to understand code a lot more.
__________________
Titus M. Plautus - Not by age but by capacity is wisdom acquired.

Last edited by Barna Biro; 11-14-2012 at 09:02 PM.
Barna Biro is offline   Reply With Quote
Old 11-14-2012, 11:50 PM   #16
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Here, the idea of 'better' coding style is fairly subjective and should differ to who you are talking to.

I'd like to call myself not amateur since I do this for living and have started coding stuff whole lot earlier than 90s but I always find it easier to read the code when it is indented the way I read codes better, ie Allman style. It probably is because that was sort of standard when I started learning stuff and it just got engraved in my brain.

We are living in an age where you can use good editor that can configure the code the way you want and I really don't see good value discussing something that is really subject. Like Barna Biro said, it is important to write code that is easier to understand and maintain.
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 11-15-2012, 12:00 PM   #17
ASWC
Super Moderator
 
ASWC's Avatar
 
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528
Default

It's worth noticing that while the code writing style is personal, it should also accommodate to your teammates if you have any. When it's the case then the 'I do it like that', 'that's the best way for me' is no longer accurate. I do use Allman style and all my code is always very organized in carefully named packages. The result is all my coworkers find it very easy to work with my code, everything is easy to find, easy to read.
__________________
aswebcreations
Super Duper!
ASWC is offline   Reply With Quote
Old 11-15-2012, 03:50 PM   #18
marlopax
Senior Member
 
Join Date: Aug 2008
Posts: 340
Default

Writing Code is everyone's stylistic choice. It all matters of readability and easy to understand. Here is a sample how we format our Classes:



Where auto formatting in Flash IDE is looks like this:

ActionScript Code:
package com.client_domain.author{     /*[ Short comment ]*/     import flash.display.MovieClip;     import flash.events.Event;     import flash.events.MouseEvent;     import flash.text.TextField;     /*[ Short comment ]*/     import com.client_domain.author.utils;     public class DocumentClass extends MovieClip {         /*[ Short comment ]*/         public var user:User;         public var active:Active;         private var _privilage:Privilages;         public function DocumentClass() {             init();         }         public function init() {             user=new User ();             active=new Active ();             _privilage=new Privilages ();         }     } }


Attached Thumbnails
Click image for larger version

Name:	class_format.JPG
Views:	12
Size:	42.4 KB
ID:	38880  
__________________
marlopax

Last edited by marlopax; 11-16-2012 at 02:14 PM.
marlopax is offline   Reply With Quote
Old 11-15-2012, 04:04 PM   #19
Barna Biro
Senior Member
 
Barna Biro's Avatar
 
Join Date: Nov 2009
Location: LU, Switzerland
Posts: 1,406
Default

Huh... your formatting actually makes me want to jump out the window Sure, eventually you get used to it, but I see absolutely no point in adding so much whitespace between things... if anything, it might only make the code less readable and definitely weird looking ( frankly, I'd prefer staring at the auto-formatted code than the stuff from the screenshot ). I definitely dislike that style... it also looks extremely time consuming ( lining up everything all the time and adjusting lines if you refactor things - at least, I'm guessing that you also adjust them, otherwise it makes even less sense, etc. ).
__________________
Titus M. Plautus - Not by age but by capacity is wisdom acquired.

Last edited by Barna Biro; 11-15-2012 at 04:15 PM.
Barna Biro is offline   Reply With Quote
Old 11-15-2012, 04:31 PM   #20
marlopax
Senior Member
 
Join Date: Aug 2008
Posts: 340
Default


Actually we have enough time to play formatting our codes.
Some others dont even have time to comment on there code.

It all depends on how much work pressure you have.

We have plenty


__________________
marlopax
marlopax is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:31 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.