I can’t get any lower than this
No, this is not an emotional breakdown. However, if you came in here just to say some nice words of encouragement, say them anyways. Not that I need them, I just have this friend…
I am actually here to talk about is the choosing between lower-level (C++, C) versus higher-level (Java) programming languages when tackling a new random computer science concept.
For the sake of discussion, suppose you have an assignment and you are to decide between the two options above . What I plan to share with you is my chain of thought and why I decided to take the alledgedly easier route even though I love C/C++.
Did you make your choice? Let’s start then…
The level of abstraction of a programming language is usually related to the number of steps away from the processor it runs in. The famous language for being notoriously low-level is Assembly. If you write something in Assembly that means you are talking directly to the processor, literally feeding it instructions one at time, exactly the way it understands. However, if you use Java, for instance, there are a lot of steps in between including a Virtual Machine until your code is finally compiled and executed as machine code.
How much lower can I get?
I got into this reflection after having my first class on 3D Programming using OpenGL in my post graduate course on Game Development. OpenGL is a multi-platform specification for defining graphics. We haven’t even gone very far, actually only two classes in to be precise and I’m already hooked with the subtleties of manually handling 3D graphics.
It is not that hard to conclude, from the fact that it is a platform agnostic universal API for GPU communication, that it must be somewhat low-level. The specification is mainly focused for C and C++ with numerous ports for other languages. The lack of context in the API side coupled to the constant worry of CPU to GPU communication bottleneck also doesn’t contribute towards the friendliness of the API. In our first 3D programming class, it took us a couple of hard dedicated hours to grasp the concepts for the drawing of the simplest of the shapes, a triangle.
To be able to only do the aforementioned you have to be acquainted to so many terms: vertex arrays, array buffers, vertex shader, fragment shader, GLSL... After you are done, it definitely feels like adding a new line of code will jeopardize the entire system.
For development we are using a Java implementation and that at least blind us from all that compiling, linking, platform-dependent shady (pun intended) stuff. Additionally, the JOML library will assist on the maths related concepts, such as compoundable transformation matrices.
After the class introduction, my little ‘I want to do it from scratch little brain of mine’ started to come up with an idea:
How much lower can I get?
It is not uncommon for programming geeks to have an uncontrollable will to reach out for the lower levels. The thought of descending further into the abstraction hierarchy and getting access to things as raw as it gets always shines on the eyes of those who praise for an additional challenge. There is this sense of undeserved accomplishment that hits when you code upon something that wasn’t thoroughly implemented by yourself.
How much lower can I get?
The first thing that I thought about was getting rid of the auxiliary math library. I could use some additional knowledge on 3D geometry, so it wouldn’t hurt to force learn it anyway. Also, Java is too kind, all that automatic memory management handling makes you soft. I’d rather handle everything on my own and choose C++. Choosing C++ though is kinda convenient. It is object-oriented so you get all that behavior paradigm, dynamic function dispatches, hierarchies and etc going on for free. Nah, I don’t want that kind of help.
Let’s dive deeper.
I could, in light of old good times, use the C language. Let’s play around with structs, preprocessor magic and mallocs and frees. I’ll even maybe write some parts in assembly to make sure the computer is doing exactly what it is being told.
But then again, why stop now?
So am I only capable of so much? No! Let’s tackle assembly code, like the one engraved up there, maybe better yet, I am going to prototype my very own GPU and make it implement the OpenGL specification and then I’ll be ready to code. Huh, it wasn’t that hard after all, I am glad we sorted that out.
I maybe even build the computer with which I will design my own GPU. I might want to learn how to start a fire while I’m on it.
I think it gets pretty clear, that the main objective of the class has been lost a long time ago. I was supposed to be learning 3D programming with OpenGL. It is like going to a rookie cooking class and be asked to scavange for your own food prior to actually learning how to cook it. I am not saying it is not important, it just doesn’t make sense.
The turning point actually happened when I couldn’t reason about whether stepping down a notch or just going all the way down. So, I decided that instead of pushing down the boundaries I would pull up the goals.
I mean, people have been drawing shapes on screen for a while now, right? Why make it harder on me?
I figured that getting stuck trying to set up a development environment was not worth it, so I embraced Java. Rather than writing my own math library I decided to learn how to use one and finally see what some unorthodox vector operations would do for me. Instead of wasting time on anything else I decided to focus on simply learning 3D programming with OpenGL.
Do not focus too hard on the language itself. After all, it is just the tool!
I am profoundly satisfied with this approach for I am finally able to invest time on the subjects that matter to the class. I am all set up and ready to go, however, my curiosity still begs the question:
How low are you willing to get?