I like the way Perl makes ,comma optional terminators rather than required separators or terminators in constructs like ordinary and associative arrays. It allows you to put one entry per line, and easily comment-out an entire line without having to rejigger the syntax to add or replace a ,comma that may or may not be necessary depending on whether adjacent lines have been commented in or out.
Indeed, several significant programming languages have added this sort of thing late, several versions in, when they realize that programmers were asking for it. I think this sort of thing can now be considered a BKM in the design of programming language syntax.
Code: Select all
$ bash $> cat EXAMPLE-Perl-independent-lines.pl
@a = (
1,
# 2, # <--- comment-out an entire line
3,
);
%h = (
a => 1,
# b=>2, # <--- comment-out an entire line
c => 3,
);
foreach $v ( @a ) { print "<$v>"}; print "\n";
foreach $k ( sort keys %h ) { print "[$k$h{$k}]"}; print "\n";
OK
$ bash $> perl ./EXAMPLE-Perl-independent-lines.pl
<1><3>
[a1][c3]
OK
AutoHotKey does not support this sort of thing.
Code: Select all
;; AHK syntax is *not* Perl-like, and does *not* facilitate independent lines.
;; This code is not accepted by AutoHotKey.
a := [
1,
2,
3,
]
h := {
a:1,
b:2,
c:3,
}
The closest I have been able to come to this in AutoHotKey is as follows: to have dummy 0 elements at the beginning and end of a and AutoHotKey array, and 0:0 elements at the beginning and end of an AutoHotKey associative array/object. I have to arrange to have the code using these linear and associative arrays skip the placeholder elements. If 0 and 0:0 are not acceptable as placeholders because those keys and values are needed, I have to come up with others.
Combining this with AutoHotKey's line continuation, I get the following:
Code: Select all
a := [0
, 1
, 2
, 3
,0]
h := {0:0
, a:1
, b:2
, c:3
,0:0}
I wonder if anybody has a better way?
-----------
In case anyone cares, I like this approach that allows individual lines clauses or sub expressions to be commented-out so much that I often write code like
Code: Select all
if(0
|| expr1
;; || expr2 ; <-- disabled his part of the expression
||
||0)
{
...
}
Code: Select all
msgbox,% ""
. "Title:"
. "`n" . "thing #1: " . thing1
;;. "`n" . "thing #2: " . thing2
. "`n" . "thing #3: " . thing3
Code: Select all
my_notification_fn("message"
, { 0:0
, msgbox: "longer message"
, timeout: 1.5
, tooltip: "short message"
, tts_say_through_speakers: "problem"
, 0:0 }