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.
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.
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.
a new beginning
A New Beginning - Again
Hi, I am tardis1 and, yes, I am a Whovian, but I am also many other things as well.
Yes, this is a new beginning for the TARDIS Server Project. I have made several of these over the years, but they all lacked something. Maybe this time will be different.
I grew up as a child during the Gemini and Apollo space flights. Like many others of that era, I wanted to be an astronaut. However, my poor vision ruined that by the time I was a teenager. Yet, there were still space things I could participate in. One of those was computers.