Unpopular Opinion #1: Teach Raw Pointers First

Being the administrator of a large programming Discord server, and the owner of a YouTube channel with a large audience of programming beginners, it is with some frequency that questions about the basics of programming are asked. In fact, it’s often the same questions. This is perfectly fine, after all, the ethos of One Lone Coder can be encapsulated in the phrase:

“There is no such thing as a stupid question”

An attitude which I wholly endorse, and encourage others to actively embrace because at least the asker is actually asking – a necessary step on the journey to acquire knowledge.

And so it was with admittedly brash vitriol that I lambasted several members of the community the other night, for which I can only apologise, as it was uncharacteristically impetuous of me, though I stand by my lambasting. Before we get there, please consider this code:

descriptor<utilises: a>
{ 
allocate : 23[a] 
<for 'all' in a> set [traits:on]?"numeric type"
    === literal_cast<set.trait>(12);
}
end

Now, tell me which modifications to the code will ensure that allocations remain aligned to 32 byte boundaries, in a contiguous fashion? C’mon it’s really simple!

If you know the answer, you’re lying. If you don’t know the answer, I’m not surprised. You haven’t encountered this language before, you know nothing of its semantics, structure, flow or algorithmic composition. You have just become the programmer you once were, when you first started.

So then, why when someone asks the innocent and innocuous “How do I declare a 2D array in C++?” is the immediate response:

std::shared_ptr<std::array<std::array<int, 500>, 500>>

Let’s just do a little reality check here. Firstly, the question itself implies the asker is not familiar with the language at a fundamentally basic level, so why should it be assumed that requiring the asker to first understand:

  • the standard template library
  • templates
  • object oriented programming
  • compile time memory descriptors
  • smart pointers
  • the concept of ownership

…is acceptable? The guy just wanted a 2D array!

This is a confrontation I often have with my fellow community. It’s great to be able to help people, it’s satisfying, and it makes you look great in front of others – and hey, it’s a chance to flex your skills and knowledge under the guise that in the long term, you are doing them a favour!

Well, sorry, you could not be any more wrong.

Not only is showing off in such a manner obnoxious, it labels you as being confusing in the eyes of the asker, and as a twit in the eyes of your peers. An array is fundamental, and if you are being asked how to create one, chances are the asker doesn’t really know anything about arrays. So don’t bog down your explanation in elitist, pedantic wafflery, just show them how to make an array!

// Ask for some memory
int *a = new int[500*500];

// Do something with it
a[y * 500 + x] = 6;

// Give it back
delete[] a;

Put aside the snobbery, and understand there is a beautiful elegance to this from the perspective of someone who is learning. Every single byte of source code in that snippet contributes to the most minimal form required to understand such an important concept.

  • A variable ‘a’ contains a memory address
  • That memory is requested, and the address put in ‘a’
  • The memory is indexed somehow, starting from its beginning
  • When finished, give the memory back

Surely, for such a basic question, understanding this sequence of events and their associated outputs is significantly more beneficial to the asker, than requiring them to concern themselves with ownership, templates and objects? But alas, empirically it would seem not because invariably the following argument is raised:

It’s better to teach people the correct way from the start, so they don’t form bad habits…

Oh be quiet! You’re embarrassing yourself and patronizing the asker. Firstly, there is no way you learned about arrays (or the fundamentals of programming) according to some “standard” first time around, so stop being a hypocrite. Secondly, you have assumed the asker is too dumb to understand the consequences of their code. And most importantly, thirdly, you have assumed the asker doesn’t have the capacity to adapt and change as they learn and gain experience – which clearly they do, as they are asking the questions in the first place!

Javidx9 Top 5’s

It would seem people are quite curious about things I like, so I thought it would be useful to have a page that I can point such individuals towards. Here are my Top 5 “things” in various categories.

Top 5 Films

  • Hackers
  • The Andromeda Strain (1969)
  • Batman Trilogy (Nolan)
  • Inside Out
  • John Wick

Top 5 Foods

  • Chilli Con Carne
  • Pulpo a la Gallega
  • Char Siu with Green Pepper and Blackbeans
  • Walkers Chicken and Thyme Sensations
  • Pistachio Nuts

Top 5 Programming Languages

  • C++
  • Lua
  • Java
  • BBC Basic
  • VHDL

Top 5 TV Series

  • The West Wing
  • The X-Files
  • Lost
  • The Orville
  • The Sopranos

Top 5 Tracks

  • La Gazza Ladra – Rosinni
  • Nightrain – Guns N’ Roses
  • Contact – Daft Punk
  • The Haunt of Roulette Dares – The Mars Volta
  • You To Me Are Everything – The Real Thing

Top 5 Albums

  • Frances The Mute – The Mars Volta
  • The Wall – Pink Floyd
  • Appetite For Destruction – Guns N’ Roses
  • Deloused In The Comatorium – The Mars Volta
  • Mechanical Animals – Marilyn Manson

Top 5 Star Trek Captains

  • Janeway
  • Picard
  • Lorca
  • Kirk
  • Pike

Top 10 Games

  • The Witness
    Deservedly titled “the best game I have ever played”. What a wonderful experience from start to finish (and yes I 100% it, even the damn boat and time trial). It is a lesson in game design. If you think its just line puzzles, you are very very wrong, and it gives you those “oooh I get it now, I wasn’t expecting that!” moments every couple of hours. Do not spoil this game, it is best enjoyed not knowing anything about it, and just enjoying the ride. A true masterpiece.
  • Final Fantasy VII
    Admittedly, there is a heap of nostalgia bundled into this, but wow was this an eye opener. RPGs up until this point were good but despite its aged looks today, this was really immersive, and grown up, and fun, and surprising, and tactical, and explorational. A rock solid adventure, creating mountains of lore, that’s really addictive to play.
  • Super Metroid
    Often touted as the pinnacle of game design demonstrated in a single title, and deservedly so. I don’t like shooters, I don’t care for shooty platformers either, but this game plays so well, its like playing a musical instrument when it comes together. Packed with replay value, a genuine demand for gameplay skill, and a variety of ways through the game, means its a game I play several times a year.
  • Super Mario Brothers 3
    It’s Super Mario Brothers 3 – what else needs to be said?
  • Uncharted 2
    So Uncharted 1 was good, but a bit generic. This sequel was genre redefining. It’s like a roller coaster all the time, the world collapsing and changing around you whilst you explore and navigate is captivating. The story and acting is top notch, and its the first time I’ve ever felt that a game is a genuine interactive movie. Really gripping and fluid gameplay all the time just makes this extremely fun to play, and can be enjoyed by spectators too.
  • Crash Bandicoot
    What really needs saying? It’s Crash Bandicoot! At the time, absolutely mind blowing visuals and gameplay which still hold up to this day. Classic Naughty Dog stuff, being very simple and accessible, but requiring lots of practice to master.
  • Fez
    An absolute gem. Look pass it’s indy credentials and its controversial developer and what you discover is a real masterpiece. Its geeky, the puzzles are hard and its a game with so much beneath the surface its easy to think its a different game entirely. The fact it has distinct “new game” playthroughs, and it took me ages to find all the cubes (except the final one, I had to google that) really impressed me.
  • Batman: Arkham City
    I like Batman. I like exploration games, and I like games with loads of things to find. This was a superbly immersive and engaging game. Fun fact, I’ve found all the Riddler trophies in all the Arkham games.
  • Command & Conquer: Red Alert
    A perfect blend of story and gameplay depth made this a far better sequel to its predecessor. The cinematics, the music, and the variety kept me coming back for more. Also exchanging strategies with friends as currency.
  • The Incredible Machine
    At the time it was genre defining. Solve puzzles by building various mechanical contraptions, and had a sandbox mode you could simply build in. Very addictive, highly educational and totally silly nonsense. Perfect.

How to attribute/credit/cite the olc::PixelGameEngine

Hello! Firstly a big thank you, the fact that you are reading this means you actually care about doing the right thing, and want to acknowledge the software you have used from other developers.

The olc::PixelGameEngine is open source and is released under the OLC-3 licence. This means you can use it freely, even for commercial projects. However, the licence requires that appropriate attribution is required.

Releasing Software in Executable Binary Form

Your olc::PixelGameEngine application needs to display to the user the following message:

Copyright 2018 – 2020 OneLoneCoder.com

Most people prefer to do this by either:

  • Keeping the application in window mode, and not changing the text displayed in the window’s title bar. By default, olc::PixelGameEngine applications are out-of-the-box compliant.
  • A splash screen along the lines of “Made using olc::PixelGameEngine” and including the above notice.
  • Full attribution in a “Credits” or “Licences” menu available without special requirements of the user (such as completing the game for example)

Releasing Software in Source Code Form

If your project is distributed via source code, and you use either part, or all of the olc::PixelGameEngine, the full text of the OLC-3 licence needs to be included in the source code distribution. By default, an unchanged olcPixelGameEngine.h file will satisfy the licence requirements. If you maintain an external catalogue of licences, you should include OLC-3 in that too.

Releasing Derivative Works

Since the olc::PixelGameEngine is open source, you are allowed to modify it. This could be in the form of adding additional features, wrapping it into an alternative framework, cloning the features, or using parts of the code. In this instance, the full OLC-3 licence text needs to be included, and if your derivative work is in binary form, it must display to the user the above copyright notice.

Citation in Academic Works

If you use olc::PixelGameEngine for school, research, academic pursuit, you can reference/cite it properly in the following way:

olc::PixelGameEngine, v2.05, OneLoneCoder.com, 2020

The version number and year are of course flexible and should be changed as required.

Referencing in Digital Media

If you write blogs, make videos, create content and want to reference the olc::PixelGameEngine,, or indeed the OneLoneCoder website or javidx9 youtube channel, then the correct links are:

https://github.com/OneLoneCoder/olcPixelGameEngine

https://OneLoneCoder.com

https://youtube.com/javidx9

Finally, again a big thank you for taking this seriously. Software development is a hard and time consuming task, in the hope that it makes someone else’s software easier and quicker to produce. It is important that the hard work of others is given the credit it deserves – javidx9.

olc::PixelGameEngine 2.0 is here!

After quite a few late nights, it’s finally here! PGE 2.0 is a significant upgrade on its predecessor, and is 100% backward compatible. This major revision brings in hardware accelerated sprites in the form of the olc::Decal, multiple rendering layers, and has been completely re-organised to make it easy to port to other platforms.

The features added were in response to the fantastic feedback from this community. You guys wanted to use it as a genuine game engine? Now you can.

Download from the Github Repo and try for yourself!

Enough! Why rand() cant compress!!!

Unless you are born an information theory genius, at some point during your programming learning you might have considered the following hypothesis:

A file is a sequence of bytes. If I could find the appropriate seed for srand(), surely I could generate the file, just by successively calling rand() % 256? Therefore I could represent the file with just the seed and the expected file length.

Continue reading “Enough! Why rand() cant compress!!!”

Small Project Planning

It’s codin’ time…

Planning well is the key to successfully finishing a project, and it does not solely apply to large projects. Even your small one file programs could really benefit from a plan before you start. If you’ve ever watched one of my videos, you’ll frequently see me drawing my intentions on screen – this is not just for a visual demonstration, more often than not, these drawings are inspired by squiggles I drew while I was planning the project. In this post I want to point out a few things that I do to ensure in the very least, I reach my project goals.

Continue reading “Small Project Planning”

Non-Repeating Pseudo Random Sequences

Pseudo-random numbers are numbers drawn which on the surface appear random. It’s not possible for a computer to actually generate “genuinely random numbers” without additional hardware, and even then their credibility of randomness is not guaranteed. For most purposes in game development, it’s rare to actually require genuine random numbers and so we rely upon the the numbers provided by libraries.

Continue reading “Non-Repeating Pseudo Random Sequences”