Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Is This Use of Brace Indentation Discouraged?


  • Please log in to reply
38 replies to this topic
Rhys
  • Members
  • 761 posts
  • Last active: Aug 09 2013 04:53 PM
  • Joined: 17 Apr 2007
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?

TheIrishThug
  • Members
  • 419 posts
  • Last active: Jan 18 2012 02:51 PM
  • Joined: 19 Mar 2006
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.

Oberon
  • Members
  • 442 posts
  • Last active: Jul 03 2008 11:34 PM
  • Joined: 18 Feb 2008
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.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
I use it .. :D

  • Guests
  • Last active:
  • Joined: --
Never do these...

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

if (DoThis) {
	MsgBox, Do this...
	CoolPoints:=1
} else {
	MsgBox, ...or this...
	CoolPoints:=1
}
if (I && Am || Really || Cool) {
	MsgBox, Do this...
	CoolPoints:=1
}
CoolPoints:=1
...note every difference...
[*:15p45fc2]Never put anything on an opening brace (or closing brace, except else on closing brace of if)...
[*:15p45fc2]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...
[*:15p45fc2]Never use true/false or True/False...use 1/0...
[*:15p45fc2]Never put spaces around = or :=...
[*:15p45fc2]Never use AND OR...
[*:15p45fc2]Always use && ||...
[*:15p45fc2]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)[*:15p45fc2]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)...
[*:15p45fc2]Always use expression-if, when possible...this means USE PARENS...

Not...
if test
	msgbox, bad
...but...
if (test)
	msgbox, good
[*:15p45fc2]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...
[*:15p45fc2]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...[/list]...feel free to ignore my style & write unreadable code...

Oberon
  • Members
  • 442 posts
  • Last active: Jul 03 2008 11:34 PM
  • Joined: 18 Feb 2008

Never put spaces around = or :=...

Why not? When you write equations irl don't you put spaces around numbers and operators?

  • Guests
  • Last active:
  • Joined: --

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

...I don't have a spacebar IRL...

Oberon
  • Members
  • 442 posts
  • Last active: Jul 03 2008 11:34 PM
  • Joined: 18 Feb 2008

...I don't have a spacebar IRL...

Who said anything about a space bar? Do you need explaining what spaces look like irl?

trik
  • Members
  • 1317 posts
  • Last active: Jun 11 2010 11:48 PM
  • Joined: 15 Jul 2007
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.

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
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.

...feel free to ignore my style & write unreadable code...

Indeed, I believe that you are the 'man to whom one must stick it'

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

Never use true/false or True/False...use 1/0...

true/false are more readable/clearer/more intuitive (where appropriate), in my opinion.

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.

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.

Always use expression-if

A traditional If is often more readable than its expression equivalent, and also faster.

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.

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.

CoolPoints:=-2147483647

Regarding the "authoritative" tone of your post...
CoolPoints := 2**64
8) (-9223372036854775808)

imho, bracket lines are for comments....

I often put comments on brace lines, if only to even out the distribution of text. :lol:

Raccoon
  • Members
  • 178 posts
  • Last active: Oct 06 2014 05:58 PM
  • Joined: 02 Jan 2008

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.
Posted Image

Need help right away? Get live support on IRC.
Already have an IRC client installed? /join #ahk

  • Guests
  • Last active:
  • Joined: --

Never listen to an Anonymous Coward.

F*** YOU!

BoBo¨
  • Guests
  • Last active:
  • Joined: --

Raccoon wrote:

Never listen to an Anonymous Coward.

F*** YOU!

:shock: Looks like he/she wanted ensure to prove Racoon right. :lol:

Azerty
  • Members
  • 72 posts
  • Last active: Jan 16 2009 10:08 AM
  • Joined: 19 Dec 2006
raccoon : :lol: