your personal AutoHotkey style guide

Talk about anything
wolf_II
Posts: 2299
Joined: 08 Feb 2015, 20:55

Re: your personal AutoHotkey style guide

03 Sep 2018, 04:57

I would choose MyFunc1. Preferences change over time, but the fact that the function returns either one of two value is for my eyes more visible in MyFunc1.

Tomorrow, I might want to emphasize the fact of "default behaviour" being False. Then I might choose MyFunc2, with an extra empty line before the return statement, like I often do for more possible results to choose from.

Code: Select all

If (isSpecialCase1 = True)
    Return, "Bingo"
If (isSpecialCase2 = True)
    Return, "Bongo"

; default
Return, "Bungo"    
I guess, my personal style prefers to put similar Return statements at similar indentation levels.
User avatar
jeeswg
Posts: 5447
Joined: 19 Dec 2016, 01:58
Location: UK

Re: your personal AutoHotkey style guide

19 Sep 2018, 18:14

- Often, when writing scripts, I might choose an object's variable name based on what the keys are, e.g. oPID.
- But it can be unclear what values that object contains, so perhaps a better name would be oPIDToHWnd.
- Even with this, the syntax can get quite confusing regarding the order, e.g. hWnd := oPIDToHWnd[vPID].
- But if you were to add an hWnd key for each PID, it seems like overkill, e.g. hWnd := oPID[vPID].hWnd.
- hWnd := oHWndFromPID[vPID] isn't great.
- ObjGetValueByRef(oPIDToHWnd, vPID, hWnd) perhaps. Hmm.
- I wondered what other people thought.
Helgef
Posts: 3307
Joined: 17 Jul 2016, 01:02
Contact:

Re: your personal AutoHotkey style guide

21 Sep 2018, 03:12

using To make no sense imo. I'd do it like this, hwnd := hwnds[ pid ], it clearly shows the association between pid and hwnd in a list of hwnds. When you first create the hwnds array, make a comment describing it. Prefixing o or v only clutters the view imo.

Cheers.
User avatar
nnnik
Posts: 3563
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: your personal AutoHotkey style guide

21 Sep 2018, 03:28

Or make a function which is descriptive and keep using your unreadeable names.
Yeah using o and v makes no sense. It doesn't tell you anything at all.
v means value - yeah great what kind of value? Is it float a string or an integer? Maybe a boolean or you expect a hex string?
o is even worse. It tells you its an object but what kind of object? Is it a function object a menu item or maybe even a self defined image object?
o and v contain no information whatsoever. Having descriptive names is more important.
And what do you do if the variable can be a callable object or a function name?
Recommends AHK Studio
User avatar
jeeswg
Posts: 5447
Joined: 19 Dec 2016, 01:58
Location: UK

Re: your personal AutoHotkey style guide

21 Sep 2018, 04:37

- To me, the main problem when reading code is to know what is a variable and what isn't. Whether the language is familiar or unfamiliar.
- I can instantly see what is a variable in my code, other people's code takes longer to read/debug. This is particularly true of LaTeX for example.
- (Using a letter prefix means that you can use CamelCase for functions and vCamelCase for a variable name, and I find 'camelCase' for variable names awful, and 'var_name' unfortunate.)
- (To use the word 'unreadable' seems a bit perverse, I was converting some code today and noticed how much more readable it was becoming with the 'v' prefixes and CamelCase.)
- My naming system makes it very easy to identify/enumerate/replace variables (and to not accidentally replace words in comments), and to spot unusual entries in the variables list.
- I don't think people appreciate how quick and easy my systems make it to code.
- In some (many/most?) languages: XXX(), this could be a function or a variable. So you need some kind of identifier. So perhaps a prefix e.g. sXXX, or the use of numbers as a suffix: XXX1. I'm moving to the latter for languages that enforce types since there are just too many types (and thus prefixes).
- I use vFunc and oFunc for function names and function objects(/bound funcs).
- (There's a logic to using oHWnds/oPIDs instead of oHWnd/oPID, but I find it neater without the 's'.)
User avatar
nnnik
Posts: 3563
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: your personal AutoHotkey style guide

21 Sep 2018, 05:08

Its more readeable because your used to it. I'm not used to it so its not readeable to me.
Also in other languages like python or javascript there is not a single difference between a variable and a function.
I really assumed you had at least the sense to choose something different than variable as the long version for v.
Everything you put that v in front is a variable. But also everything you don't put this in front of.
Essentially there is no difference between a variable and a function in many languages.
It's pushed the furthest in languages like python or javascript where you cannot have function but only references to function types.
What you say is the most senseless thing I've heard of you since quite a while - you are once again loosing any contact with the actual reality of programming and development.
Thus I will not respond any further - since it would be a massive waste of time.
Recommends AHK Studio
User avatar
jeeswg
Posts: 5447
Joined: 19 Dec 2016, 01:58
Location: UK

Re: your personal AutoHotkey style guide

21 Sep 2018, 05:43

I really assumed you had at least the sense to choose something different than variable as the long version for v.
Everything you put that v in front is a variable. But also everything you don't put this in front of.
- I don't understand this point. Use something other than 'v', like what?
- I use 'v' for non-object variables and nothing else.
What you say is the most senseless thing I've heard of you since quite a while - you are once again loosing any contact with the actual reality of programming and development.
Thus I will not respond any further - since it would be a massive waste of time.
- I don't know what you're referring to. I said that variables and functions can look(/be) similar in some languages, which you agreed with.
- (Let's pretend that I didn't know that. There are all sorts of things that people happen not to know. You could be gentler with people.)
- (You're using words/phrases like 'senseless'/'losing touch with reality'/'waste of time' over literally nothing. This can be bad because you can mislead people reading your comment.)

- Here is my view on variable names:

Code: Select all

InStr(vText, vNeedle, vCaseSen, vPos, vOcc) ;preferred
InStr(text, needle, caseSen, pos, occ)
InStr(text, needle, case_sen, pos, occ)

SplitPath, vPath, vName, vDir, vExt, vNameNoExt, vDrive ;preferred
SplitPath, path, name, dir, ext, nameNoExt, drive
SplitPath, path, name, dir, ext, name_no_ext, drive
- Another advantage of my system is that you can stick in an extra word at the start, without having to change the capitalisation. And that key words always start with a capital (useful when searching).

Code: Select all

vPath -> vPfxPath
path -> pfxPath
path -> pfx_path
User avatar
jeeswg
Posts: 5447
Joined: 19 Dec 2016, 01:58
Location: UK

Re: your personal AutoHotkey style guide

25 Sep 2018, 14:20

On Stack Overflow, it seems that all the Java for/while examples use curly braces for one-liners even if they're not required e.g.:
java - Regex to find all matches - Stack Overflow
https://stackoverflow.com/questions/328 ... ll-matches

Code: Select all

//with
    while (m.find()) {
        matches.add(m.group(0));
    }

//without
    while (m.find())
        matches.add(m.group(0));
What's more common, use or don't use? Are they using some official/unofficial Java style guide?
User avatar
SL5
Posts: 497
Joined: 12 May 2015, 02:10
GitHub: sl5net
Contact:

Re: your personal AutoHotkey style guide

27 Sep 2018, 02:36

jeeswg wrote:On Stack Overflow, it seems that all the Java for/while examples use curly braces for one-liners even if they're not required e.g.:
java - Regex to find all matches - Stack Overflow
https://stackoverflow.com/questions/328 ... ll-matches

Code: Select all

0. while (m.find()) 
    {
        matches.add(m.group(0));
    }
1. while (m.find()) {
        matches.add(m.group(0));
    }
2.    while (m.find())
        matches.add(m.group(0));
What's more common, use or don't use? Are they using some official/unofficial Java style guide?
i dont konw. i always using 2 or 1. 0 i really dont like.
with PHP i often see style 0.

i like this (nearly like 1.) https://de.wikipedia.org/wiki/Einr%C3%B ... small-Stil
User avatar
tank
Posts: 2417
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Louisville KY
Contact:

Re: your personal AutoHotkey style guide

27 Sep 2018, 09:53

Code: Select all

;YES
;~ comment
;NO
; comment

;Indentation style - Wikipedia
;https://en.wikipedia.org/wiki/Indentation_style

;YES 
Loop, 3
	{
	MsgBox
	Loop, 3
		{
		InputBox, vInput
		}
	}
;NO (K&R: one true brace)
Loop, 3 {
	MsgBox
	Loop, 3 {
		InputBox, vInput
	}
}

;NO
if (var1 = var2)
;YES
if ( var1 = var2 )

;YES
oArray := ["a", "b", "c"]
;NO
oArray := ["a","b","c"]

;YES
DllCall("MessageBox"
		, Ptr, 0
		, Str, "text"
		, Str, "title"
		, UInt, 0)
;NO
DllCall("MessageBox", "Ptr", 0, "Str", "text", "Str", "title", "UInt", 0)

;YES
MsgBox, % var "text" var var "text" "text" var "text"
;NO
MsgBox, % var . "text" . var . var . "text" . "text" . var . "text"

;YES (initial commas)
Loop, Parse, vText, `n, `r
;NO (no initial commas)
Loop Parse, vText, `n, `r

;YES (initial commas)
MouseGetPos, vCurX, vCurY, hWnd, vCtlClassNN
MouseGetPos,,, hWnd, vCtlClassNN
;NO (no initial commas)
MouseGetPos vCurX, vCurY, hWnd, vCtlClassNN
MouseGetPos ,, hWnd, vCtlClassNN

;YES
txtText
arrArray
nNumber
;NO
text
array

;YES
if !(var1 = var2)
;NO
if not (var1 = var2)

;YES
if (var1 && var2)
if (var1 || var2)
;NO
if (var1 AND var2)
if (var1 OR var2)

;OBVIOUSLY YES
var := "text"
var1 := var2
;OBVIOUSLY NO (NOTE: NOT AVAILABLE IN AHK V2)
var = text
var1 = %var2%

;YES
vText = 
(
line 1
line 2
line 3
)
;NO (the 'n' combines with the string, bad for spellchecking)
vText := "line 1`r`nline 2`r`nline 3"

;YES
vText := A_Space A_Space
;NO (never have multiple consecutive spaces)
vText := "  "

;YES (indentation of 1 tab)
if (var1 = var2)
	MsgBox
;NO (indentation of 4 spaces)
if (var1 = var2)
    MsgBox

;AMBIGUOUS CASES ...

;NEVER
if (var1 = var2)
	MsgBox
;IT'S OK (UNNECESSARY CURLY BRACES)
if (var1 = var2)
{
	MsgBox
}

;IT DEPENDS
var := 1 + 1
;IT DEPENDS
var := 1+1
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request

Return to “Offtopic”

Who is online

Users browsing this forum: No registered users and 10 guests