Does any other language other than JavaScript have a difference between brace start locations (same line and next line)?-Collection of common programming errors

The first language where I came across this was awk (which also has its share of syntax “oddities”; optional semi colons, string concatenation using only whitespace and so on…) I think the DTrace designers, which based the D syntax loosely on awk, had enough sense to NOT copy these features, but I can’t remember off the top of my head. A simple example (counting the number of ENTITY tags in a DTD, from my Mac):

$ cat printEntities.awk 
# This prints all lines where the string ENTITY occurs
/ENTITY/ {
  print $0
}
$ awk -f printEntities.awk < /usr/share/texinfo/texinfo.dtd | wc -l
     119

If this little script instead were written with the brace on a line of its own, this is what would happen:

$ cat printAll.awk 
# Because of the brace placement, the print statement will be executed
# for all lines in the input file
# Lines containing the string ENTITY will be printed twice,
# because print is the default action, if no other action is specified
/ENTITY/
{ 
   print $0 
}
$ awk -f printAll.awk < /usr/share/texinfo/texinfo.dtd | wc -l
     603
$ /bin/cat < /usr/share/texinfo/texinfo.dtd | wc -l
     484
$ 

Originally posted 2013-11-09 23:38:46.