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 

Autohotkey coding standards (naming, etc)

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
urlwolf



Joined: 16 Mar 2006
Posts: 100

PostPosted: Sun Jan 06, 2008 12:26 am    Post subject: Autohotkey coding standards (naming, etc) Reply with quote

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
View user's profile Send private message
Guest






PostPosted: Sun Jan 06, 2008 1:19 am    Post subject: Re: AutoHotkey Coding Standards (naming, etc) Reply with quote

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 :=

    Code:
    var=thing
    var:=1

  • 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

PostPosted: Sun Jan 06, 2008 5:32 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Sun Jan 06, 2008 5:34 pm    Post subject: Re: AutoHotkey Coding Standards (naming, etc) Reply with quote

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
View user's profile Send private message Visit poster's website
Tuncay



Joined: 07 Nov 2006
Posts: 383
Location: Berlin

PostPosted: Sun Jan 06, 2008 7:45 pm    Post subject: Reply with quote

Thats a good idea to have coding standards. I am also one of the people who like standards. Like the guest (no nick chosen Mad) 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
View user's profile Send private message Send e-mail
corrupt



Joined: 29 Dec 2004
Posts: 2381

PostPosted: Sun Jan 06, 2008 8:58 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Page 1 of 1

 
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