03-04-2012, 03:22 AM
|
#11
|
|
Flexpert
Join Date: Sep 2006
Location: Seattle, WA: USA
Posts: 1,564
|
Quote:
Originally Posted by Xegnma
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!
|
|
|
03-09-2012, 04:10 AM
|
#12
|
|
Site Contributor
Join Date: Jun 2006
Posts: 3,160
|
Thanks for the tip. I'll have to check out that book!
|
|
|
06-17-2012, 04:59 PM
|
#13
|
|
Cloud Strife's Agent
Join Date: Jun 2012
Location: Iowa
Posts: 3
|
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.
|
|
|
11-14-2012, 07:59 PM
|
#14
|
|
Registered User
Join Date: Nov 2009
Posts: 2
|
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
|
|
|
11-14-2012, 08:56 PM
|
#15
|
|
Software Engineer
Join Date: Nov 2009
Location: LU, Switzerland
Posts: 1,325
|
@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.
|
|
|
11-14-2012, 11:50 PM
|
#16
|
|
Super Moderator
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
|
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.
|
|
|
11-15-2012, 12:00 PM
|
#17
|
|
Super Moderator
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,514
|
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.
|
|
|
11-15-2012, 03:50 PM
|
#18
|
|
Senior Member
Join Date: Aug 2008
Posts: 340
|
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 ();
}
}
}
ö
__________________
marlopax
Last edited by marlopax; 11-16-2012 at 02:14 PM.
|
|
|
11-15-2012, 04:04 PM
|
#19
|
|
Software Engineer
Join Date: Nov 2009
Location: LU, Switzerland
Posts: 1,325
|
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.
|
|
|
11-15-2012, 04:31 PM
|
#20
|
|
Senior Member
Join Date: Aug 2008
Posts: 340
|

Actually we have enough time to play formatting our codes.
Some others don’t even have time to comment on there code.
It all depends on how much work pressure you have.
We have plenty …
ö
__________________
marlopax
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 10:30 PM.
///
|
|