Good names are golden

Names are an important part of programming. They should be relatively easy to create. Up until this development point, I wasn’t making that the case, and because of that, things were looking alot more difficult.

After some deliberation, it seems permitting numbers and possible symbols in names would greatly speed up code writing and reading. While in some ways, it makes code more error-prone and less readable, in other ways, it decreases the likelihood of typos and saves stress in typing and reading.
Consider the following: C++ and Copper with and without numbers and symbols in names:

98 % ( 7 * a - 3 )

int_mod(98 int_rcd(int_mul(7 a:) 3))

int%(98 int-(int*(7 a:) 3))

I save about 9 characters here in such a short section.
The benefits and readability can be further shown in longer names. Again, I compare the same three options:

matrix2x2::operator+= (vector2d v) {
	setVector(v + getVector(0), 0);
	setVector(v + getVector(1), 1);

matrix_twoBytwo_vect_twoD_sum = [m v] {
	m1 = Matrix_twoBytwo_get_vector(m: 0)
	m2 = Matrix_twoBytwo_get_vector(m: 1)
	Matrix_twoBytwo_set_vector( Vect_twoD_sum(v: m1:) 0 )
	Matrix_twoBytwo_sec_vector( Vect_twoD_sum(v: m2:) 1 )

matrix2x2+vect2 = [m v] {
	m1 = Matrix2x2_get_vector(m: 0)
	m2 = Matrix2x2_get_vector(m: 1)
	Matrix2x2_set_vector( Vect2d_sum(v: m1:) 0 )
	Matrix2x2_sec_vector( Vect2d_sum(v: m2:) 1 )

The last one might be confusing and might be more appropriately named “matrix2x2_vect2_sum”, but even that happens to be shorter than what I’m currently forcing.
Therefore, I’ve decided to allow numbers and symbols in names. Each option (numbers or symbols) can be separately enabled and disabled via preprocessor macro.
Incidentally, at first I had dreamed of writing code this way but I was (and sort of still am) afraid that it will lead to minor little errors in coding. Alas, such is the nature of making a sloppy syntax language.

Going further

Suppose I wanted Unicode names.

家.家族 = [
	父 = "としひろ"
	母 = "渚"

I don’t want to incorporate an entire Unicode library into the core of the virtual machine. That would bloat it, and I suspect most people who would want to use Copper have no need for Unicode within the actual code region (note: binary is currently permitted within strings, so that allows UTF-8, and you can easily add a filter if you expect use input scum).
To compensate, I decided to add a function to the engine that allows users to perform their own valid name checking. Here, they could perform UTF-8 checking if they decide to incorporate a library for doing so. They can also use it to allow or forbid characters such as numbers in names.

Branch notice: The options here are available for both the original syntax branch and the new one.

Note: The Copper VM allows for custom name filters, so you can allow or prohibit anything you want at a slight initial cost.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s