Syntax and naming conventions?

Talk about anything
Xeilous
Posts: 12
Joined: 04 Feb 2018, 04:06

Syntax and naming conventions?

13 Feb 2018, 12:12

What sort of naming conventions and syntax do you use(if any) when writing your code. I find myself changing portions of my code until "I like it."

Just wanting to get some different perspectives here, because I see all sorts of variations out there. I know Autohotkey is case-insensitive, and so it doesnt usually matter how you write things.

Variable & Function Names:
I always use camelCase
I always use the := operator, even when it's not necessary.
I always put spaces around the operators.

Code: [Select all] [Download] GeSHi © Codebox Plus

firstName := "John"
lastName := "Doe"
firstLast := firstName " " lastName


Others:
I'll add more after I get off work, just wanted to start the discussion for now.
Last edited by Xeilous on 13 Feb 2018, 16:17, edited 1 time in total.
User avatar
nnnik
Posts: 3204
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Syntax and naming conventions?

13 Feb 2018, 14:26

I use camelCase for variables, methods and function names.
I use CamelCase for class names.
I always use the := operator.
I always use the . operator to combine strings.
Lately I've started to use OTB.
I use a space after every comma. I use spaces before and after surrounding brackets.
I use [] for properties even if it isn't eneccessary. I use () with new even when it isn't neccessary.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Recommends AHK Studio
User avatar
tidbit
Posts: 1088
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Syntax and naming conventions?

13 Feb 2018, 15:36

never use := %
:= is an expression.
single % forces a non-expression to an expression.
since := is an expression, single % is useless.
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
Xeilous
Posts: 12
Joined: 04 Feb 2018, 04:06

Re: Syntax and naming conventions?

13 Feb 2018, 16:15

Just noticed I did that by accident lol, typing this all out on my phone. I don't actually do the := % thing.

I think I did that because I'm so used to typing MsgBox, % varOne " " varTwo. That's where I got that from.
User avatar
Trogluddite
Posts: 8
Joined: 23 Mar 2018, 06:42

Re: Syntax and naming conventions?

23 Mar 2018, 15:45

Pretty much as described already for variable/function/method names. I'm not a big fan of CamelCase generally, but it seems to be the de-facto standard for AHK.
  • I drop my leading braces down a line - I blame a workplace style guide from years ago where OTB was frowned upon for some reason.
  • Arguments always in parentheses for functions and methods, spaces after commas but not around the parentheses
  • Indent levels are two spaces.
  • Double indent for a continuation line.
  • Two leading underscores for anything I consider "private".
  • Single leading underscore for arguments and locals (another bad habit picked up years ago. :oops: )
  • Assignment operators lined up if there is any chance I'll need to column edit a run of lines.
  • SCREAMING_SNAKE_CASE for "constants" (static globals.)
  • Double blank lines between method and class definitions.
  • Single blank lines within definitions to separate 'paragraphs' of code.
  • One class per file if it's a big project.
  • Endless hours of tinkering with whitespace and renaming everything umpteen times!

That's for AHK anyway. For other languages, I'll generally try to adopt what is commonly accepted if there is any kind of standard (e.g. slithering_snake_case for methods/variables in Ruby.)
User avatar
Cerberus
Posts: 95
Joined: 12 Jan 2016, 15:46

Re: Syntax and naming conventions?

03 Jun 2018, 22:43

Trogluddite wrote:Pretty much as described already for variable/function/method names. I'm not a big fan of CamelCase generally, but it seems to be the de-facto standard for AHK.
  • I drop my leading braces down a line - I blame a workplace style guide from years ago where OTB was frowned upon for some reason.
  • Arguments always in parentheses for functions and methods, spaces after commas but not around the parentheses
  • Indent levels are two spaces.
  • Double indent for a continuation line.
  • Two leading underscores for anything I consider "private".
  • Single leading underscore for arguments and locals (another bad habit picked up years ago. :oops: )
  • Assignment operators lined up if there is any chance I'll need to column edit a run of lines.
  • SCREAMING_SNAKE_CASE for "constants" (static globals.)
  • Double blank lines between method and class definitions.
  • Single blank lines within definitions to separate 'paragraphs' of code.
  • One class per file if it's a big project.
  • Endless hours of tinkering with whitespace and renaming everything umpteen times!

That's for AHK anyway. For other languages, I'll generally try to adopt what is commonly accepted if there is any kind of standard (e.g. slithering_snake_case for methods/variables in Ruby.)


I love SCREAMING_SNAKE_CASE! I think henceforth I'll USE_HIM_FOR_EVERYTHING!!!1ONEONE

Return to “Offtopic”

Who is online

Users browsing this forum: No registered users and 13 guests