Syntax and naming conventions?

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Syntax and naming conventions?

Re: Syntax and naming conventions?

Post by Cerberus » 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

Re: Syntax and naming conventions?

Post by Trogluddite » 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.)

Re: Syntax and naming conventions?

Post by Xeilous » 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.

Re: Syntax and naming conventions?

Post by tidbit » 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.

Re: Syntax and naming conventions?

Post by nnnik » 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

functionName( argumentName1, argumentName2 ) {
	return new ClassName1()
}
functionName2( singleArgument ) {
	return 42
}
class ClassName1 {
	property[] {
		get{
			return "Hello" . " World" . "!"
		}
		set{
		}
	}
}

Syntax and naming conventions?

Post by Xeilous » 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

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.

Top