Friday 31 December 2021

LP's 12 Months of Games // Alien Invaders Part 1 [C++ & SFML]

Completed Independently

So the final game of "Beginning C++ Games Programming" by John Horton was a clone of "Space Invaders". I skimmed the first chapter of the project and he starts talking about Entity component systems, Factory class designs etc and I just completely zoned out and decided to make it myself. 

This took me a while as Back 4 Blood added an offline mode and there's nothing quite like hitting zombies with a baseball bat. Also the Witcher season 2 and Lost In Space season 3.

So anyway, I kept getting annoyed with myself whilst making this game; I was trying to make the code as beautiful as possible right off the bat; which is impossible unless your Bjarne or Scott Meyers or something. I asked many colleagues how they would go about implementing Space Invaders and amusingly, the more senior the engineer the more the answer became "just do it all in main, who cares?"

So, I've written some terribly hacky code that only gets worse as time goes on but I have a game! This is labelled part 1 because it's not finished however, there is a title screen, a game and a game over. It saves the high score between runs and loops after game over so it is a game...regardless of how finished.

I'm quite into the task now and the shields are ready to be implemented, as are the sounds. Then the flying saucer needs some attention as do the shot exploding animations but then I'll have a full Space Invaders clone!

I've given myself a few little extras that involve creating a CRT shader and making it look as though you're playing the game on an arcade machine.

Result:
Space Invaders Clone Using C++ and SFML

I'm extremely happy with what I've done so far. I'm really trying my best to make it look and feel exactly like the original. I'm going so far as implementing the same bugs using this site which comments all the assembly:

There are some issues which you may have already noticed; my game over text isn't displaying and the high score isn't updating. That will be fixed next but the code is in place.

I just really wanted to get something uploaded for this month and I've already learnt so much from attempting to do this by myself. I'm glad I ignored the book as this game is deceptively hard but a great place to start when making a complete game from scratch for the first time.

I almost gave up a couple weeks ago as I find it difficult to find the motivation to finish things. I have about 70 started projects but I thought to myself, the whole point of this challenge is to get better at making games and I won't get better if I don't at least try! So I managed to scrape the code together enough to call it a "game".

It also made me realise that I hate UI programming with a burning passion.

Code:


Friday 24 December 2021

C++ & SFML // Creating The Disintegrating Shields in Space invaders

Whilst making a clone of Space Invaders, I got to the point where I had to make the shields. They are interesting as only parts of them get destroyed when hit by bullets:


The damage done to the shields is based on the type of bullet and where they hit. It reminds me of the old Worms and Lemmings games that have disintegrating terrain due to explosions.

The player's shot and 2 of the invader shots deal the same type of damage. However the "plunger" looking invader shot is the most powerful and deals more damage. Therefore, having the shields as sprites make no sense as you can't manipulate the pixels in a sprite, so I started looking into ways to draw and modify pixels in SFML as well as do per-pixel collisions.

I eventually came across this post:

This seems super long winded for what I want as it copies the image from the gpu into an array of pixels, then you modify those pixels and then send that array back to the texture. But it's also the closest to how the original game implements the shields (in a way).

I then found this after googling "sfml array of pixels":

I was able to write a program that can draw individual pixels to the screen:

This is more along the lines of what I wanted, as I could now simply create a vector of vertices in the shape of the shield. SFML already provides this type called VertexArray which can be passed directly to a RenderWindow's draw call.

Here's a simple program I wrote that uses a VertexArray to create a rectangle with a gradient fill:

In my version, the shields are 66x48 pixels, with each vertex needing 4 uint8's of data (RGBA), so that means I need to supply 12,672 uint8's and I don't really want to type that out. So I had to start looking for a way to read in that data from something. SFML does not provide a way to convert textures or images to VertexArrays. I can get the pixel colour data by using the first method and copying the texture to an image but that doesn't provide pixel positions (which a vertex wants). So I wrote a method to combine the two. 

It creates a temporary texture, copies the texture to an image then loops through every pixel, pushing back a new Vertex after all 4 pieces of the pixel have been collected. The positions are calculated using an offset from the top left hand corner. So after 66 vertices have been pushed back, the y co-ord is shifted down 1 pixel. However there is still a glaring problem with this method; I have 4 arrays containing 3168 elements.

So I went back to the drawing board and found this post:

Using the code from Laurent (the developer of SFML) I managed to write a program that creates a "mask" from a png and uses that to turn pixels transparent:

C++ & SFML // Creating The Disintegrating Shields in Space invaders

Armed with this knowledge I then set about creating a cannon that fires lasers at the doge image to destroy it:
C++ & SFML // Creating The Disintegrating Shields in Space invaders

The next issue to solve was the per-pixel collisions as the laser was still colliding with the bounding box of the sprite. I hackily solved this by writing a very simple collision check:

C++ & SFML // Creating The Disintegrating Shields in Space invaders

First, it only does a per-pixel check if the laser has collided with the bounding box of doge. Then, it checks to see if 3 spots on the laser have hit solid pixels. If they're all transparent then the laser can pass through.

This isn't perfect, but it's good enough.

Thursday 16 December 2021

Chapter 22 // Exercise 15 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 22 // Exercise 15

Write a program that, given a file of (name, year) pairs, such as (Algol,1960) and (C,1974), graphs the names on a timeline.


I finally did this exercise after much procrastination. I also hate Bjarne because the scattergraph class I made back in chapter whatever doesn't exactly fit this example.

Instead of continuing to procrastinate I decided to hack it together one night....it's not exactly a timeline but well I guess it is. There is a line and there are times...done.


I had a look for rotated text in FLTK and it looks like it's just been implemented in 1.3.8, which was released last month. I'm still on 1.3.7 but I'll update at some point as that would've made this much easier.

Friday 19 November 2021

C++ & SFML // Simple Event Queue System with Timings

In a previous post (C++ & SFML // Simple Timer), I showed how you can create a simple timing system in SFML to display messages on the screen.

In this one I created a very simple "Messaging Dispatcher" that receives messages and displays them. I followed along with the Ring Buffer design by Robert Nystrom in "Game Programming Patterns" to create this little demonstration.

C++ & SFML // Simple Event Queue System with Timings

Here, when E is released, it fires a message to the dispatcher. Each message has a random time to display between 1 and 4 seconds.

The code can be found here:

There are a few caveats with this simple system:
  • The queue is a fixed size so it will reject messages when full,
  • The queue doesn't create an empty slot until the top message has finished displaying; if this was set to display for 5 minutes and all the other messages in the queue only want to display for 1 second, the queue will be held up waiting for the top message to finish.
  • The dispatcher shouldn't really be handling the time.
  • Everything is passed by value.
All these things are fixable with some brain power but getting the first implementation out of the way is key to figuring the fixes out. For the next step, it would make sense to create a class that handles the updating and displaying of the messages that it receives from the dispatcher. This way the dispatcher only has to worry about getting the messages to the right place each update.

As the class is static, you could have anything send messages to the dispatcher. it could also be modified to display sprites or play sounds (although I would define a set of events as enums instead of sending the sprite/sound itself).

The code may look a little odd in the dispatcher but the above link to the chapter in Robert's book explains what it's doing far better than I will be able to.

Thursday 18 November 2021

C++ & SFML // Simple Timer

So I'm currently working my way through making a clone of Space Invaders using SFML and I got to the point where I needed to do something after X amount of seconds. Usually I use FLTK and that would've been simple using it's callback system however SFML is event based and as such doesn't really supply a "timer system" out of the bag like fltk.

Therefore I googled and eventually found pieces of what I was looking for and managed to put this simple demonstration together for those who just want to figure out how to get seconds displayed on the screen. This is what the "tutorial" will give you:

C++ & SFML // Simple Timer displaying seconds passed

The program does 2 things:
1) Display the number of seconds since the program started
2) Every second it chooses a random message (from 4) to display.

Very exciting. Let's begin.

Here is the full code:

Have a look, it's all in main for simplicity. 

There is a clock that is restarted at the beginning of the main loop and assigned to DeltaTime.
SFML have handily provided a way to get the DeltaTime as seconds. All you have to do then is += that to a variable defined outside the loop and you have your seconds since the program started.

For the text, I just made a variable that holds the max time we want to show the text for (maxDelay) and another variable to hold the elapsedTime. Getting the elapsed time is the same as getting the seconds above only when updating which message to display, there is a check to see if the elapsed time has gone above the max delay. If so, it changes the message and resets the elapsed time back to zero.

The concepts here can be used for many other things like displaying a sprite for a given amount of time as well creating more complicated things, like an event queue system that dispatches events based on the elapsed time (much more useful for larger projects than above).

for an example on how this can be put together.

Saturday 13 November 2021

LP's 12 Months of Games // Thomas Was Late [C++ & SFML]

Completed Via Tutorial

The 4th game taught in "Beginning C++ Games Programming" by John Horton and there are some more things I found strange:
  • The engine class had 4 functions but only the constructor and 1 other function were defined in the cpp; the others were given their own cpp file....I have honestly never seen this. I can understand wanting to keep the code "manageable" but just collapse the function? There are class definitions in Unreal Engine thousands of lines long. If you're having trouble use Alt+G to directly go to the function or just Shift+F and search.
  • The private const member variables in classes. If they're private, they can only be used within the class anyway so move them out of the class and into a private namespace in the cpp. Those variables are padding out the size of the class; all those bytes add up; especially if you are creating many instances of the class (as games often do). The const variables in the namespace will still be static but at least they're only being created once instead however many times you have created instances of the class they were in.
  • There are also other implications on your classes to do with move/copy constuctors caused by const members.
  • I've also seen some "Variable const x", especially in function argument parameters. Yes the compiler will accept it but it's good practice when declaring a const variable to have the const before the type. You may see const after a function declaration but that is promising that function doesn't modify any member variables inside the function. The const before the function return type specifies that return value cannot be modified.
  • The given code doesn't actually work or compile. 
  • Pointer pointers were introduced....in a book aimed at those who have never programmed before....I have no words. I know you can't create a 2d array without using values defined at compile time but that's because it's an array; just use a vector. This is not Beginning C Games Programming.
  • The LevelManager should be holding an instance of the level vector array, this eliminates the need to new anything up. In the original code the pointer is returned to a different class. If it has to be a pointer at least ensure that whatever is holding the pointer frees it properly in the destructor (or better yet, use smart pointers).
  • He includes headers in cpp's that have already been included in the matching header file.
I will admit, I did find this funny though:


Finished Result:
The tutorial spanned from chapters 14 - 18 and I stopped halfway through 17 because the game is severely broken:
LP's 12 Months of Games // Thomas Was Late [C++ & SFML]

I don't have time to get this working nor do I really care. There was something going on with the drawing and ordering of the sprites vs the background. Left and right were only for the green shape, A and D were for the red. It knew this when input was received yet for some reason it decided to apply the updates to some other sprite.

There's only space invaders left now which should be more fun; this one was a bit dry.

Code:
No code drop for this one. The authors repository for the book is here though:

Friday 12 November 2021

LP's 12 Months of Games // Zombie Arena [C++ & SFML]

Completed Via Tutorial

Another tutorial finished from "Beginning C++ Games Programming" by John Horton. 

Please do not use this book to learn C++. Some things boggled the mind when following this tutorial like:
  • variable + 0 (???)
  • Creating a header, only for it to contain functions that are neither marked as extern or static or within a namespace. One function returns a raw pointer which is deleted somewhere else...
  • #pragma once #ifndef #define combo (pick one. I like ifndef define because it's slightly more portable).
  • Constant float to int/int to float with no casting or safety in place. For example, he'll choose to make an int variable but only use it with a float???
  • Singleton classes. Don't get me wrong, I like singletons but this is not the best way to do it. The constructor should be private with copy and assignment deleted. There should instead be a static public function that declares and returns a reference to a static instance of the class to ensure it is destroyed properly.
  • Member functions that don't modify are not marked as const nor is anything returned by const reference if it can be.
  • Initialises class members in the constructor body instead of via initialiser list; this causes the member variable to be default initialised and then assigned again.
  • Const member variables are initialised in the class body definition??? static const integral types yes, but otherwise for linking sake, it's best to initialise const members in the constructor.
One thing that really bugged me was all the event handling for input was done in main. I am a firm believer that objects should handle input events themselves. That said, the author promised at the end of this game that there will be better code handling in the next two projects so I'll hold further judgement until I finish the book.

Finished Result:

LP's 12 Months of Games // Zombie Arena [C++ & SFML]

I was having fun with this one by the end. I quite like "Demakes" and I think this style would make a good Left 4 Dead demake. The hitboxes on the zombies are a bit janky and I'd like some background music but other than that I'm actually pretty happy with this one. 

It taught some solid SFML concepts that I can take away to personal projects. I'm itching now to start Tetris or my own version of pong to apply what I've learnt but I'm going to finish the book first as he mentioned using more advanced sound features, particle effects an split-screen in the upcoming chapters.

Code:

There's a code drop for this one as I feel I changed it enough. Assets haven't been included for copyright reasons but here is the authors repository:
https://github.com/PacktPublishing/Beginning-Cpp-Game-Programming-Second-Edition

Tuesday 9 November 2021

Chapter 22 // Exercise 7, 8, 9, 10, 11, 12, 13, 14 - Principles & Practice Using C++

The following exercises are once again all word-y ones. Some of this stuff is interesting to learn but I'm not writing any essays; I've done my time.

Chapter 22 // Exercise 7

We have "missed" many important languages. In particular, we essentially had to cut all developments after C++. Make a list of five modern languages that you think ought to be covered and write a page and a half (lol) - along the lines of the language sections in this chapter - on three of those.

So I guess the 4 "major" ones not covered would be; Python, Java, Javascript (and all it's fecking friends) and C#. I couldn't decide on the 5th but I guess Objective-C is pretty popular with those iOS programmers *shudder*.

Chapter 22 // Exercise 8, 9, 10

8) What is C++ used for and why? Write a 10- to 20-page report.
9) What is C used for and why? Write a 10- to 20-page report.
10) Pick a language (not C or C++) and write a 10- to 20-page description of its aims, origins and facilities.


In all seriousness; C++ is used by people who like programming and C is used by people who like torturing themselves; just use C++ (unless you're in embedded systems or something).
Java - Used by people for reasons unknown.

Chapter 22 // Exercise 11

Who currently holds the Lucasian Chair in Cambridge?

According to this source:
It's Professor Michael Cates. I had no idea what the Lucasian Chair was before this; it was founded in 1663 and is one of the most prestigious academic postings in the world? Apparently, in Star Trek: TNG, Data is the current holder.

Chapter 22 // Exercise 12, 13, 14

12) Of the language designers mentioned in this chapter, who has a degree in mathematics, who does not?
13) Of the language designers mentioned in this chapter, who has a Ph.D? In which field? Who does not have a Ph.D?
14) Of the language designers mentioned in this chapter, who has received the Turing Award?

David Wheeler: Awarded the worlds first PhD in Computer Science in 1951 (very cool). 
Maurice Wilkes: PhD in Physics. Turing Award in 1967.
Stanley Gill: Mathematic degree (I think). Has PhD, not sure what in.
John Backus: Doesn't have a PhD, but has a bachelors and masters in mathematics. Turing Award in 1977.
Grace Murray Hopper: PhD and BSc in mathematics.
John McCarthy: PhD and BSc in mathematics. Turing Award in 1971.
Peter Naur: PhD in Philosophy. Turing Award in 2005.
Edsger Dijkstra: Has a PhD, doesn't say what in. I'm guessing Computer Science. Turing Award in 1972.
Niklaus Wirth: PhD in Electrical Engineering and Computer Science. Turing Award in 1984.
Anders Hejlsberg: Has no PhD but is the current lead dev for C# at Microsoft, found him on Teams. I always find it amusing that I can just send fellow Microsoft employees a DM. There is a part of me that just wants to send Satya Nadella "yo whattup??". But I like my job and don't want to lose it.
Kristen Nygaard: Msc in Mathematics. No PhD. Turing Award in 2001.
Ole-Johan Dahl: Unsure what education he has. Turing Award in 2001.
Dennis Ritchie: BSc in Physics and Applied Mathematics. PhD never officially received. Turing Award in 1983.
Ken Thompson: BSc in eletrical engineering and computer science. No PhD. Turing Award in 1983.
Doug McIlroy: BSc in Engineering Physics. PhD in Applied Mathematics. 
Brian Kernighan: BSc in Enegineering Physics. PhD in Electrical Engineering.
Martin Richards: BSc in Mathematics. PhD in Programming Language Design and Implementation.
Christopher Strachey: BSc in Natural Sciences Tripos.
Bjarne Stroustrup: MSc in Mathematics and Computer Science. PhD in Computer Science.
Alex Stepanov: Not a lot of info on this man.


Monday 8 November 2021

LP's 12 Months of Games // Basic Pong [C++ & SFML]

Completed Via Tutorial 

This is the second project taught in "Beginning C++ Games Programming" by John Horton. The two chapters mainly focused on teaching classes and multiple files so the actual pong game was lacking.

Finished Result:

LP's 12 Months of Games // Basic Pong [C++ & SFML]

The "bat" is far to quick and moves off the sides. The ball scrapes along the bat or becomes stuck resulting in ridiculous scores and there's no states like a menu or game over. The basics are there though but I'll be improving this over the next week to add better collision, sounds and "english" (where the ball bounces off the bat with a certain velocity) as well as multiplayer.

I did finally learn how to use Github with Visual Studio though in this exercise. It's quite painless once you get used to it. I still prefer Perforce but for project sharing/collaboration, Github is the clear winner. That won't stop me from using Perforce though.

Code:
I modified the code in the book however it's mainly from the tutorial so I won't be posting. The next Pong game I will though.

Sunday 7 November 2021

LP's 12 Months of Games // Timber!! [C++ & SFML]

Completed via Tutorial

I started a book called "Beginning C++ Games Programming" by John Horton. It's aimed at those who've never used C++ before and teaches you how to make 5 games using SFML. I thought this would be the perfect introduction to SFML as I could ignore the bits about C++ and focus on the library. I was right.

I've just completed the first game; Timber!! I've used sfml once, many years ago to try and make pong. At the time I had been learning cpp for about 6 months and found it utterly confusing. This time, thanks to experience with FLTK and DirectX it was more "ah so this is how I get a sprite, this is how I draw it, this is how you poll events" etc.

I'd say this project would take a while for a complete C++ beginner but it was perfect to showcase on how to get to grips with sfml. I'm looking forward to the other 4 games and learning other sfml features.

As for the tutorial itself; I don't like the amount of hardcoded numbers and the fullscreen game (I prefer windowed when debugging). All the textures rely on the screen being a certain size as well but I can remedy that in my own projects. Also, the author is extremely bias to arrays and OOP with the code being very java-ry. I wouldn't recommend the book for first time C++ programmers as I feel it would teach some bad habits; make sure you use Principles & Practice for cpp.

Finished Result:

LP's 12 Months of Games // Timber!! [C++ & SFML]

The assets were all provided by the book and I made a few adjustments to the code but other than that it's pretty much what the book gives.

I will say I'm extremely surprised by just how easy SFML actually is to use. I'm already formulating how to get a tetris game working or match 3 from just doing this simple game. So I guess it was a good tutorial overall.

Code:
A code drop will not be provided for this one as it's mainly from the book.

Saturday 6 November 2021

Challenge // LP's 12 Months of Games

So I'm an engine programmer...I like optimisation and tool creation. I'm at my happiest when making/doing things that makes gameplay programmers lives easier. That's mainly because I find the more gameplay aspects of games, well, tedious. 


The problem with this mindset though is that ultimately it makes me a terrible engine programmer. I can't make the best game engines if I don't know how games work. Like I know how a game works in the logical sense of how a computer understands it but I don't understand the nuances of level design, timing, AI, suspense, re-playability, state, message dispatching, entity systems, stat balancing...the list is endless. Hats off to gameplay programmers; you are wizards to me.

That's why, I'm designating the next 12 months as the year of games (it was originally supposed to be a new years resolution but I always fail at those so I'm starting early to try and trick myself). I'm going to attempt to make a game every month; no matter how shitty or simple; I want to make a game that has a start, a middle and an end. I've already got some ideas like:
  • Slenderman clone in UE4 (I already half started this in 2020 and then got bored when I had to actually make the game)
  • Tetris
  • Solitaire
  • Pong
  • Space Invaders
  • Doom
  • Five Nights At Freddy's clone
  • Super Mario World clone (not the entire game...jesus like 1 or 2 levels)
  • Game Jam entry (probably Ludem Dare or Haunted PS1)
  • Bejewelled clone
  • Minecraft??
I want a good mix between styles, like shoot-em-up, platform, 3D, strategy, etc. Also I need them to be well documented so I don't get caught up in deciding what game mechanics to put in. I've noticed that if there is too much choice, I get overwhelmed and abandon the project. I think that's why I'm such a terrible gameplay programmer; the ability to do anything is too much and I just want very specific projects like; implement rotating images. Add animated gif support.

For the more classic games I'd like to just use C++ and DirectX or FLTK/SFML and then Unreal for the 3D games...I might even make slenderman in UE5 as I've not even opened that thing yet.

I'm saying 12 games because I feel that's more realistic, however if I feel like making something new every weekend I'm not going to stop myself. I'll update this post with games as I finish (or not finish them) and I'm excited to see how I've done by November 6th 2022.......

EDIT:

Wednesday 3 November 2021

Chapter 22 // Exercise 6 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 22 // Exercise 6

For each language mentioned in this chapter, look at a popular textbook and see what is used as the first complete program. Write that program in all of the other languages. Warning: This could easily be a 100-program project.

Github: 

Due to the warning I decided to do something different as I don't have that much time (and I get bored easily). So instead, I went back to Chapter 3 (had a nostalgia trip) and decided to implement Exercise 2:
"Write a program in C++ that converts from miles to kilometres"
This needs input, output and some mild arithmetic; perfect.

As for the languages; I spent a couple days doing the previous exercise and that was just Hello World programs so I chose 9 of the 20 languages I got running. 5 of them are languages I'm most likely to use (and most have VS support). The other 4 are "legacy" languages and completely outside my comfort zone.

1) C++
To start off here is the nice C++ console version:

2) C
This was trickier than I expected. Reading in from the console is not as nice as cin >>. Also I forgot that bool isn't a native type in C but was added in C99 via stdbool.h. I also spent a bit too much time faffing about with VS Code so I could build and run C code in that. Honestly doesn't feel worth it; will continue to use VS.

3) Visual Basic
This was a task. First I had to google how to make functions in VB, then how to make variables, then how to write if else and compare.....This language is strange. It uses = for equality AND assignment disgusting. I also hate how everything is english yet cobol....
Dim number As Integer = 0
is way more tedious than
int number = 0;

4) Python
So I learnt that Python doesn't support const values and I found this answer from Stackoverflow amusing:
"No there is not. You cannot declare a variable or value as constant in Python. Just don't change it"
Just don't change it. If only it were that simple. It's also weird not having a main and everything is out in the open with no brackets. I hate loosely typed languages and languages that insist on not instead of !. I think I'm just set in my ways at this point.

5) Java
The only good thing about Java is that it uses semi-colons; praise be to semi-colons and brackets. The importing of everything and creating NEW of everything annoys me constantly though. When I'm making apps it just feels like every other line is 
SomeType = new SomeType(Stupid.Long.Type.Name);

6) C#
This one took me about 5 minutes; I was surprised. It was like a Java version of Visual Basic....I guess that sums up C# in a nutshell.

7) Pascal
This was truly the strangest so far...the function definition is so unnecessarily complicated. Also when multiplying a float (or real in Pascal) with another float, the point was always in the wrong place. I couldn't figure this out and frankly I don't care enough.

8) Fortran
This one took me a good 40 minutes and I initially almost gave up as I could not for the life of me figure out how to get functions to work. I now see where Visual Basic comes from. It wasn't completely awful once I'd figured out the function definition and logical operators/loops. I can understand why no one wants to learn it anymore though...

9) Cobol
I'd honestly rather program in straight up assembly than this monstrosity. It's ironic that the syntax was chosen for "readability" but ultimately it makes it more confusing. Also, calling a variable a 'picture' because you give the computer a 'picture of the value' is stupid.

This one I had to skip because it was just too different. I think Cobol has user defined functions but I couldn't figure out how to make one. Variables need to be declared up front in a "data bank" of some sorts which is almost identical to ASM.

I feel sorry for anyone who was forced to use this language professionally.

10) Simula87
And I also gave up on this one because I just couldn't anymore. The further I stray from C++, the more I want to jump off a cliff.

// Conclusion
This exercise was amazing and I highly recommend that you choose an exercise from Chapter 3 and implement it in other languages. It made me realise that Visual Studio is God, semi-colons must always end an expression and loosely typed languages should have a word with themselves (pun intended).

Attempting the exercise in Pascal, Fortran, Cobol and Simula was the most "enlightening" though. Bjarne said he made C++ for a "more enjoyable" programming experience; he wasn't lying. Programming in C++ is pure joy, not just in comparison to "legacy" languages but new ones as well. I can safely say that there is no other language I would rather program in and it's not because C++ was my first language but I genuinely believe it's the easiest and most straight forward language of them all.

Learn C++ first.

A huge shout out to TutorialsPoint though for their excellent overview of all the ancient languages.

Sunday 24 October 2021

Chapter 22 // Exercise 5 - Principles & Practice Using C++

Chapter 22 // Exercise 5

Write a "Hello, World!" program in each of the languages mentioned in this chapter.


[Preface] Ok so....not counting various revisions of languages (like C98, C11); I counted 29 (?) languages. Now I don't know if we're just supposed to write the hello world program or actually get it to compile and execute?...I'm guessing the latter. That means I have to figure out at least 27 ways to build a language and a lot of these aren't in use anymore....hooo boy.

LETS BEGIN.

1) C++
The most obvious and easiest (for me):
This was extremely nostalgic and I had to pause for a moment as it took me back to January 2016 when I first saw "Hello, world!" in C++ and wondered "how the hell am I ever gonna remember what all this shit does?"

2) LISP
Lisp is quite honestly, disgusting, and I never want to look at it again.

3) FORTRAN
Trying to get Fortran to build on Windows honestly went over my head. Apparently there is an Intel Fortran compiler for Visual Studio but  I couldn't find it. I ended up using an online compiler again.

4) COBOL
Oh my christ; what is this?? It's like assembly and the terminator had a child.

5) ALGOL68
So this is where Python comes from? The Algol68 Hello, World is more efficient than the normal Algol but it took me a while to figure out how to add comments.

6) SIMULA87
This is a strange one. It's kind of like pseudocode but it runs....the comments also need semi-colons at the end which is weird. It's like a combination of Fortran and Pascal syntactically.

7) BCPL (Basic Combined Programming Language)
Apparently this the language that they used to program compilers with! The very first Hello, World! was written in this language as well so doing this felt like some sort of programmers pilgrimage. The language was created by Martin Richards who rivals Bjarne himself for the most "programming language creator" website in the world:
Sometimes I feel like blogger is too much and I too should resort to plain HTML.
More fun facts, it was the first brace language! And introduced // for comments (which C rejected).

Unfortunately there is no online compiler for BCPL, however it was recently revised by Martin himself as recently as 10th October 2021! So for this one I ended up getting the most recent version of the compiler and then spent all Friday evening trying to get it to work. Narrator: it did not work.

Even using the pre-compiled applications wouldn't work and it would exit immediately with an error. I think it's something to do with the date as it thinks it's January 13th 2020. Excellent. Oh well. I learnt a lot about batch files in this one so there's that!

8) PL/1
The aptly named "Programming Language 1" language also doesn't have an online compiler; or any compiler for windows. Just Linux and something called z/OS. I'm not interested in going to great lengths to get these to work. I did look at the hello world sample on Wikipedia though and I hate it.

9) PASCAL
Pascal I've come across before. Chapter 18 Exercise 11 asks you to implement a skip list and I used a paper that used Pascal. It's not completely awful. Fortunately it has an online compiler.

10) C
Ah C, my old friend. Compiling C with Visual Studio is quite simple but at least you can just create a new C++ project, add C files to it and VS should compile with the C compiler if it sees .c extensions.

11) HASKELL
This one was simple enough. It looks a bit strange; not sure how I feel about it.

12) EULER
The wiki page is short for this one and I can't find much about it. It seems it fell out of favour and no one is really using it anymore.

13) MODULA
Niklaus Wirth really loved creating programming languages. Apparently Modula 3 had an online release in 2010 but the websites look really dodgy and I don't fancy downloading weird applications off websites to try and compile it.

14) OBERON
Niklaus Writh is back in this list for the 5th time! (I think). Oberon had a stable release last year however there's no online compiler apart from one that converts Oberon to Javascript?? I did find this amazing website though:
I must check out lolcode. It seems like the language for me.

15) TURBO PASCAL
Ok so Turbo Pascal isn't actually a language; it's a compiler/IDE for Pascal??

16) DELPHI
Delphi also isn't a language; its an IDE and another Pascal compiler.

17) ADA
Not the bitch in the red dress, a programming language. Another Pascal-like language with what wikipedia says "extremely strong typing", not just strong but "extremely". 

Also, this quote from Bjarne's Website:

Do you really recommend Ada over C++ for larger projects?

No. I have no idea who started that rumor, but it must have been an over-enthusiastic or malicious Ada devotee.
 

18) SCHEME
Oh no....a LISP language KILL IT WITH FIRE.

19) CPL
So this is the predecessor to BCPL? It seems to be maintained which is cool however it's only for Linux and even the Windows version wants you to have a Linux subsystem so no thank you. 

20) B
I feel like when I'm on Wikipedia looking at pages for the Jurassic age with all these ancient languages and "predecessors"/"ancestors" talk. B is very similar to C and someone made a working compiler for it but it's janky. Also, just use C. I learnt that B was implemented and then C immediately came out. I've read a few comments around saying how small B is and "any good programmer should be able to implement it". Sounds like a good exercise.

21) SMALLTALK
Another object-orientated language derived from Simula. Wikipedia says its an entirely reflective system which is interesting and could be worth learning to understand how Unreal Engines Reflection system works (it uses reflection for the editor/blueprints). The hello world is a one liner in this project and looks completely unlike an object-orientated language.

22) EIFFEL
An object oriented language that ended up influencing Java and Microsoft Java and is still in use today! You have to make a class and then do things with that class...a true Java Parent....disgusting. Also, if you google eiffel stuff it almost always brings up pictures of the eiffel tower.

23) VISUAL BASIC
In all seriousness though I actually didn't mind this one? I think it's because it was extremely easy to set up and run thanks to Visual Studio. I kind of like how it looks as well, plus it comes with a console window....Also, Excel uses a form of VB, maybe I'll finally become an Excel wizard?

24) PYTHON
Oh Python...how I detest you. We had a brief module in the first year of Uni where we had to create a networked version of noughts and crosses using Python. I hate Python. However back then, Visual Studio had only begun to toy with the idea of adding Python support so I had to use the Python thing; Idle (which I also hate). Now VS has full Python support and makes this Hello World a painless 1 liner.

25) PHP
I was weirdly looking forward to this one as everyone online seems to think PHP is the anti-christ or something. Yeah it looks a bit strange but have they ever used Lisp??? To be honest I don't understand the fuss with this language? It's basically just HTML with added functionality.

26) JAVA
I also detest Java with a passion however I am strongly team Android and as such use Android Studio quite often. Even though I hate it, I'd say it's my second most-used language and thanks to learning C++ first I didn't really even need to learn Java. I just google what I need to know as I go along. I used an online compiler for this as it's a nightmare installing IntelliJ IDEA and Android Studio takes 5 years to boot.

27) PERL
I don't really have any strong opinions on this one. Basically looks like Python.

28) C#
Sometimes I'm not sure which I hate more Java or C#. I have to use C# at work sometimes (as all our tools are written in it) and I hate it. Sure, it's fast to get things working and you see results quickly but the language is not for me. It does have an edge over Java though because I can use Visual Studio. 

Microsoft though has a really cool interactive website that takes you through learning the basics of C#:

29) JAVASCRIPT
And last (and certainly least) is Javascript where everything is THIS and VAR. Like PHP, this is just another way to add functionality to HTML. Due to its C++ style syntax I find it easier to understand than PHP but I don't like using it. I think it's safe to say I don't like any form of web programming.

And with that I'm done! I managed to compile and run 20/27 languages which is pretty cool and it gave me a real insight into language similarities/differences. It also made me seriously appreciate Visual Studio more than I already do. I think at this point I'm too far down the VS rabbit-hole and giving it up would feel like losing something dear to me.

I don't think using Online Compilers is cheating though; setting up language environments is tough and honestly one of the worst aspects of programming; I think that's why VS wins for me and a deciding factor over which languages I choose in the future.

Saturday 23 October 2021

Chapter 22 // Exercise 1, 2, 3, 4 - Principles & Practice Using C++

I thought about not doing these written exercises, however the entire chapter is about learning about history so you don't make the same mistakes/understand what came before and how that influences the present.

I actually enjoyed looking up all these random people. Well not all of them are random (I'd heard of most of the computer scientists) but the non-scientists were more interesting.

Chapter 22 // Exercise 1

Define programming.

Github: N/A

I would say programming is the art of making a computer do what you want.

Chapter 22 // Exercise 2

Define programming language.

Github: N/A

Using page 807, a programming language is many but most notably a tool for making the computer do what you want. There are many different languages that do different things but having standards for those languages allows effective communication between programmers. I used to be a flight attendant for Emirates. The global aviation language is English; when flying, relaying instructions etc., it is imperative you speak English so everyone is on the same page.

Chapter 22 // Exercise 3

Go through the book and look at chapter vignettes. Which were from computer scientists? Write one paragraph summarising what each of those scientists contributed.

Github: N/A

Well I'm not writing a paragraph...later on he wants 10-20 page reports on C++....ain't nobody got time for that.

Chapter 2 - Brian Kernighan; Canadian computer scientist that contributed to the development of Unix and C (and many other things).

Chapter 4 - Gerald Weinberg; American computer scientist who specialised in the psychology and anthropology of computer software development.

Chapter 5 - Maurice Wilkes; British computer scientist who designed and helped build the Electronic Delay Storage Automatic Calculator (one of the earliest stored program computers) and invented microprogramming.

Chapter 6 - Kristen Nygaard; Norwegian computer scientist who is the co-inventor of object-oriented programming and Simula.

Chapter 13 - Alan Perlis? This chapter says traditional however google says Alan Perlis but it isn't sure. Anyway he was an American computer Scientist and was the first recipient of the Turing Award.

Chapter 17 - Alex Stepanov is a Russian-American computer programmer best known as the primary designer and implementer of the C++ Standard template library.

Chapter 20 - Douglas McIlroy is an American (?) mathematician, engineer and programmer. He participated in the design of many influential languages (including C++) and is still a professor at the age of 89.

Chapter 21 - Trygve Reenskaug is a Norwegian computer scientist who formulated the model-view-controller patter for graphical user interface software design.

Chapter 22 - Alan Perlis. See Chapter 13 description.

Chapter 26 - Donald Knuth is an American computer scientist and called "the father of analysis of algorithms).

Chapter 27 - Dennis Ritchie was an American computer scientist and co-creator of the C programming language (amongst many other things).

Chapter 22 // Exercise 4

Go through the book and look at chapter vignettes. Which ones were not from computer scientists? Identify the country of origin and field of work in each.

Github: N/A

Chapter 0 (Switzerland?) - Swiss army proverb . I google this and it came up with many other books also using this quote in their chapter vignettes but couldn't actually find a source for it.

Chapter 1 (USA) - R A Heinlein is a Science Fiction author and this quote is from the "Competent man". Apparently a competent human should be able to do such things as "build a wall", "pitch manure", "solve equations, "butcher a hog", "die gallantly" amongst other things....

Chapter 3 (France) - Louis Pasteur was a French chemist and microbiologist renowned for discoveries of the principles of vaccination, fermentation and pasteurisation...I actually found this very interesting. I guess Pasteur is where the word pasteurisation comes from.

Chapter 7 (USA?) - First recorded use was Dallas Morning News in 1976 apparently.

Chapter 8 (USA?) - It says "traditional" in the book but google attributes this quote to Marion J. Levy Jr who was an American sociologist noted for his work on modernisation theory.

Chapter 9 (Denmark) - Peit Hein was a Danish polymath. He also invented the Soma cube and the board game Hex.

Chapter 10 (USA) - Richard Feynman was an American theoretical physicist known for many things made out of big words. He looks more like a Hollywood actor than a scientist.

Chapter 11 (Germany) - Albert Einstein was a German theoretical physicist who practically invented all physics (I'm exaggerating but he made a lot of contributions). I had no idea that he died in 1955, I thought it was much later.

Chapter 12 (USA) - Calvin and Hobbes was a daily American comic strip that I had never heard of until researching this. I literally put "Calvin's dad" into google and it knew exactly what I was talking about. Google says it's cited as "the last great comic newspaper". Clearly they had never heard of Garfield.

Chapter 14 (Roman Republic) - A Roman author, architect and civil/military engineer during the 1st century BC.

Chapter 18 (?) - Caveat Emptor is apparently a Latin phrase that means "let the buyer beware".

Chapter 15 (France) - His actual name is Francois-Marie Arouet (quite possible one the Frenchest names I've encountered) and was born 1694. He was an French "enlightenment" writer. I'm guessing that's not to do with new age stuff but more philosophy. 

Chapter 16 (USA) - Nicholas Negroponte is a Greek-American architect and stupidly rich.

Chapter 19 (UK) - Winston Churchill was the Prime Minister of the UK from 1940 till 1945.

Chapter 23 (USA) - Errol Morris is an American film director known for documentaries. 
 
Chapter 24 (USA) - Henry Louis Mencken was an American Journalist.

Chapter 25 - Pretty sure Bjarne made this one up.

Friday 22 October 2021

Chapter 21 // Exercise 15 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 21 // Exercise 15

Provide a GUI for the program from the previous exercise.


Oh this took an hour of just pure ctrl+c ctrl+v slight edit. I'm not surprised the creators of FLTK created Fluid, creating forms is tedious. But I powered through and I'm happy with the result.

FLTK Forms Chapter 21 // Exercise 15 - Principles & Practice Using C++

I did it! I managed not to procrastinate as much with this chapter and got it done in just under a month. With that I'm finally onto a chapter I've been looking forward to.