New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v1: Added A_Comma, A_DQ/A_SQ, A_CR/A_CRLF/A_LF. #295
Conversation
If I were you I'd slam all those things into a separate ahk file, place it in the global Lib folder and #include it only where and when necessary. Did that with variables required for AHK_L <=> AHK Basic compatibility and it works just fine. |
@Drugwash2: The same thing applies when you want to share a quick bit of code to a forum ... In general, it simplifies things to use as few dependencies as possible. |
Something else to consider:
For what it's worth I personally never felt the need to replace a comma with a seven-letter placeholder, nor the other suggested BIVs. It's all about coding style, and it would be interesting to find out how many AHK coders would really really need all those BIVs. By the number of comments in the thread you linked to it doesn't look like there would be many. But maybe I'm wrong. Or maybe not. After all it's just a personal opinion. |
@Drugwash2: |
I've observed the comments here re. single/double quotes: Single quotes
Single quotes are just as problematic as double quotes, they just never needed escaping in AHK v1, because you couldn't define strings with single quotes.
What users are asking forIn the comments, people want:
Quote/Quot/Q and Apos/QQ v. DQ and SQIf CR and LF weren't common, people would be suggesting There is a precedent for SQ and DQ: I considered various short variable names, but felt Anyone suggesting The words 'single'/'double' and 'quote'/'quotation' appear in that order in the AHK documentation already, and commonly appear in that order in Unicode character names: Other pointsFormatted strings. I'd welcome something like one or both of these, but still feel
|
I find it clearer and more elegant to use single quoted strings, with syntax highlighting. Escaped double quotes aren't much worse with proper highlighting. |
I particularly wanted Single Quote AvoidanceI avoid using single quotes to define strings. (Also, a personal preference, I find single quotes for string definitions, a bit silly-looking.) The one place where single quotes could be used, that I'd approve of, is code in a string, for an Using
Backtick AvoidanceIf not using single quotes, that only leaves: (I sometimes store lists of characters as strings, and select the string to count the characters.) (Also, it's not great if copying/pasting between multiple languages.) Syntax Highlighting Dependence AvoidanceAgain, personal preference, I prefer not to depend on syntax highlighting. (People often overcomplicate their code structures and coding setup.) Libraries and Two-way CompatibilityI'm working on a massive library, to share, that is intended to be AHK v1/v2 two-way compatible.
|
Documentation
A_Comma. This variable contains a comma character.
A_CR. This variable contains a carriage return (CR) character.
A_CRLF. This variable contains two characters: a carriage return (CR) and a newline (linefeed/LF).
A_DQ. This variable contains a double-quote mark.
A_LF. This variable contains a newline (linefeed/LF) character.
A_SQ. This variable contains a single-quote mark.
Descriptions based on:
Escape Sequences - Definition & Usage | AutoHotkey v2
Variables and Expressions - Definition & Usage | AutoHotkey v2
There is a precedent for SQ and DQ:
Syntax - IBM Documentation
Computing Fundamentals and Programming in C - Nasib Singh Gill - Google Books
Comments
A_DQ / A_SQ
I define and use a custom
DQ
variable for double quotes very very regularly, and would benefit greatly from a BIV (built-in variable).(E.g. in my main function libs:
vDQ := Chr(34)
appears 57 times,Chr(34)
appears 395 times.)Quite often, I'm writing some quick code, and I wish that
A_DQ
were available.I've tried
A_Quote
, but it uses too much screen real estate, so is impractical for many use cases such as: command-line strings, or strings with multiple quote characters. It is as long asChr(34)
, 7 characters, which is also rather long.Also, if it was
A_Quote
, what about a single quote equivalent?A_Apos
for apostrophe? HenceA_DQ
andA_SQ
.Comparisons: the BIVs are short, readable from a distance, meaningful ('DQ' v. '34') and v1/v2 compatible:
A_CR / A_CRLF / A_LF
E.g. VBA has
vbCrLf
,vbCr
,vbLf
andvbTab
, amongst others.Miscellaneous constants | Microsoft Docs
I chose all capital letters, because they're easier to type and look more elegant. (You can hold shift the whole time.)
Some uses:
\\\n
)."abc`ndef"
is bad for spellchecking versus"abc`n" "def"
or"abc" A_LF "def"
. I.e. there is no word 'ndef'.vbCrLf
or equivalent, and just replace the variable names, without worrying about defining variables.var = "abc" "def"
lines in AHK v1, in preparation for AHK v2. WithA_DQ
unavailable, you have to pick a short but custom variable (requiring storing a variable definition somewhere), or the long and readability-reducing but universalChr(34)
.A_DQ
, short and universal, gives you a simple solution.A_Comma
Useful to make it more explicit that a comma is being used.
E.g. in a function call full of literal and parameter-separating commas.
Or similarly for a command in AHK v1.
Also, in situations where there are known to be no literal commas, quick-and-dirty parsing algorithms can be written more simply.
Test code