Easy Weekend Refactoring Java to C++
Refactoring from Java to C++
After several hard weeks of RL and coding, I am taking it easy this weekend. I started a little project to increase my fluency in C++ and how to integrate it with make. I am taking some of my adventure game classes and refactoring to C++.
Here is the Thing class as it looks in Java.
Thing.java
import java.io.Serializable;
public class Thing implements Serializable{
private String name;
private String description;
private boolean takable;
private boolean movable;
public Thing(String name, String description, boolean takable, boolean movable){
this.name = name;
this.description = description;
this.takable = takable;
this.movable = movable;
}
public String getName(){
return this.name;
}
public String getDescription(){
return this.description;
}
public boolean getTakable( ){
return this.takable;
}
public boolean getMovable( ){
return this. movable;
}
public String describe(){
return " Here is a " + this.getName() + ": It is" + this.getDescription();
}
}Pretty straightforward. It is one of my base classes. And, here is the final look in C++. Doing it the alleged “correct” way is why there are two files, a header file and an implementation file. Using this method, I can mirror how I do it in Java with one class per file.
CI/CD Woes
How to screw up CI/CD without really trying
It begins
Yes, I am way behind on writing. RL keeps invading and I spent so much time recently trying to figure out how to create workflows that would showcase my work on an app.
I have a small Java console text adventure game I am working on. The goal is not the game, but the engine and the process of developing software. I am approaching a major point in the development. I am nearly at V1.0. I have someone that is testing the playability of the software. Having just a regular repo isn’t enough anymore. I needed something more robust. So, I started learning some of the things to do with CI/CD ( continuous integration, continuous development ).
Packaging software is not easy
Now I understand bloatware
I have not written in a while, which is not good. But, I have been so busy between RL work and my software work that I just have not had the energy or time. When I am at home, I have been working on learning how to package my adventure game. It is not as easy as it looks. I would liked to have written this post as a mini-howto on packaging via jpackage, codeberg, and github. Yeah, it’s not happening yet.
An overview of Gradle's build.gradle.kts
Background and beginning
If you read my previous post, you know that I recently spent a good deal of time debugging a Java build of a program. Not a bug in the Java code, but a bug in gradle, my build environment. Specifically, in my gradle build file: build.gradle.kts.
After going through that problem, I spent time, finally, not pursuing more programming, but learning how gradle’s build operated instead. So, this is a summary of that learning. Sorry, it’s going to be a bit long. But, first, I need to take a minute to go over background things so that we are all on the same page. If you read my post about writing and compiling a Hello World! program in C and in Java , you will know what a basic Java program looks like. You will also see that, in theory, you can compile a Java class with javac MyMain.java into a program.
Learning Gradle
A sleeping build time bug arises
I haven’t written in a while. Sorry. It’s hot here and I’ve been spending extra time working on the adventure game . I sat down to start writing some of the unit tests for the game. I wanted to do one simple one and test to see if everything built and tested correctly. I always do things in code incrementally; a little at a time and test. Sometimes, it seems pedantic, but it pays off. Though it was not expected to fail, JUnit pushed a failure during testing that hadn’t been there when no tests were available.
Zen and the Art of Server Administration
Making things easier
Now that the server has been online for a while, it is time to begin the work of ensuring the safety of the server. Mine needed its own firewall. It also needed the ability to ward off those that seek ill of my little server in my little corner of the Interwebs. Time to get my hands dirty. This is the story of logs, awk, bash, and bad guy databases.
Refactoring sometimes creates issues
Not as expected
I didn’t get much accomplished this weekend on my adventure game. While I did manage to get a ContainerThing class created, the next step kind of failed miserably.
ContainerThing was added as a descendent of the Thing:w
class so that we can have chests and sacks; things that have to be opened and closed before user access. That all went pretty well. I did have to adapt to using instanceof in order to access the isOpenable field and the open() and close() methods. But it worked out.
Why I like C
General Update Stuff
I haven’t been able to post in a couple of days. I thought I would update things. Also, because I sometimes don’t have access to my primary server, I want my readers to know there is a backup. You can also reach me here. I keep a Codeberg page. I can sometimes upload to it quicker.
I like to write code in C. Why would I say such a thing?
Hello World in C and Java
First steps in programming
Now, that we have all the background covered, I want to show you the beginnings of programming. I will be showing you the steps to build and run the ubiquitous “Hello World” program in both C and Java. The C version will use the C99 standard ( though it matches most standards as well ) and the Java version will use Java 17 ( though it will likely run in whichever Java you have ). These two language standards will be where I will work as I write more posts.
development stack
How I write code
I hope two write two posts today. I need to set things up for you all before I dive into code. I don’t know if others call the developer environment they use a stack, but that’s my term.
The reason I do this is that when I learned C#, I used what was good for me. I had Microsoft’s VS Code running on a linux machine with Dotnet Core . I was watching some learning tutorials on YouTube and discovered things didn’t work like the presenter showed them. After much frustration and arguing with the presenter, we both discovered that while I used Dotnet Core and VS Code, he used Microsoft Visual Studio and .NET. The two were not the same, though now they finally are the same. Since then, I am careful to note what I am using so that others will know beforehand.