Wednesday, 29 July 2015

JavaScript Variable Names

In schappo.blogspot.co.uk/2015/06/php-variable-names.html I explained how PHP variable names are determined at the byte level. JavaScript variable names are determined at a higher level and are defined in terms of Unicode Properties and General Categories.

Letʼs start with some simple Basic Latin variable name examples.
  • Valid Names:  nottingham  nottingham8
  • Invalid Name:  8nottingham
where 8 is Unicode character U+0038 DIGIT 8. The last name, above, being invalid because it begins with a digit.

We are in the Unicode age and so do not need to restrict ourselves to Basic Latin. Some time ago I asked myself whether the same Basic Latin rule, an initial digit is invalid, applies to other Scripts and yes it does (well mostly).
  • Valid Devanagari Names:  नाटिंघम  नाटिंघम६
  • Invalid Devanagari Name:  ६नाटिंघम
where ६ is Unicode character U+096C DEVANAGARI DIGIT SIX
  • Valid Thai Names:  นอตทิงแฮม  นอตทิงแฮม๘
  • Invalid Thai Name:  ๘นอตทิงแฮม
where ๘ is Unicode character U+0E58 THAI DIGIT EIGHT
  • Valid Telugu Names:   నాటింగ్‌హామ్  నాటింగ్‌హామ్౬
  • Invalid Telugu Name:  ౬నాటింగ్‌హామ్
where ౬ is Unicode character U+0C6C TELUGU DIGIT SIX
  • Valid Chinese Names:  诺丁汉  诺丁汉八  八诺丁汉
where 八 is the digit 8, aka Unicode character U+516B CJK UNIFIED IDEOGRAPH-516B

So, Unicode CJK Ideographs are the exception as a name can begin with a digit. Unicode CJK Ideographs encompass Chinese Hanzi, Japanese Kanji and Korean Hanja. The reason for this exception is because of the Unicode General Category to which these digits are assigned. The digits 8, ६, ๘, ౬ have the General Category Nd which is Decimal Number and thus, cannot be the first character of a variable name. 八 has the General Category Lo which is Other Letter and thus, can be the first character of a variable name even though semantically it is a digit.

The above holds true for ECMAScript 5 and 6 and possibly earlier versions but it is unlikely I will test earlier versions. You can validate your variable names online at mothereff.in/js-variables.

For further reading I suggest:

Friday, 17 July 2015

Multilingual PDF

There is an OS X extension lpdf, which is the Multilingual PDF of the title of this blog article. Letʼs look at System Information.app with terminal.

find . -name '*.lpdf'
./Contents/Resources/ProductGuides/productinfo1.lpdf
./Contents/Resources/ProductGuides/productinfo2.lpdf
./Contents/Resources/ProductGuides/productinfo3.lpdf
./Contents/Resources/ProductGuides/regulatory-022-00023.lpdf
./Contents/Resources/ProductGuides/regulatory-022-00272.lpdf
./Contents/Resources/ProductGuides/regulatory-022-00432.lpdf
./Contents/Resources/ProductGuides/regulatory-022-00458.lpdf
./Contents/Resources/ProductGuides/regulatory-022-00459.lpdf
./Contents/Resources/ProductGuides/regulatory-022-00465.lpdf
./Contents/Resources/ProductGuides/regulatory-022-00466.lpdf
./Contents/Resources/ProductGuides/regulatory-022-5167.lpdf
./Contents/Resources/ProductGuides/regulatory-022-6097.lpdf
./Contents/Resources/ProductGuides/regulatory-022-6098.lpdf
./Contents/Resources/ProductGuides/regulatory-022-6346.lpdf
./Contents/Resources/ProductGuides/regulatory-022-6347.lpdf


Looking inside, for example, productinfo1.lpdf/Contents/Resources we can see a set of lproj directories.
ar.lproj es.lproj id.lproj pl.lproj th.lproj ca.lproj es_MX.lproj it.lproj pt.lproj tr.lproj cs.lproj fi.lproj ja.lproj pt_PT.lproj uk.lproj da.lproj fr.lproj ko.lproj ro.lproj vi.lproj de.lproj he.lproj ms.lproj ru.lproj zh_CN.lproj el.lproj hr.lproj nl.lproj sk.lproj zh_TW.lproj en.lproj hu.lproj no.lproj sv.lproj
The above directory names are of the form language tag.lproj. Languages include: ar (arabic), fr (french), ja (japanese), ko (korean), th (thai) and zh_CN (chinese in China). Inside each of the above directories is a language localized productinfo1.pdf e.g. ko.lproj contains a productinfo1.pdf which is the Korean language version of the document.

More concisely: A lpdf is an OS X Package containing a set of language localized PDFs.

Note: This exploration of lpdf was carried out using OS X Yosemite 10.10.4.