AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Is This Use of Brace Indentation Discouraged?
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> General Chat
View previous topic :: View next topic  
Author Message
Rhys



Joined: 17 Apr 2007
Posts: 618
Location: Florida

PostPosted: Thu Mar 20, 2008 9:31 pm    Post subject: Is This Use of Brace Indentation Discouraged? Reply with quote

Code:
If !Discouraged
{   MsgBox, This isn't discouraged.
   Coolpoints:=True
}
Else   
{
   MsgBox, This style is much better.
   Coolpoints:=False
}
I prefer the first style but find myself going back and forth for some reason. Can anyone offer an argument to use one over the other?
_________________
Back to top
View user's profile Send private message
TheIrishThug



Joined: 19 Mar 2006
Posts: 347

PostPosted: Thu Mar 20, 2008 9:50 pm    Post subject: Reply with quote

I don't think I've ever seen someone use that style. I think I'd stay away from it simply because it would make tabbing and shift+tabbing a selected block harder. If you care about the extra line, you can put the open brace at the end of the if clause.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Oberon



Joined: 18 Feb 2008
Posts: 408

PostPosted: Thu Mar 20, 2008 9:52 pm    Post subject: Reply with quote

The K&R style or OTB is the most common for scripting languages like javascript and php which makes it my preferred format for AutoHotkey. Also all your if-statements should be parenthesized if they are expressions.
_________________
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5298

PostPosted: Thu Mar 20, 2008 10:10 pm    Post subject: Reply with quote

I use it .. Very Happy
Back to top
View user's profile Send private message
Guest






PostPosted: Thu Mar 20, 2008 10:38 pm    Post subject: Re: Is This Use of Brace Indentation Discouraged? Reply with quote

Never do these...

Code:
If NeverDoThis
{   MsgBox, Never do this...
   CoolPoints:=False
}
Else
{
   MsgBox, ...or this...
   CoolPoints:=False
}
Code:
If ExtremelyNeverDoThis
   {
   MsgBox, Extremely never do this...
   CoolPoints:=-2147483647
   }
Else
   {
   MsgBox, ...or this...
   CoolPoints:=-2147483647
   }
Code:
if (I AND Am OR A OR Moron) {
   MsgBox, Never do this...
   CoolPoints:=0
}
Code:
CoolPoints := 0

Do these...

Code:
if (DoThis) {
   MsgBox, Do this...
   CoolPoints:=1
} else {
   MsgBox, ...or this...
   CoolPoints:=1
}
Code:
if (I && Am || Really || Cool) {
   MsgBox, Do this...
   CoolPoints:=1
}
Code:
CoolPoints:=1

...note every difference...
  • Never put anything on an opening brace (or closing brace, except else on closing brace of if)...
  • Extremely never indent the braces (this is what I thought your subject meant), never never never indent the braces to the level of the commands they brace...NEVER!!!...it's unreadable & U-G-L-Y...
  • Never use true/false or True/False...use 1/0...
  • Never put spaces around = or :=...
  • Never use AND OR...
  • Always use && ||...
  • Always lowercase I in if, lowercase E in else
      Exception: when using the IfWinExist command (& other If-commands), capitalize the I & capitalize the matching Else (if using if with WinExist() function...lowercase if & else)
  • Always use OTB-style: opening brace of if on same line as if, close brace of if on same line as else (seperated by 1 space), open brace of else on same line as else (seperated by 1 space)...
  • Always use expression-if, when possible...this means USE PARENS...

      Not...
      Code:
      if test
         msgbox, bad
      ...but...
      Code:
      if (test)
         msgbox, good

  • Always use real tabs...not spaces...my tab-width is "4 spaces" but when you use real tabs, any one can set the width in their editor...
  • Use of braces on all if's is encouraged, since OTB-style doesn't increase the lines too much...btw..."braces" are { }..."parens" (parentheses) are ( )...all if's should have both...
...feel free to ignore my style & write unreadable code...
Back to top
Oberon



Joined: 18 Feb 2008
Posts: 408

PostPosted: Thu Mar 20, 2008 11:27 pm    Post subject: Re: Is This Use of Brace Indentation Discouraged? Reply with quote

JSHater wrote:
Never put spaces around = or :=...
Why not? When you write equations irl don't you put spaces around numbers and operators?
_________________
Back to top
View user's profile Send private message
Guest






PostPosted: Thu Mar 20, 2008 11:48 pm    Post subject: Re: Is This Use of Brace Indentation Discouraged? Reply with quote

Titan wrote:
When you write equations irl don't you put spaces around numbers and operators?

...I don't have a spacebar IRL...
Back to top
Oberon



Joined: 18 Feb 2008
Posts: 408

PostPosted: Thu Mar 20, 2008 11:58 pm    Post subject: Re: Is This Use of Brace Indentation Discouraged? Reply with quote

Quote:
...I don't have a spacebar IRL...
Who said anything about a space bar? Do you need explaining what spaces look like irl?
_________________
Back to top
View user's profile Send private message
Ian



Joined: 15 Jul 2007
Posts: 1077
Location: Enterprise, Alabama

PostPosted: Fri Mar 21, 2008 1:23 am    Post subject: Reply with quote

Who are you to try to contradict how people write their expressions? I actually prefer to put spaces in mine because it helps me to see what is being done (Not that I can't without a space). Using spaces or changing the case of a function does not affect the outcome.
Back to top
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 702

PostPosted: Fri Mar 21, 2008 2:02 am    Post subject: Reply with quote

Code:
If ( MyPreference = "This style" ) ; with spaces around the operators ¬_¬
{ ; A short description of what to expect here AS WELL AS LEVEL OF NESTING = 1
   Something = SomethingElse
   Etc := Something** (1 / SomethingElse)
} ; Here I will tell you that we have just come out of nesting level 1 and maybe some expected value of 'Something'

imho, bracket lines are for comments.... not that I actually follow any such style, mind.

guest wrote:
...feel free to ignore my style & write unreadable code...
Indeed, I believe that you are the 'man to whom one must stick it'
_________________
My Home Thread
More Common Answers: 1. It's in the FAQ 2. Ternary ( ? : ) guide 3. Post code with [code][/code] tags
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2359
Location: Australia, Qld

PostPosted: Fri Mar 21, 2008 4:44 am    Post subject: Reply with quote

Quote:
Never use true/false or True/False...use 1/0...
true/false are more readable/clearer/more intuitive (where appropriate), in my opinion.
Quote:
Never put spaces around = or :=...
When = or := are the left-most operation on the line, I think it is clearer and more readable to have spaces. I do omit some spaces in complex expressions, to make the grouping/order of operation clearer.
Quote:
Always use OTB-style
This is not always possible. For instance, all types of traditional If and certain types of Loop do not support OTB.
Quote:
Always use expression-if
A traditional If is often more readable than its expression equivalent, and also faster.
Quote:
Always use real tabs...not spaces...my tab-width is "4 spaces" but when you use real tabs, any one can set the width in their editor...
I disagree: always use spaces. That way, the indentation will be consistent as long as the editor uses mono-spaced fonts, regardless of indentation settings. Changing the tab width to view someone else's script isn't practical, especially when you're also viewing your own scripts.
Quote:
Use of braces on all if's is encouraged,
This may be a good idea for those not familiar with the "rules", but I tend to avoid braces where possible, for readability.
Quote:
CoolPoints:=-2147483647
Regarding the "authoritative" tone of your post...
Code:
CoolPoints := 2**64
Cool (-9223372036854775808)
[VxE] wrote:
imho, bracket lines are for comments....
I often put comments on brace lines, if only to even out the distribution of text. Laughing
Back to top
View user's profile Send private message
Raccoon



Joined: 02 Jan 2008
Posts: 60

PostPosted: Fri Mar 21, 2008 7:46 am    Post subject: Re: Is This Use of Brace Indentation Discouraged? Reply with quote

Anonymous wrote:
Never do these...


Never listen to an Anonymous Coward.

I disagree with most every point made in his post, mainly because he refused to back up any of his points, but also because they reek of personal style preference and offer nothing tangible to this conversation.

Do whatever suits your coding style. Unless you're writing for a multi-national software corporation, your creation is nothing short of art.
_________________
Need help right away? Get live support on IRC.
Already have an IRC client installed? /join #autohotkey
Back to top
View user's profile Send private message
Guest






PostPosted: Fri Mar 21, 2008 2:11 pm    Post subject: Re: Is This Use of Brace Indentation Discouraged? Reply with quote

Raccoon wrote:
Never listen to an Anonymous Coward.

F*** YOU!
Back to top
BoBo¨
Guest





PostPosted: Fri Mar 21, 2008 2:43 pm    Post subject: Reply with quote

Quote:
Raccoon wrote:
Quote:
Never listen to an Anonymous Coward.
Quote:
F*** YOU!
Shocked Looks like he/she wanted ensure to prove Racoon right. Laughing
Back to top
Azerty



Joined: 19 Dec 2006
Posts: 58
Location: France

PostPosted: Fri Mar 21, 2008 3:59 pm    Post subject: Reply with quote

raccoon : Laughing
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> General Chat All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group