notation: parameter could be a variable or an object Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 6371
Joined: 19 Dec 2016, 01:58
Location: UK

notation: parameter could be a variable or an object

20 Jan 2018, 15:22

- Sometimes when I'm writing a function, or elsewhere, I have a parameter that could be a variable or an object.
- One of the most obvious examples of this is an object loop. I usually use 'vValue', expecting a string/number, but it could be an object.

Code: Select all

for vKey, vValue in oArray
	vOutput .= vKey " " vValue "`r`n"
- I'm not really sure what the best notation is that I could use for this. But I know I should incorporate *some* system, to make some of my scripts/functions clearer.
- Some possibilities. None are great.
vTextORoArray
oArrayORvText
voTextOrArray
ovArrayOrText
xTextOrArray
xArrayOrText
- Has anyone else had this problem, or come across/considered a solution? Cheers.

- [EDIT:] A related point. I have a function that can accept an hMenu or an hWnd, based on the options parameter.
- Possibilities. Again, not great.
hMenuORhWnd
hMenuOrWnd

- [EDIT:] Also related. An array of structs. E.g. MCM_GETSELRANGE requires a struct that is two SYSTEMTIME structures back-to-back. If I have one SYSTEMTIME structure, I called the variable SYSTEMTIME. But what about multiple SYSTEMTIME structures.
- A possibility. So-so.
ArraySYSTEMTIME
[EDIT:] or arrSYSTEMTIME
- Note: I don't use prefixes with struct names, or constants, but I'm tempted to, because prefixes to indicate variable or object always make things easier.
- Note: In this context the word 'array' is used, but it is what I would usually call a 'variable' (text/string/binary data), and not an 'object' (array/COM object).
Last edited by jeeswg on 21 Jan 2018, 07:24, edited 2 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
derz00
Posts: 497
Joined: 02 Feb 2016, 17:54
GitHub: derz00
Location: Middle of the round cube

Re: notation: parameter could be a variable or an object

20 Jan 2018, 17:50

jeeswg wrote:

Code: Select all

for vKey, vValue in oArray
	vOutput .= vKey " " vValue "`r`n"
if vValue was an object, why put it in a string? if it is a string, why not call it "Book_Title" or "File_Name" ?

Usually I would name the variable after its contents. Or when golfing/cutting corners 1- or 2-letter variable names are handy. :)
try it and see
...
wolf_II
Posts: 2585
Joined: 08 Feb 2015, 20:55

Re: notation: parameter could be a variable or an object

20 Jan 2018, 18:09

If you use vValue or vText, the v-prefix carries no info other than "It's not a function name". The nature of what content there is follows the prefix.
So you could push a bit further and regard a "mismatching prefix" as added info. E.g.: oText is plain text or array of plain text, oValue means we can expect regular value or an array of regular values.
Helgef
Posts: 3703
Joined: 17 Jul 2016, 01:02
Contact:

Re: notation: parameter could be a variable or an object

20 Jan 2018, 19:28

It is oBviously a voValue ;)
If I had a collection of something undecided, I'd call it something generic, like,

Code: Select all

for k, item in items
	if isobject(item)
		; 
	else
		; 
I couldn't cope adding all the vs and os, even if I thought it had any value. What is readable is very personal. I cannot read my own code (months/years later) if I do not make a lot of comments.
I have a function that can accept an hMenu or an hWnd, based on the options parameter.
Sounds like you need two functions ;).

Cheers.
User avatar
jeeswg
Posts: 6371
Joined: 19 Dec 2016, 01:58
Location: UK

Re: notation: parameter could be a variable or an object

20 Jan 2018, 20:24

- See JEE_MenuGetText/JEE_MenuGetTextAll, here:
GUIs via DllCall: get/set internal/external control text - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=40514
- For example, it's good to be able to specify the hWnd for menu bars, or an hMenu for a visible context menu (e.g. that you get via MN_GETHMENU).
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6371
Joined: 19 Dec 2016, 01:58
Location: UK

Re: notation: parameter could be a variable or an object

31 Jan 2018, 18:39

A related problem.
If a function typically returns an object, but the function fails for some reason, should it return an empty object, or should it return a blank string.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6371
Joined: 19 Dec 2016, 01:58
Location: UK

Re: notation: parameter could be a variable or an object  Topic is solved

09 May 2018, 15:16

A solution, as specified here:
your personal AutoHotkey style guide - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 28#p212128
[solution: choose 'o' or 'v' as the default, do an IsObject() check at the start of the function, and create a new 'o'/'v' variable if needed][also: add a comment above the function explaining that the parameter can accept a string or an object]
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: asad41163, Bing [Bot], frd, Google [Bot], Odlanir and 138 guests