Program The rantings of a lunatic Scientist

Posts marked as L2Program

Merry Christmas and a Happy New Year


Happy holidays! It’s been quite a year and I have a feeling 2014 will be just as exciting. The beginning of this year I was still on the MEng course, with over a year to go, then in May I found out I would be starting my PhD! Which meant I got to graduate with a BSc in July, and started research in October.

So far the PhD is going well. Slowly, but well. I’ve read and heard from a lot of people that the first year is always like this with research. A lot of background reading and very little of knowing what you’re actually supposed to be doing. That said, I think I’m on track.

I broke for Christmas to go stay with my family for a couple of weeks with the intention of getting a good amount of reading done each day, sans Christmas Eve/Day themselves. In the end I actually took a bit more time off work. In some respects I feel very guilty about it, and in others I think it’s the best thing I could have done. I just didn’t realize how much time I’d been putting in each week until I stopped all together for a few days.

Now I’m back in Swansea obviously it’s going to be full speed ahead again.

Mark (my supervisor) told me before I left he wanted to have something working if not publishable by around April time this year. Yikes! But it looks really promising and hopefully I can get my head around it before then.

More Bi-Directional Path Tracing

C/C++ GPGPU Graphics Java L2Program PhD

It’s still not perfect, far from it in fact, but it’s progress none the less. I’ve been reading a lot lately about Metropolis Light Transport, Manifold Exploration, Multiple Importance Sampling (they do love their M names) and it’s high time I started implementing some of them myself.

So it’s with great sadness that I am retiring my PRT project which began over a year ago, all the way back at the start of my dissertation. PRT is written in Java, for simplicity, and was designed in such a way that as I read new papers about more and more complex rendering techniques I could easily drop in a new class, add a call to the render loop, or even replace the main renderer all together with an alternative algorithm which still called upon the original framework.

I added many features over time from Ray Tracing, Photon Mapping, Phong and Blinn-Phong shading, DOF, Refraction, Glossy Surfaces, Texture Mapping, Spacial Trees, Meshes, Ambient-Occlusion, Area Lighting, Anti-Aliasing, Jitter Sampling, Adaptive Super-Sampling, Parallelization via both multi-threading and using the gpu with OpenCL, Path Tracing, all the way up top Bi-Directional Path Tracing.

But the time has taken it’s toll and too much has been added on top of what began as a very simple ray tracer. It’s time to start anew.

My plans for the new renderer is to build it entirely in C++ with the ability to easily add plugins over time like the original. Working in C++ gives a nice benefit that as time goes by I can choose to dedicate some parts of the code to the GPU via CUDA or OpenCL without too much overhead or hassle. For now though the plan is to rebuild the optimized maths library and get a generic framework for a render in place. Functioning renderers will then be built on top of the framework each implementing different feature sets and algorithms.

99 Bottles of beer

L2Program Language

Still very much a work in progress but it’s at least 99% there. And what better way to celebrate than with a round of 99 bottles of beer on the wall!

1.1 Do part 2 for a = 99(-1)2.
1.2 Do part 3.
1.3 Line.

2.1 Type a in form 1.
2.2 Type a in form 2.
2.3 Do step 4.1.
2.4 Set b = a - 1.
2.5 Do step 3.1 if b = 1.
2.6 Do step 3.5 if b != 1.
2.7 Line.

3.1 Type "1 bottle of beer on the wall".
3.2 Type "1 bottle of beer".
3.3 Do step 4.1.
3.4 Set b = 0.
3.5 Type b in form 1.

4.1 Type "You take one down, you pass it around".

Form 1:
_._ bottles of beer on the wall
Form 2:
_._ bottles of beer

Parsing begins!

L2Program Language

The PEG.js parser is now complete!!! Now all that is left to do is write the functions for the evaluator and control flow. For now I have locked the parser to only testing commands against MathExp as the root node. The function eval_math(tree) accepts a syntax tree with a root node marked as num for a plain numerical value, var for a reference to a variable, math for a simple add/sub/mult/div between two other math trees, or function which represents a call to a math function (built into the language). Below is an overview of the parse tree for a math expression (MathExp).


{ tag: "num", val: 0 }


    tag: "var", 
    val: {
        id: "a",
        index: {
            // Another Math Expression


    tag: "math", 
    val: {
        op: "+",
        left: {
            // Another Math Expression
        right: {
            // Another Math Expression


    tag: "function", 
    val: {
        func: "sqrt",
        param: {
            // Another Math Expression

Math::Function (multiple params)

    tag: "function", 
    val: {
        func: "min",
        param: [
            {}, // Another Math Expression
            {}, // Another Math Expression
            {}  // Another Math Expression

Simulator Progress

L2Program Language

Progress on the JOSS language simulator is coming along nicely. I decided to take a break from transcribing and converting the grammar so I could work on the ui for a bit. This will be helpful as soon I’ll need a way to parse input commands and output the system replies.

So far the terminal is designed along with the input bar. Upon pressing enter the currently written command is added to the bottom of the terminal feed and (if necessary) the terminal is smoothly scrolled down to it’s new bottom. Like the original typewriter consoles on JOHNNIAC, inputs typed by the user appeared in black type and responses from the system are shown in green.

Further plans for the ui are to eventually include some form of modal or accordion based content organisation to allow a pane describing the history of JOHNNIAC, and a pane to describe the syntax for the language.

A JOSS simulator

L2Program Language

As I alluded to at the end of my last post on the subject of the JOSS programming language, my goal is to revive the language and create a usable version of it. (Why, you ask? Why not)

The design for the Simulator is to construct a webpage with a black/green terminal style display with a text box at the base of the terminal to allow command statements to be prepared and submitted to the system. On the backend the simulator will run entirely in Javascript, utilizing the PEG.js parser builder to tokenize and execute commands.

When a command is submitted to the terminal it will be given to PEG.js to parse and turn into a syntax tree of tokens. PEG.js also gives very precise parse errors which will allow the simulator to give the user feedback on their commands. If a command is successfully parsed the parse tree and the text version of the command will either be stored as as elements in the “program tape” a javascript object of the form:

    1:{ // Part 1
        1:{ // Step 1
            text: "Do part 2.",
            tree: [{ /* JSON PARSE TREE */ }]
    2:{ // Part 2
        1:{ // Step 1
            text: "Stop.",
            tree: [{ token:"STOP", value:"Stop", children:[] }]
], vars:[
    a:[0:26, 1:3.14], // a = a(0) = 26, a(1) = 3.14
    b:[0:17],         // b = b(0) = 17

By expressing the entire program and state of the simulator in JSON we gain the ability to easily have access to any part of the program or data. We also have the ability to save the current session using the browser’s local storage api or share the program by simply saving the serialized JSON to the server with a unique link. JSON is also the reason for storing the parse trees as objects rather than compiling them to an intermediary before use. By walking and evaluating a command by climbing through it’s parse tree we can use recursion to jump to other commands in the program tape. When we have fully climbed back up the tree to the root node or a command returns the Stop. token we know the program has finished executing.

One problem I see currently is that the language is based around the use of fixed precision arithmetic using 9 decimal places for precision. Currently I don’t know of any way to do math in fixed precision in JavaScript short of rolling my own set of maths classes, and I’d really rather not. For now we’ll work in standard floating point and see if it can be added in later.

The Grammar

Citation: "JOSS: Experience with an experimental computing service for users at remote typing consoles", J. C. Shaw, May 1965, Page: 10
Citation: "JOSS: Experience with an experimental computing service for users at remote typing consoles", J. C. Shaw, May 1965, Page: 10

Using the paper I found previously discussing the use of JOSS on JOHNNIAC over a 16 month period, I have been able to piece together a Context Free Grammar. While I am pretty happy with it, it’s not perfect. Every now and then I spot an error and fix it but for the most part I’m satisfied it’s solid.

There are however a couple of things intentionally in there which aren’t perfect but there is good reason for them. For instance, because JOSS lacks the ability to have user defined functions I have created a function token and within it an array of tokens, each representing a different standard math function available to the user. The reason for this is to allow parse time error checking of the number of variables.

Converting for PEG.js

So far I have gotten numbers and math expressions converted into a PEG.js parser. The current state of the parse can be seen on this Gist along with the BNF Grammar. Eventually I will move all of this into its own repo on Github but for now it’s all being developed in the browser; that is, I’m writing the PEG.js parse directly into their online compiler to test it as I go, so there is nothing local to save to a repo at the moment.

Below is the current BNF Grammar for the language.

Why C++ is only mortal

C/C++ L2Program Rant

Another opinion piece if you’ll grant me the time. Not that there’s anyone to read it but this site, much like blogging was in the olden days of the internet is really more of a hobby and for peace of mind than anything else.

This post was once again inspired by a comment on reddit asking why there were so few good resources for people who wanted to start their education into programming and software engineering by learning in C++.

In my honest opinion as a developer, a computer scientist, and as a teacher the reason there are no “good” resources for people looking to start with C++ is because C++ is just not something you should start with.

Programming is a relatively unimpressive skill to have on its own. The knowledge and ability to design software on the other hand is an incredibly powerful thing to be able to do. Having that ability gives unmeasurably high value to your ability to program, and it scales with how many paradigms, languages, and platforms you can take that to.

Programming is simply syntax wrapped around design. A house is a design built in brick, and likewise a piece of software is a design programmed in syntax.

Now tell me, is it of vital importance that you learn all the engineering principles, all the design aspects, all the architecture concepts, and all the safety mechanisms to build a house at the same time as you learn to lay diamond encrusted bricks in the most elaborate and complicated way possible? Of course it isn’t! It’s much more sensible (and safe) to learn to build a house with normal, simple, sensible bricks and then work on your skills and work your way up to laying diamond encrusted bricks in fancy patterns.

In exactly the same way, this is why someone who has never programmed before should not just dive into C++. Why make life harder for yourself when you just aren’t going to benefit from it? It’s much more sensible (In my opinion at least) to learn about language structures like loops and conditionals, and then learn about Imperative design patterns, and Object Oriented design patterns, and learn about inheritance, and interfaces, and type checking, object references, and data structures, and algorithms, ect, in an easy to pick up and safe to f#$k up language like python or java or C# who all have simplified and friendlier syntaxes (I’m not looking to start a war of which language is best/worse). Then if and when you have a use or a desire to use C++ you already know how to design the house. All you need is the bricks and mortar.

People become complacent and become afraid to branch out from their comfort zones

Another thing that really comes into play here, and this can be a really touchy subject for a lot of developers. You need to pick the language that’s right for the job. And as often is the case, there will be no perfect language. There will certainly be ones which are worse than the others, but there may be several who all excel towards one aspect of your goal but each fall short in some way making none of them quite right. In this case you need to pick the one you feel most comfortable with and roll with it.

A lot of the time I see people trashing languages, Java gets a terrible reputation and a similarly PHP developers have to hide their heads in shame as they pour their coffee at lunch. This (to me) is ridiculous. Each has it’s benefits, and each has it’s laundry list of shortcomings; just like every other language. Every language has it’s purpose, even BrainFuck and MOO had a place in the scientific community. Developers get really attached to their languages and tool chains and far too often they would rather reinvent the wheel bulkier, buggier, slower, and harder to use just to stay within their comfort zone so they don’t have to swap environments (or sometimes even as little as changing their IDE for five minutes…).

So here’s my point.

If a person is coming into a development situation fresh, and they have no prior knowledge of programming, and they have to (unavoidably have to) be developing in C++ for whatever reason, then that person is catastrophically unprepared for what they have walked into. Plain and simple. However, if that person just inherently thinks of C++ as the ultimate in coding and they want to do it in C++ just because then chances are 99.999999% of the time they can do it in a different language, a language that will be friendlier, be easier to learn in, will have libraries which are far easier to incorporate and run with, and will have a development environment which is often far easier to setup and target for their system. More importantly, is a person who is fresh to to all of this and knows very little on the subject really in a position to make an informed decision on what environment is “the best one, I must use that one!” ? By very definition they are not.

I am one with the computer… The JOSS programming language

L2Program Language

My name is Zaphod. Or at least, if my father had had his way my name would be Zaphod.

As the story goes my mother, still light headed and exhausted from child birth had to up and run down to the reception office to stop my father from having the name Zaphod (as in Zaphod Beeblebrox from The Hitchhiker’s Guide to the Galaxy) put on my birth certificate.

Now as uncommon and strange of a name as Zaphod is my parents compromise on the name Joss is arguably just as uncommon. In fact, the only reason you have probably heard the name Joss is because a large proportion of the few people called Joss are famous (no pressure or anything). Joss is also commonly (cough: incorrectly) used as a shortening for Jocelyn.

However, what if my father in fact had another trick up his sleeve? A plan so cunning and dastardly that my mother never would have suspected his evil doing. What if my father named me after a programming language…? He had the knowledge, being a mathematician and programmer at Aldermaston, and he had shown the capability by attempting to name me after a character in a Sci-Fi TV / Radio show & Book series.

The JOSS Language

Today by random happenstance (no I was not Googling my name… who on earth does that? …) I discovered a Wikipedia page about a programming language called JOSS.

JOSS was the child of a 1950’s R&D firm called RAND which quite unimaginatively stands for Reasearch ANd Developement. RAND was funded by the US Army Air Corps which later became the US Air Force, and is still an active organisation today.

RAND developed a computer called JOHNNIAC in 1953. JOHNNIAC, which stood for John v. Neumann Numerical Integrator and Automatic Computer, was soon surpassed by faster and more reliable machines. This however, allowed for other non performance critical research to be carried out on JOHNNIAC; most notably the development and usage of the JOSS programming language.

The JOHNNIAC Open Shop System, JOSS, was the first language which allowed for interactive and concurrent access to a computer. Developed between 1963 and 1964 by Cliff Shaw (inventor of the Linked-List), JOSS allowed for up to eight users to access JOHNNIAC simultaneously via separate typewriter terminals.

The language was designed as a way for mathematicians and engineers to perform small but complicated calculations quickly without having to have a great knowledge of computers or direct access to a “Computer Expert”. JOSS has two methods of interaction, direct and indirect. In direct mode the user presents command statements to the terminal (which were printed in black ink) and JOSS replies to these statements as each arrives (printed in green ink). In indirect mode the user queues up commands by preparing a program, the user then types Go. or types a statement to be run as an initializer which then runs the program.

So was I named after a programming language?

JOSS is openly referred to as JOHNNIAC’s legacy. As it just so happens my father is named John, and by being his only son I am by very definition his legacy. Coincidence? I think not!

After a little more digging trying to find out more about this language I stumbled across this paper published by the RAND Corporation in 1965, describing the results of using JOSS on JOHNNIAC over a period of approximately sixteen months. From this paper, which also gives a good overview of how to use and program in JOSS, a couple of quotes stuck out to me.

People adjust their lives to fit around JOSS… No use coming into RAND before 10:00 am when JOSS arrives, in fact noon or after 5:00 pm is a better time, JOSS is less busy. When JOSS starts typing answers, the titillating pleasure is equalled only by the ensuing anguish when JOSS breaks off into jibberish or goes away commending your code to oblivion. We can hardly live with JOSS, but we can’t live without it.

Now you can’t say that doesn’t sound like me.

JOSS lacks the problem-solving capacity to carry on a sophisticated conversation.

Actually, that sounds a little more like m… nevermind.

So was I named after a programming language? Okay probably not. I actually asked my father and while he betrayed a slightly evil smirk before he began to laugh he claims he and my mother simply chose Joss because it was uncommon.

Where to go from here?

Well I would think that’s obvious don’t you? I am a Computer Scientist name Joss and there is a programming language named JOSS which for all intents and purposes, much like Latin, is a dead language. The next step, clearly, is to find a more formal specification of JOSS or derive one if none exists and create a JOSS interpreter.

For now though I will leave you with this program which looks for a user named Joss, programmed in JOSS, by a programmer named Joss. How meta is that :)

1.1 Type "Are you Joss? (1 or 0)".
1.2 Demand n.
1.3 Do part 2 if n=1.
1.4 Do part 3.
1.5 Stop.

2.1 Type "Hello Joss!".
2.2 Stop.

3.1 Type "You aren't? Only Joss is welcome!".