Style guide for Rexx, ooRexx, NetRexx, and CREXX
This style guide is maintained by Matt Ferlita with input from the RexxLA community. It is viewable and printable at https://mferlita.github.io/rexx-style-guide/
This guide does not in any way prescribe a singular “correct” way to write Rexx. Rather, it gives suggestions on best practices to create readable and consistent code to facilitate better collaboration among developers. After all, communicating with your fellow programmers is just as important as communicating with the computer.
“Enhancing readability enhances our ability to solve problems” — V. Anton Spraul, Think Like a Programmer
| Element | Format |
|---|---|
| Keyword Instructions | lowercase |
| Built-in Functions | UPPERCASE |
| Directives | lowercase |
| Methods | camelCase |
| Variables | camelCase |
| Classes and Routines | PascalCase |
| Boolean | lowercase |
/* Yes - Identifier is in English */
salary = 1000
/* No - Identifier is in Greek */
μισθός = 1000
/* No - Identifier is in Greek but spelled with Latin letters */
misthos = 1000
/* Yes - descriptive, relevant */
price = 1 + 2
total = price * 3
::method calculateTotal
/* No - generic, unclear */
values = 1 + 2
computed = values * 3
::method calc
/* Yes */
do count = 1 to max
/* No */
do c = 1 to m
Exceptions: Actual mathematical notation
/* Yes */
lineCount = 2
/* No */
lineCnt = 2
/* Yes - 3 spaces */
do forever
say "SPAM"
end
/* No - no indentation */
do forever
say "SPAM"
end
/* No - 5 spaces */
do forever
say "SPAM"
end
Use spaces around operators, after commas, colons, and semicolons.
/* Yes */
say 98 + (59872 % (13 * 8)) * 52
x = 1, 2, 3
min = 2; max = 4
/* No */
say 98+(59872%(13*8))*52
x=1,2,3
min=2;max=4
Exceptions: Exponentiation, negative integers, method send operator (twiddle), and extended assignments
/* Yes */
say -52 * 5**2
say "!elloH"~reverse
sum += 1
/* No */
say - 52 * 5 ** 2
say "!elloH" ~ reverse
sum + = sum
/* Yes */
someArray = "Apples", "Oranges", "Persimmons", -
"Lemons", "Limes", "Bergamot", -
"Pears", "Cherries", "Plums"
/* No */
someArray = "Apples", "Oranges", "Persimmons", -
"Lemons", "Limes", "Bergamot", -
"Pears", "Cherries", "Plums"
Note: “if…then” and “else if…then” count as one statement
/* Yes */
say "Hi"
say "Bye"
if someVar > 0 then
say "positive"
if lineCount > 1000 then
do
say "Warning: large file"
end
/* No */
say "Hi"; say "Bye"
if someVar > 0 then say "positive"
if lineCount > 1000 then do
say "Warning: large file"
end
if lineCount > 1000
then do
say "Warning: large file"
end
/* Yes */
price = 1 + 2
total = price * 3
taxRate = 0.08
tax = total * taxRate
say "Total: " || total
say "Tax: " || tax
/* No */
price = 1 + 2
total = price * 3
taxRate = 0.08
tax = total * taxRate
say "Total:" total
say "Tax:" tax
/* Yes - Inline Comments */
-- an inline comment (ooRexx/NetRexx/CREXX only)
/* Yes - Block Comments */
/*
* This is a block style comment
* for describing things in detail
* and grabbing attention
*/
/* This is a single line block comment. */
/* No - Block Comments */
/************************************************/
/* To the interpreter, these lines are all */
/* separate comments and could consume extra */
/* cycles, affecting performance. They eat */
/* up file space unnecessarily which could also */
/* affect performance. Lastly, they are harder */
/* to write and thus harder to maintain. */
/************************************************/
/****************************************
* This is also a no. While the block is *
* considered one comment now, it is *
* still just as hard to maintain *
* because of all the extra symbols. *
****************************************/
I suggest the following format to use at the beginning of every program:
/*
* Purpose: description
* Author: name, date (yyyy-mm-dd)
* Changed/edited: name(s), date(s) (yyyy-mm-dd)
*/
Use inline comment lines ( – ), spanning the full line length, to separate class blocks from other directives/keyword instructions and other class blocks.
/* Yes */
sum += 1
/* No */
sum = sum + 1
/* Yes */
if x \= 12 then
/* No */
if x <> 12 then
if x >< 12 then
if x ¬= 12 then
Signal should only be used for error handling.
Prefer “do while” over “do until”.
/* Yes */
do while num > 1
...stuff to do
end
/* No */
do
while num > 1
...stuff to do
end
/* Yes */
if num > 1000 then
say "big"
else if num < 1000 then
say "small"
else
do
say "One thousand"
...some other stuff to do
end
select
when num > 1000 then
say "big"
when num < 1000 then
say "small"
otherwise
do
say "One thousand"
...some other stuff to do
end
end
do while x > 100
if y > 5 then
do
say "big"
x = x + 1
end
end
/* No */
if num > 1000 then
say "big"
else if num < 1000 then
say "small"
else
do
say "One thousand"
...some other stuff to do
end
select
when num > 1000 then
say "big"
when num < 1000 then
say "small"
otherwise
do
say "One thousand"
...some other stuff to do
end
end
do while x > 100
if y > 5 then
do
say "big"
x = x + 1
end
end
/* Yes */
name = "Fred"
say "My name is " || name || "."
say 2 || "5"
say "I like " || "apple pie."
/* No */
name = "Fred"
say "My name is" name"."
say 2"5"
say "I like" "apple pie"
Don’t assume an unquoted word will be treated as a string instead of a variable.
Only use single quotes ( ‘’ ) when the string contains double quotes, to avoid escaping.
Use “signal on syntax”, “signal on error”, and “signal on novalue” and their
appropriate labels.
Use error handling only as needed for simpler programs.
...main body of code
...code
...code
/* Directives */
::class SomeClass
Portability problem when transferring code to an ASCII platform.
This guide is a work in progress. Some guidelines don’t have examples to illustrate them, others haven’t been fleshed out, and still others have not been considered yet. As such, nothing is set in stone. If you’d like to contribute, feel free to open issues or send pull requests with improvements. See contributing.md for details.
This guide is licensed under CC BY 4.0
A style guide isn’t really any use if no one uses it. If you like the guide, tell your friends, your colleagues, and share it on social media!