 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
urlwolf
Joined: 16 Mar 2006 Posts: 100
|
Posted: Sun Jan 06, 2008 12:26 am Post subject: Autohotkey coding standards (naming, etc) |
|
|
I've reading ahk code lately, and one thing that pops up is the lack of coding standards.
The only thing that I've seen as a common practice is to use 'fake namespaces' by preceeding vars and functions with the name of the file they are in.
Vars and arrays look exactly the same. Maybe one could use some conventions?
Here are some (old) actionscript coding standards that could be used as example.
www.adobe.com/devnet/flash/ whitepapers/actionscript_standards.pdf
I think that'd improve the readability of scripts. For example, one could do @arrays and $vars (a la perl) or foo_arr, foo_var. Same for other constructs. Maybe a poll to decide. Any standard is better than no standard.
What do you think? |
|
| Back to top |
|
 |
Guest
|
Posted: Sun Jan 06, 2008 1:19 am Post subject: Re: AutoHotkey Coding Standards (naming, etc) |
|
|
| urlwolf wrote: | | What do you think? |
...I think, that unless everyone codes my way, I will not follow any "standard" (cuz if the standard don't fit me, why would I use it?)...no one will bow to my coding practices & I will not bow to theirs...I see no reason for @array & $var...I don't understand why people need to differentiate between the 2...in JavaScript everything is great...a var is a var, if you decided to turn it into an Array, great!...do it...no need for ugly symbol appendages to the chosen var/array name...I am for AutoHotkey turning into JavaScript...I am against AutoHotkey turning into ANY rigid language...I am against any dumb "coding standards" telling me I should code in a dumb way to make other people happy...I code my way, you code yours...
If a standard is created...I am for...
- One True Brace (OTB) (with space between close paren on param list & open brace)
| Code: | otbrules(p1, p2, p3) {
;//function body indented with tab
msgbox, hi
} |
No spaces around any = or :=
Use of && || over AND OR
| Code: | if (one && two || three)
msgbox, hi |
All "blocks" indented with tab
| Code: | function(p1, p2, p3) {
;//function body indented with tab
}
Loop {
;//indented
} |
Subroutines not indented
| Code: | subsnotindented:
msgbox, hi
return |
Calling it AutoHotkey (capital A, capital H) not: Autohotkey, AutoHotkeys, Autohotkeys...I could list more, but no one likes my style, so I'd be wasting my time... |
|
| Back to top |
|
 |
John W
Joined: 09 Apr 2007 Posts: 148
|
Posted: Sun Jan 06, 2008 5:32 pm Post subject: |
|
|
The idea is good. I use my own "standard": Subroutines are not indented, blocks are indented with two spaces (including the braces), functions do not use the OTB style and the braces and the contents are indented with two spaces, too. And I write some letters in uppercase to separate parts of the name.
| Code: | Start:
FileName = My standard.ahk
VarName = Hello!
MsgBox, %VarName%
Loop, 3
{
Sum := Add(A_Index, 3)
If Sum > 5
MsgBox, %A_Index% + 3 = %Sum%
}
Return
Add(A, B)
{
Return A + B
}
|
_________________ John
Inactive - Until AutoHotkey is available for Linux. |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5009 Location: imaginationland
|
Posted: Sun Jan 06, 2008 5:34 pm Post subject: Re: AutoHotkey Coding Standards (naming, etc) |
|
|
| Anonymous wrote: | | Use of && || over AND OR | I don't like confusing logic conjunctions for operators; the latter should only be expressed in symbols as it's a system people have adopted thousands of years ago with numeracy. If you prefer && you would need a glyph for 'if' since that's technically a similar clause. _________________
RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 383 Location: Berlin
|
Posted: Sun Jan 06, 2008 7:45 pm Post subject: |
|
|
Thats a good idea to have coding standards. I am also one of the people who like standards. Like the guest (no nick chosen ) above show us why this is not easy to do. Every experienced coder have its own style and may be that for years. Most wouldnīt agree with you, because they donīt see the advantage having a standard and may not care.
We could make documents like the W3C, just recommendations how to write something. May be there could be more than one standard to choose for. We shouldīt someone drive into what s/he donīt like, but we could tell him why he should do it that way.
For example, I am completly disagree with the style of that Guest above us.
My style:
- using AND and OR over && and ||, because it does not look so cryptic
- with spaces around every operator and variable in expression, because without spaces it looks like one word only and not like an expression with different elements
- nearly always 4 spaces, sometimes 2 or 3, but never tabs
- always indenting subroutines, functions, ifs and all other sort of blocks
- no OTB style, always like this
| Code: | function(_p1)
{
return 0
} |
only one return per function, but exceptions are possible
(since some weeks) a preceding underscore character "_" on parameters
case of function-, command-, variable-names etc matching like in documentation, for example: MsgBox over msgbox.
avoiding globals in functions
to tell just some of them. |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2381
|
Posted: Sun Jan 06, 2008 8:58 pm Post subject: |
|
|
| As an IT tech I spoke to recently said "The problem with Standards is that there are so many to choose from..." |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|