Zach Cochran

fuzzy blog

Daily notes about things I've learned.

TIL: Strings

Today we’re going to talk a little about strings. I had initially been trying to plan out something that was much larger than this, but after more consideration I decided that I wanted to keep this short and better scoped. Sometimes I worried that I’m too close to going off on tangents instead of just talking about what I learned about. Like i’m doing now… Some Things About Strings Strings are pretty basic conceptually, right?

TIL: Inheritance pt2

We’re going to continue where we left off yesterday and discuss a few more things related to inheritance. Now that we have a good understanding of how inheritance works there’s a few more things to cover to round out our understanding. Final When defining your class and methods, you have a variety of keywords available to tag onto definition. This typically would go in front of the type declaration. One of these keywords is final.

TIL: Inheritance pt1

Coming off of the talk of constructors and variables, we’re going to move on to the concept of inheritance. This is a topic that completely baffled me back when I took coding classes in school… of course that’s not really saying much as most of the classes had left me completely confused, but I digress. Inheritance isn’t that hard at all and it actually provides a huge amount of functionality to your code by using it.

TIL: Variable Number of Parameters in Methods

We’re going to build off of the method discussion from yesterday a bit more and cover the topic of sending n number of parameters of a specific type to a method. There are occasions where you might want to support anywhere from 1 to n number of a type of parameter in a method. In the case of the Flight class example from yesterday, maybe we want to be able to register more than just a single person at a time to the plane.

TIL: Overloading

Today we’re going to take a look at overloading in Java. I really don’t understand why they call this overloading, but it’s essentially exactly what we talked about yesterday with constructors. You can define multiple methods with the exact same name within a class, each with a unique set of accepted parameters that make the method distinguishable. Just like last time, all of this code is available in my github repo.

TIL: Constructors

Today we’re going to take a look at constructors in Java. I’ve been slowly working my way through a bunch of intro level java courses over on pluralsight after a coworker had recommended the site to me a few weeks back. After jumping around between different lessons, I finally decided to land on the fundamentals course and stick there. Thankfully most of it has been review, but there’s been some stuff (like this), that’s been new info for me.

TIL: Loading YAML With Jackson

Wanted to use a YAML file for some config settings in a new app I’m writing, so I needed to look up how to do so in Java. Lots of people pointed to using Jackson for doing the loading, which seems to be the defacto when doing json reading as well. The first thing that I found while doing this was that the process is much much much more involved than simply reading in files in other languages.

TIL: Python Exceptions From Functions

Wasn’t really sure what to call this, but it’s something neat and also something that really shows just why using exceptions is so much better than returning back some other junk. Let’s suppose that I have the following code: 1 2 3 4 5 6 7 8 def myAge(age): return "You were born in {}".format(birthYear(age)) def birthYear(age): if age < 0: raise BadAgeException("You are not alive!") else: return 2018 - age The myAge function turns around and makes a call to the birthYear function, which it relies on for completing its task of printing out your birth year based on the number you provided.

TIL: Unit Testing Python Exceptions

So yesterday I talked about how you can create your own unique exceptions within your package. But how do you go about testing for them? Or testing for any exception for that matter? Let’s take a little look into it. Let’s suppose that I have one of the exceptions defined in my application that I talked about yesterday: 1 2 3 4 5 6 class RandomUserError(Exception): def __init__(self, message): super(RandomUserError, self).

TIL: Creating Custom Python Exceptions

Honestly this is something that I learned many many months back but evidently never wrote about (I’m not really sure why). I had to do a small side project at work and I needed to revisit how this was done. Thankfully I already had a project completed that I could steal off of! So the goal here is to try to make the transition away from returning something like a failed stated from a method you provide.