Basics for Writing Programs

Before diving into various syntax elements, let's first grasp the basics of starting to write programs.

- Table of Contents -

Three Rules to Remember

Programming languages come with rules for coding, which you typically learn gradually through reading sample programs and writing your own code. This guide follows a similar approach.

However, when you're just starting and unfamiliar with any rules, it can be unclear where to start when reading or writing programs. Let's begin with three fundamental rules:

Rule 1: Sequentially Write the Desired Processes in the Program

This is the most important rule. VCSSL, like other procedural programming languages, generally executes processes in the order they are written.

Although there are situations where the order of execution may change due to functions or control statements, the basic principle is to maintain the order they appear in the script.

Rule 2: End Each Unit of Process (Statement) with a Semicolon ";"

Each process should be written as a cohesive unit known as a "statement." In languages that adopt C-style syntax, it's common to end each statement with a semicolon ";". VCSSL adheres to this convention, requiring a ";" at the end of each statement.

Rule 3: Enclose Text Meant to Be Treated as Character Strings in Double Quotes

In programming, you often need to treat a sequence of characters, such as "abc," as data. However, when you write text directly into the program, it's unclear whether it's part of the code to be executed or data representing character strings. Therefore, text intended as character strings must be enclosed in double quotes ( " ).

Note: In programming, a sequence of characters treated as data within the program is referred to as a "character string" or simply "string." While this might seem an unusual term in general, it's a quite common term in the programming world.

An Example Using Rules 1-3 in Action

Now that we've covered the essential rules to remember, let's see these rules applied in an example.

SequentialPopup.vcssl

In this code, we use the 'popup' function, which opens a small window displaying a specified message or value. The content to be displayed is specified inside the parentheses (), enclosed in double quotes " ".

When you run this program, the following happens:

A small window pops up, displaying "Hello."

(You press "OK" to close the window.)

A small window pops up, displaying "World."

(You press "OK" to close the window.)

A small window pops up, displaying "!"

As the above, the program executes each statement sequentially from the beginning to the end, displaying the contents of strings "Hello," "World," and "!" one after the other.

Common Pitfalls to Watch Out For

When starting out with programming, there are several common pitfalls that beginners often fall into. Let's enumerate and introduce some of them here.

Be Mindful of Confusing Half-width and Full-width Characters!

In programming languages, there are many rules regarding the use of specific symbols, such as "use the '+' symbol for addition." However, since there are many characters available on a PC that look similar but are actually different, it's important to be careful not to confuse them.

A common mistake is confusing "half-width" and "full-width" characters. Half-width characters are the standard characters input from the keyboard in English mode, whereas full-width characters are wider and often used in languages like Japanese. Here are examples:

- Half-width Characters (Standard) -
ABCDE abcde 12345 +-*/ "


- Full-width Characters (Wider) -
`abcd@@PQRST@{[^@h

Notice the differences? In programming, you generally need to use half-width (standard) characters. Using full-width characters by mistake will cause errors, especially since "full-width spaces" can be difficult to spot.

Explicitly Specify Character Encoding to Prevent Character Garbling

There are instances within a program where full-width characters are necessary. A typical example is within "string literals" enclosed by double quotation marks, such as when writing messages in Japanese or other languages that use full-width characters like "."

In these cases, "character garbling" can occur. This happens when the character encoding used to save the program file differs from the one used when loading it for execution. While "UTF-8" has become the standard encoding for both saving and reading files in many environments, mismatches can still occasionally lead to garbling.

To prevent this, explicitly specify the character encoding at the beginning of your program. For example, for Shift_JIS:

coding Shift_JIS;

And for UTF-8:

coding UTF-8;

This declaration ensures that your program will be loaded using the specified character encoding, preventing garbling.

Useful Feature : Comments

Finally, let's cover the convenient "comment" feature, which is not essential but handy to know. Comments allow you to write notes within your program. The contents of comments are skipped during execution, so they do not affect the program's behavior. In VCSSL, the syntax for comments follows the C language style.

Single-line Comments Begin with "//" at the Beginning of the Line

First, let's look at comments that fit within a single line. For these, you start the comment with "//" (double slashes). Here's an example:

CommentLine.vcssl

When executed, only the comments are skipped:

Hello
World

You can also write comments in the middle of a line, and everything after "//" on that line will be treated as a comment:

CommentLineFromMiddle.vcssl

The result when executed will be the same as before.

Multi-line Comments are Enclosed with "/*" and "*/"

Next, let's discuss comments that span multiple lines. For these, you enclose the comment with "/*" (slash and asterisk) at the beginning and "*/" (asterisk and slash) at the end. Everything between these markers will be skipped during execution. Here's an example:

CommentBlock.vcssl

When executed, the output will be:

Hello
World

As shown, the comment section is skipped. Additionally, in VCSSL, multi-line comments using "/*" and "*/" can be nested, allowing for multiple levels of hierarchical structure, which differs slightly from the C language.

Acknowledgement: We greatly appreciate the cooperation of two ChatGPT AIs in translating this page.
» How we translated this page