DEV Community

Gabe Corsini
Gabe Corsini

Posted on

Picking a Path: Discovering my programming language through Discord Bots Pt. 1/3

As a new developer, and one who is primarily self-taught, picking a programming language can be an incredibly daunting task. Amidst the myriad of frameworks, design-patterns, paradigms, and [insert fancy word here], what should ultimately be a simple choice can often times feel like the scene from Raiders of the Lost ark: There are all these cups to choose from, but only one is correct...

The Knight Templar from Raiders of the Lost Ark meme

Choose Wisely

Daunting may it be, I set out on this journey to pick the language I would be spending my time with. I've received a lot of suggestions on first languages, read all the "which language is best articles", and came to one conclusion:
Everyone's opinion is exactly that. Their opinion.
So, to build an opinion of my own, I developed a small project that would help me pick the programming language I wanted to use, rather than what I was told would be "best".

The project

When it came down to it, the project itself had simple criteria:

  1. Learn the very basics of three languages.
  2. Build a basic Discord bot with said languages.

To evaluate which of the three languages would be the one I wanted to spend my time, I had to judge them roughly on five (opinionated) items:

  • The learning experience as a new developer
  • The feel of writing code in that language
  • The speed/efficiency in getting started
  • The tools available out-of-the-box
  • The "satisfaction" of completing the goal

Before we move forward with the examples and verdict, I want to clarify three items:

  1. Not everything I code will be best practice or efficient or even entirely correct.
  2. I'm new to all of this. I've never written production code. My most advanced project is a custom PowerShell module I wrote for work.
  3. While my decision will ultimately center on some more ephemeral ideals rather than hard facts, I believe that sometimes you just got to go with what feels good rather than what is considered "standard" or "correct".

tl;dr I didn't LOVE Java, but I didn't hate it. However, it isn't something I would want to code in daily unless my job required it. I think it could probably grow on me in time, but for now it's going to take a back seat. Click here to see my final evaluation at the end of the article if you don't want to stick around for the rest of the article.


Language #1: Java

Java, a programming language coming out of Sun Microsystems before being bought out by Oracle, is a statically typed object-oriented language designed to be general purpose and cross-platform.

Java was the first language I picked for two main reasons: It is still one of the most used languages in enterprise software engineering, and my Twin brother suggested it. That's about it. So, I dove in, headfirst, to see what I was in for.

public class Main {
    public class void main(string[] args) {
        System.out.println("Hello, world!")
    }
}
Enter fullscreen mode Exit fullscreen mode

As you can see, the simple and inaugural "Hello, world!" is a little less than simple. Java has a level of verbosity to it that makes sense. Every keyword clearly defines the languages intent. The availability of the class and its method, the return type of that method, and the type of any variable we use. This creates a level of safety when writing Java code, with everything being so explicit, but it also creates an intense level of boilerplate code that can start to feel like a hinderance to speed and efficiency. While those aren’t the most important factors for picking a language, it does add some weight.

Here is my favorite example of this kind of verbosity and boiler plate from the Discord bot I wrote, using the javacord Discord API wrapper, where I created a method to read my bot's token from a text file and return it as a string. I was told that I could have made this a lot simpler if I had use a .properties file or some such solution, but I have NO idea how that works yet so this is what we get.

 public static String tokenreader(){

        String line = "";
        File file = new File("[path/to/token.txt]");
        try (BufferedReader reader = new BufferedReader(new FileReader(file))){
            while ((line = reader.readLine()) != null) {
               return line; 
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return line;
    }
Enter fullscreen mode Exit fullscreen mode

This was the solution I had to utilize to pull the token string out of another file (for the sake of safety and not accidentally committing my bot's token to the repo) and utilize it to connect the bot to my discord server "Bot Lab". This is not a simple, or even pretty, solution by any measure, and left me more confused than when I started. This nicest part of this snippet of code is the try-with-resources, which allows you to open BufferedReader and close it when done rather than have an explicit close statement (read more about it here).

Verdict

In short, Java struggled to meet a lot of my criteria when writing code. I'll try to summarize my thoughts as follows:

  • The learning experience as a new developer
    • Java, as a language, isn't the MOST user friendly initial learning experience. There are a lot of keywords and syntax you have to get through before you can print "Hello, world". You can ignore some of it in the beginning, but as you continue to learn you'll need a steady understanding of those keywords to move forward.
  • The feel of writing code in that language
    • Due to the verbose nature of Java, it can kind of make you feel like you're a serious developer. Unfortunately, a lot of what you're writing is keyword boilerplate, but writing a simple program like this discord bot was satisfying.
  • The speed/efficiency in getting started
    • In short? There wasn't any. It was a slow process for me, period.
  • The tools available out-of-the-box
    • Minimal at best. You get the language and that's about it. Gradle, a build tool for Java projects, is what you'll need if you're going to build and test larger scale projects, but in the beginning it's more confusing than it is helpful. I tried to use it for this bot, and I think I spent more time figure out Gradle than I did writing the bot itself.
  • The "satisfaction" of completing the goal
    • Making Java work is actually quite satisfying. Writing all that code, all those lines, and having a finished project at the end feels pretty damn good. If I cared more about the number of lines I've written, I'd love coding in Java more, but I'd rather less lines and a better feel.

Here is a screenshot of what I managed to get the bot to do. It isn't much, but it allowed me to make my evaluation.
Image description

Thanks for sticking around long enough to get to this point. If you enjoyed the read, stay tuned for part 2 where I'll go through the same process and build the same bot but in Python.

Happy coding!

Top comments (1)

Collapse
 
beard_corsini profile image
Andrew Corsini

Excellent article! Looking forward to seeing the other parts!