R1D15 Methods and Exception Handling in C# and Azure Notebooks

I wrapped up the Introduction to C# course today by reviewing methods and exception handling in C#. Like Java C# supports access controls such as private, public, protected, and static.

My certificate is “signed” by Satya Nadella, which motivates me.

C# Certificate 1

C# Methods

I’ve never quite understood when the right time to use these types of access modifiers is. Conceptually it makes perfect sense, but I supposed I have not done enough OOP to come accross a case where I wouldn’t just want every single method to be public. From my understanding, it has to do with API design (in the strict sense of API not just “REST”). The whole purpose of OOP is to encapsulate pieces of code for further reuse. Public, private, static, and protected are meant to enforce the API contract that another developer using your library might be trying to implement.

You do not need to understand how the code in a method works. You may not even have access to the code, if it is in a class in an assembly for which you do not have the source, such as the .NET Framework class library.

This is something I hope to investigate and learn more about in the next few courses of this series.

I learned about ref and out, which are a bit strange to me. They allow you to return multiple values from a method call without having the method itself return anything at all. In python if we want to return multiple values we would usually return an array or some other list.

I also learned that you are able to used named parameters in C# methods. This is really cool. If you have a complex method that takes many optional arguments, you can specify the specific ones that you want by name. Or if you want to reduce ambiguity for which parameters are being passed in you can give them a name. I think this makes code a lot more readable.

C# Exception Handling

I also learned about C# Exception handling. This is actually something that I already knew a bit about since I spent a few yeasrs of my life in a previous job staring at C# call stacks trying to figure out what went wrong.

Overall Impressions

Overall, the course was fine. I think it was a bit short and I wish that it would have had more non trivial example problems. I am still going to keep going and start the next course in the series, Object Oriented Programming In C#,  tomorrow.

Azure Notebooks

I also spent a little bit of time playing around with Azure Notebooks. It is basically Jupyter as a service. I have used Jupyter quite a bit. Not so much for data science, but more for exploring various API’s in python along with notes. Azure notebooks is free to get started so if you have never played with Jupyter before I think its definitely worth checking out.

R1D14 For While Do Loops

Made it through Module 2 in the Introduction to C# course. Nothing too exciting going on. I was a bit surprised that they threw in a recursion example in between some trivial looping examples. It was kind of out of left field.

Conditionals

C# supports if and switch conditionals. It’s been years since I wrote a switch so that’s pretty exciting.

Loops

C# supports for, while, and do while loops. Do while is a good time.

I should be able to wrap up this course and move on to the next one by tomorrow.

Resources

Unsurprisingly, Microsoft has some really great docs for C#.

R1D13 Intro to C# and Getting Docker working with .NET Core and SQL Server for Linux

I signed up for the first of a three part course to learn more about C# on edX. I made it through module 1 already and was able to make it through writing a simple “hello world” style console app in C# with little trouble.

Hello World in C#

One of my favorite little bits of knowledge that I gained from the C# Intro course was the original name of C# was COOL.

The original name was COOL for C-like Object-Oriented Language

I also made a little bit more progress on my work from yesterday trying to get ASP.NET Core working with SQL Server with Docker on Visual Studio for Mac. I ran into a couple hangups.

First, docker was complaining that it was not able to find any of the shared NuGet packages. I had to add /usr/local/share/dotnet to docker folders in order to get nuget to work.

Sharing Folders in Docker for Mac

I also needed to bump up the resources to get past an error saying sqlservr: This program requires a machine with at least 3250 megabytes of memory. in order to get SQL Server to run. It needs more than 3GB of RAM in order to start up.

System Resources in Docker

 

R1D12 Dot Net

I dove head first into .NET Core again. I tried it out when it first came out a while ago but did not make it very far. After I got rid of my initial shock that .NET was properly running on Linux I lost a bit of motivation with the complexity and incomplete documentation. Things went a lot better this time.

  • I downloaded and used Visual Studio for Mac for the first time. Not sure how I feel about it to be honest. I am a huge fan of Visual Studio Code, still trying to figure out what added value Visual Studio proper brings to the table.
  • I ran SQL Server inside of Docker which still blows my mind. During my first tech job I really fell in love with SQL Server (despite the sticker shock). It was nice to be in a familiar environment again after all of these years.
  • I also tried out Visual Studio Team Services for the first time. It is a very feature rich development hub. It will probably take a few days to get through all of the various features but my first impressions have been good.

I am going to spend week 3 of my hundred days of code challenge diving deeper into .NET. Looking forward to seeing what comes out on the other side.

R1D11 There’s a Mongo in My Redis

I spent most of today banging my head against the wall trying to get some data out of a combination of Mongo and Redis using python. It paid off, because I got the data that I needed and in addition wrote a nice little script that spits out a tabular report using the wonderful and simple tabulate library in python.

Couple things to note:

  • When working with Mongo or any other dictionary like data structure (i.e JSON) you will get a lot further if you learn how to use list comprehension in python.
  • There is no real clean way to filter JSON from what I can tell in python. I need to figure out a better way to do this instead of checking if a key exists. I ran into a similar issue yesterday when trying to spit out a CSV from a JSON collection where some elements were missing.
  • Redis is fast, powerful, and kind of a beast. Learning how to get the data that you want is worth investigating. Some especially helpful commands that I learned were related to pattern matching on keys, and pfcount.

 

R1D10 Oops, Something Went Wrong.

I’m going to get back to React Native eventually, but tonight I spent some time working on a new Flask app that I started last week. I worked on trying to fix a few bugs with the Auth0 flow but spent most of my night digging through the logs and staring at this image.

Auth0 Error Screen

Login works like a charm. Logging out is a whole other story.

One interesting thing about this auth flow is that it enabled you to use wraps and make a decorator. This is a powerful functional programming concept in python that makes life a whole lot easier.

def requires_auth(f):
    @wraps(f)
    def decorated(*args, **kwargs):
        if 'JWT_PAYLOAD' not in session:
            return redirect('/login')
        return f(*args, **kwargs)

    return decorated

This concept is a “Higher Order Function” or a function that returns another function. If you are a JS developer you do this all day long. In this specific context this allows you to use the @requires_auth decorator on routes to ensure that a user is logged in before serving that route.

In other news, I also spent some time today learning more about actually using Redis. I think I’ve installed it and monitored it half a dozen times but I have never had the chance to actually do anything useful with it.

A great resource that I found was this article on how to go from zero to Redis master in 30 minutes. I also purchased Medis which is a beautiful MacOS GUI for Redis that is available in the app store for $5.

 

 

R1D9 Red Hat JBoss Ticket Monster

I took a step back from React Native today and went through the Ticket Monster tutorial from Red Hat. I wanted to get more familiar with some of the tooling that Java Web developers use since its becoming more important for my day job.

I was blown away at how awesome this tutorial is.

I’ve done a couple of these in the past. The world of Java EE is scary and overwhelming sometimes. Especially compared to the simplicity of something like Flask and the magic of something like Rails. This time instead of getting bogged down in all of the details, I just pretended like everything made sense for a while and took the tutorial at face value.

This proved to be a good strategy because some of this stuff actually makes sense.

Hot Takes

  • The Java word is full to the brim of acronyms. Just ignore them for a while and pretend like you know what they mean.
  • 99.999% of all tooling, tutorials, and “magic” in Java assumes you are using an IDE. Eclipse or IntelliJ are the frontrunners but there are others. Developing in Java EE makes so much more sense when you are doing so from an IDE because if you can get over the complexity of learning an IDE then it does all sorts of magical stuff to hides the complexity of Java. For example, among other things JBoss Developer Studio (based on Eclipse) allows you to;
    • Automatically set getters and setters for an object.
    • Reverse or Forward Engineer a DB to ORM.
    • Fill out XML files in a GUI.
    • Drag and Drop to create the GUI for your app.
  • Java is a language that developers either hate, or love to hate. But there is a reason why it has been at the top of lists like this for the last decade.

Ultimately, even if you are allergic to Java and have no interesting in learning about the tooling of that ecosystem I think this tutorial is worth checking out because by the end of your first hour you will have:

  1. A RESTful API along with a standard “CRUD” app that does something
  2. An understanding of how data is stored and retrieved from a database
  3. A real world example of grabbing data from a REST API in Javascript and displaying it on a UI.
  4. Deploy the whole thing to a cloud service (OpenShift) for free.

These are tough concepts for a lot of beginners and I think this sample tutorial application covers them all.

 

R1D8 Hello World from React Native

I made it to the middle of Chapter 4 in Mastering React Native. The sample project is a news reader app. Things are starting to get a bit complicated but I am using my typical “fake it till you make it” approach to learning.

I was completely blown away by the debugger tools that react native offers. You are able to debug an iOS application using Chrome Developer tools which is pretty amazing.

Nothing really to show for today. It will take a few more days to get through this book and have something to show for it. I am looking forward to applying what I learn to some real world project soon.

R1D7 Reading Mastering React

I didn’t get a lot of coding done today, but I continued to read through Mastering React Native.

In order to get into the React way of thinking, which is very different from traditional web application development, we went through a good exercise thinking about how to break apart a complex component (a news feed application) into its smallest reusable parts.

I also learned more about JavaScript XML (JSX) which is the main dialect that is used when developing React applications.

I continued thinking about what I wrote about yesterday in regards to using frameworks that solve problems that I don’t yet have. This theme continued in the book and Masiello did a great job priming the reader for it. During the introduction of JSX, Masiello notes

“So far, everything we’ve seen in this component could easily be created using only HTML. Rest assured, React provides several ways of making this component more interesting and useful.”

Excerpt From: “Mastering React Native.” iBooks.

You have to let you brain ignore the “so what” and “why do I need this question” in order to open it up for learning.

The whole idea of React reminds me of functional programming where you write very simple, small pieces of code, and then bring them all together to perform complex tasks.

“Composition has other uses besides making increasingly more complex components from smaller, simpler building blocks.”

Excerpt From: “Mastering React Native.” iBooks.