Installation, Configuration ∞
These are not described here. See the main Mythryl page for notes on that.
Executing code directly from the commandline ∞
Put your code between ', e.g.:
my -x '6!'
TODO – better example code.
A basic script ∞
Mythryl scripts are plain text files, like regular shell scripts.
(I don’t know if Mythryl proposes an extension, but I’ve been using .my .. for example, filename.my)
Like a shell script, the first line will be a “shebang”:
#!/usr/bin/mythryl
(If you installed Mythryl somewhere else then you will need to modify this line.)
Underneath the shebang will be braces.
#!/usr/bin/mythryl { };
Curly brackets { and } surround the entire program. End the final curly with a semicolon ( ; ).
The #!/usr/bin/mythryl shebang and the braces won’t be included in this tutorial’s code snippets. Do not forget to add them!.
Don’t forget to make your script executable:
sh \chmod +x filename.my
Then you can run it like any other executable:
sh ./filename.my
Comments ∞
Line comments ∞
You can make some text not execute by commenting it. A comment begins with the hash ( # ) character and either a space or another hash.
#!/usr/bin/mythryl { # A comment ##A second comment }
Some editors provide a hotkey for commenting and un-commenting. I use Geany, and I made control-d to comment, and control-shift-d to un-comment. This is extraordinarily handy, especially for selecting multiple lines to comment or un-comment them all at once.
(There is no block-comment functionality in Mythryl!)
Effective comments ∞
These are important for effective comments:
- Explanation
- Brevity
-
Formatting
- Explanation
A comment’s role is to explain something that is not immediately obvious by looking at the code. If the code doesn’t need explanation, then don’t explain it!
If a named value name needs explanation, then you’ve probably named it wrong.
Much of the time, changes to your code will make the code clearer to understand.. largely “self-documenting”. If you learn to write code more clearly on your first pass, then you will spend less time “cleaning up the mess” by commenting afterwards.
- Brevity
Comments should be as straightforward as possible. Be blunt.
.. like this explanation. =)
- Formatting
Writing good comments is not just about adding a lot of text.
Comments which are formatted effectively will make future reading easy.
If you indent your comments a little bit, they will stand out from regular code.
If all of your comments are indented by that same amount, skimming through your code becomes easier. The reader can choose to read either comments or code without needing to “find” one or the other.
Feel free to use paragraphs or bullet points.
Commenting blocks of code ∞
When you’re actively working on a section, feel free to comment large blocks of code.
Sometimes this is done when rewriting something, and the author wants the old mostly-working code visible for reference.
However, if old code is left laying around too long, then it will cause confusion. Unless there is some specific reason to keep the old code there, take the first opportunity to remove it.
Anti-deletionists like this author can feel bad about removing and losing that “knowledge”. If you feel awkward doing it, then use a good revision control system like Git.
Revision control is a very commonly used tool. So common it should be considered mandatory for programming. Get a revision control system, force yourself to use it and get used to it.
Running this tutorial’s examples ∞
All of this tutorial’s examples have been created in such a way that you can just:
- Create a text file (e.g.
filename.my) - Make that text file executable (e.g.
\chmod +x filename.my) - Add the
#!/usr/bin/mythryl“shebang” as the first line. - Add the opening and closing braces:
{and}; - Copy the example you want to try
- Paste the example into the text file between the braces.
- Save the file.
-
Run the file (e.g.
./filename.my)
Simply put:
1. Open your text editor.
2. Create a new file.
3. Paste the boilerplate, and your code within it.
#!/usr/bin/mythryl { # Your code goes here! };
4. Save your file as filename.my
sh \chmod +x filename.my ./filename.my
