Coding Style Guidelines
#1
Posted 27 June 2012 - 08:37 PM
#2
Posted 28 June 2012 - 03:28 PM
But the most funny thing is watching them post "whats wrong with my code!!?!?!?!??" in the support session :lol:
#3
Posted 28 June 2012 - 11:12 PM
[quote name="Chapter 1]Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read on a 80-character terminal screen. The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.[/quote]
I like reading an instruction guide that tells you what to do and then insults you (and your code) if you don't like it. :wink:
#4
Posted 29 June 2012 - 05:53 PM
In short, 8-char indents make things easier to read, and have the added benefit of warning you when you're nesting your functions too deep. Heed that warning.
#5
Posted 30 June 2012 - 09:04 AM
class test
{
f()
{
loop 10
{
if(A_Index = 1)
msgbox first
}
}
}
#6
Posted 30 June 2012 - 08:53 PM
#7
Posted 01 July 2012 - 09:26 PM
[quote name="Chapter 1]The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.[/quote][quote name="fragman"]I tend to disagree, atleast for an example like this:
class test
{
f()
{
loop 10
{
if(A_Index = 1)
msgbox first
}
}
}[/quote]Well, I wouldn't count the first two indentations as part of the 3-indentation "limit". The statements in the loop would be the first indentation I would count.
#8
Posted 01 July 2012 - 09:37 PM
SubroutineName:
MsgBox,0,,This is msg box 1
MsgBox,0,,This is msg box 2
return
this form of indentation helps me quicky identify where subroutines begin and end in my code. Especially in longer pieces.Another form of styling is the naming conventions for variables, subroutines and functions. Occasionally i will use something called Hungarian Notation to help me remember what a given routine, function or variable's purpose is http://en.wikipedia....garian_notation this can be handy if not overdone.
Whether to leave in debugging code or not and the extent of errorchecking for boundary cases is also a style guideline. Code generalization and routine factoring are also style issues as well.
If i were to give any advice at all, I'd say pick a simple subset of styling conventions and stick with them for all your projects. Start with indentation and code factoring and try to keep your code as simple as possible given the job you need to do. The principle of Occam's Razor http://en.wikipedia....i/Occam's_razor is an important concept to apply to any code you write. And try to make your code as re-usable as possible to help you keep from having to reinvent the wheel every time.
#9
Posted 04 July 2012 - 02:19 PM
#10
Posted 22 July 2012 - 10:09 PM
#11
Posted 23 July 2012 - 08:06 AM
Do not add spaces around (inside) parenthesized expressions. This example is
*bad*:
s = sizeof( struct file );
not so sure i agree here
i've been working on my code and was finding that its much easier to read if () statements with function calls inside if there is a space such as
if ( isMyFunctionTrue(param1, param2) )
#12
Posted 23 July 2012 - 02:22 PM
Since a function follows the if, you don't need the outside parentheses at all.i've been working on my code and was finding that its much easier to read if () statements with function calls inside if there is a space such as
if ( isMyFunctionTrue(param1, param2) )
In addition, the open-parenthesis may be omitted entirely if the first item after the word "if" is a function call or an operator such as "not" or "!".
if isMyFunctionTrue(param1, param2)
#13
Posted 24 July 2012 - 02:22 AM
#14
Posted 20 August 2012 - 09:36 AM
Me too - AHK has too many special handlings when parenthesis are omitted that I tend to use them always. In v2 this might change, as a if will always be followed by an expression.yea i know that, i've tried that as well, but i like to enclose all my ifs in parenthesis not only to standardize the use of expression-if but also because i find it easier to read (pradoxically i know)
Some other rules I use - personally but also enforce in teams, no matter what language used:
[*:2mm0qmes] Good readable Variable names / Method names (no abbreviations, no one-char names; exception: i,j for counters)
[*:2mm0qmes] Method Line-Count should fit on a single screen. Max 3 nested Code-Blocks. (=> create new Methods where the code is "out-sourced")
[*:2mm0qmes] Never ever have redundant code. Sounds obvious, but some people don't get it.... they copy 30lines of code, and change one single thing and generate lot of redundant overhead
#15
Posted 26 October 2012 - 04:19 AM
Unlike C, AHK is case-insensitive, therefore it boils down to personal preference whether to use upper or lower case. I find that capitalizing the first letter of each word not only aids readability, but also saves space:
IfWinActive that's niceifwinactive had a rough day?if_win_active underscores = more horizontal space usedAfter using AHK for nearly three years, it is clear to me that most coders here favour capitalization, and so does the AHK help. Then why is it that many of these people choose NOT to capitalize certain keyboards such as
if, else, return, while, but do capitalize most other keywords?Personally I capitalize everything and use underscore to separate an acronym or a single letter from a word e.g.
A_PriorHotkey or OSD_Message so that the first letter of the next word is not mistaken as being part of the preceding acronym.




