My Deliberate Practice Plan to Become a Better Programmer

In the previous post, I reviewed the book So Good They Can't Ignore You. I wanted to take the ideas and advice from there and to create my own plan for deliberate practice as a software developer. Here's what I came up with...

Continuous learning

Being a software developer means to always be learning. Whether it's a new framework, new programming language, or a whole new programming paradigm learning something new is integral.

There are several ways to do this and I will try to incorporate all of them, though more will take more presidence and attentnion than others.

  • Use sites like Pluralsight and Udemy for on-demand tutorials and training.
    • Watch at least one course each one or two weeks, depending on the length of the course.
  • Watch at least one software presentation on YouTube or similar site.
    • Watch one at least each week. This should generate some "Top 10" posts for everyone to enjoy or, if it's really good enough, a post about a specific presentation.
  • Read at least one technical book each quarter.
  • Read and try to understand at least one journal paper on programming each quarter.

Practicing

Of course, one of the biggest and best things to do as a developer is to actually program something...anything to help put into practice what I've learned. The above methods are great for learning new things, but they have to be put to use, as well, otherwise I won't be able to retain what I've learned.

  • Have at least one personal project going at a time.
  • Blog about things learned and always have a demo project for it, if possible.
  • Get certified, if available.

Being uncomfortable

Doing deliberate practice often means being uncomfortable during the practice. This is an easy way to know if the practice is good or not. Here a couple of ways I can step outside of my comfort zone.

  • Speak at a local user group at least once each quarter.
  • Try to speak at a conference at least once this year.
  • Do more screencasts instead of regular text posts for the blog.

Keeping track

Now, none of the above doesn't mean all that much if I don't keep track and accoutable for each of these. Saying I'm going to do it doesn't mean I am going to do it.

  • Once again, blogging about each of the above items as much as possible
  • Use a time tracker such as Plan to keep a digital record and for some nice reports.

Since it's very close to the 2017 year, this is a great time to get started with this.

Do you have something you've done work very well for you but wasn't mentioned? What are your plans for having deliberate practice?

Consuming the Jamendo API with AngularJS: Services

It took a little while to get back to this little project. After watching some nice stuff from NgConf the other week, it helped get me excited again for AngularJs. Plus, I was stuck on a problem for quite a while that I'll explain in more detail below that really slowed me down. After a bit of a break I got back to it and was able to figure it out.

Services

Before we looked at how to use the $http get method from AngularJS, but all of that was within the Angular controller itself. To separate things out and to help us test easier I moved the $http calls into an Angular service.

To recap, let's take a look at our controller currently:

As mentioned earlier, we have our $http call right inside of our controller. While that definitely works, it's better to separate that out into it's own service. Let's refactor this down a bit...

Now this looks a bit cleaner. We're first passing in the albumsService as a dependency into the controller. Of course, if Angular can't find that the albumsService is defined, it'll throw an error.

Next, we have the function definition of our getAlbums method. In here we extract out the artist from the scope and then call the getAlbums method on our service. In our call to the service we give it a function as a callback if the $http get was a success that we'll see later when we look at our service. This basically just gets the results and puts them into the scope.

Now let's take a look at our service.

Pretty straight forward as it's basically the same as what we had in our controller earlier. We inject in the $http Angular object and we create our getAlbums method while prepending it with this

When we call our success promise from the get method, I just pass in the callback method that we defined in our controller earlier. This makes it a bit easier on our service since the callback method was updating our $scope object and we don't have to worry about that here in our service.

I mentioned earlier that I had a bit of an issue that kept me from finishing this up. I kept getting an $inject error on my service that indicated that it wasn't defined, but I couldn't figure out why that was. After some fiddling around with it, it turns out that I was trying to inject the $scope object into the service and Angular doesn't like that. That's also a reason to use the callback.

Conclusion

Moving the $http get call to an Angular service is mostly just a small refactoring, but it's a good one to do. We will see later when we start to do testing how much easier it is to have that separated out.

Of course, this was just an introduction to Angular services so there's tons more to learn about them. I'll recommend Dan Wahlin's AngularJS in 60ish Minutes to anyone. In fact, I've referenced it a few times to remind myself about services. There's also the WintellectNow video from Jeremy Likness on AngularJS Services that goes into much greater detail of services.

You can play with the demo and, as always, you can play around with the code itself.

Beginning Ruby for C# Developers

Ruby has become quite popular as a programming language over the past few years. Probably mainly due to the popularity of the Ruby on Rails framework. Because of its popularity, it makes sense to learn at least the basics of it and what all it can do for you as a developer.

Until I have a better solution for embedding Ruby code and output, I'm just embedding the code and results as Github Markdown for now. Even though it doesn't seem to display properly in the embed, it does when viewing the actual gist on GitHub.

Getting Started

One of the easiest ways to get started using Ruby is to just use your browser. Repl.it is a site that supports many dynamic languages to be run in a browser and it's very handy to just play around in.

I've also seen people use Sublime Text to edit their Ruby code (I admit, I enjoy using it as well as a light weight IDE. I've had no problems using the beta of version 3, either). For Windows, you'd just need to install Ruby. If you're on a Mac, you already have it installed. In fact, you can just type "ruby -v" in the terminal to see what version you have.

Since Ruby is a dynamic language, there is no compiling. However, everything in Ruby is considered an object, and because of that everything will include some built in functions with it. With everything in Ruby being an object isn't necessarily a new concept to C# developers since every object in C# derives from System.Object and you do get a few predefined functions, Ruby just seems to have gone that extra step. 

For example, say you want to run a statement three times in a row. How would you do that in Ruby? It's actually easier than just using a for-loop similar to what you would do in C# or even creating a way to use a lambda expression.

Pretty easy and very straight forward, especially for someone who may not even have a programming background.

Let's go on with a few other basics...

Output

Ruby has a couple of ways to display output back to the console. The main way is to use the "print" statement, though you may also see the "puts" (put string) command as well. The only difference in these is the "puts" command will append a new line. You'll probably see these statements quite a bit, especially if you go through online tutorials.

Methods

As mentioned earlier everything in Ruby is an object, and since that's true it can have methods on those objects. Of course, depending on the type Ruby recognizes it during runtime is what methods are available. For example, the "length" method can be used on strings but not on numbers.

Methods, like in C#, can also be chained together to give some added syntactic sugar and to reduce the overall code needed to accomplish what you need.

One final note about methods that got me confused early on but I thought was really nice is that there is a bit of a naming convention associated with certain methods. Mainly methods that change the object itself and methods that return a boolean.

Take the "upcase" method we used earlier. There are actually two versions of this method, "upcase" and "upcase!". The first returns a copy of the string being used, the second (indicated with an exclamation point) changes the instance of the string being used. In other words, the first version causes the string to be immutable.

For methods that return a boolean value a question mark is appended to the end of the method name to indicate to the developer that that method can be used for branching. Take the string's "empty?" method, for example. As you can probably tell, it returns if the string is empty or not.

Program Flow

Like most programming languages Ruby supports the if/else block. However, one noticeable difference is that Ruby also has an "unless"' keyword. It will only execute if the given conditional is false. This was included to help make certain branching more readable and a bit more intuitive.

So we can change the structure of an if/else to an unless block like so...

Further Learning

One of the best resources I can recommend to help get you on the path of learning Ruby much easier is Code Wars. This site has quite a few code katas that will help in understanding the syntax and included methods that come in with Ruby.

Codecademy is recommended a lot, as well, by people and for very good reason...they have a lot of good interactive tutorials for learning Ruby.

Conclusion

Of course, I definitely don't know everything about the language or all the tools the community uses. I still haven't gotten my head totally around gem files or rake. I'm not even totally sure of the correct structure of a Ruby application! But, hopefully this will at least spark some interest in you C# people to maybe try something different outside of the .NET world. There is plenty of fun to be had with it and I throughly enjoy learning the language and all it has to offer.

Core C#: Delegates

Microsoft has made it easier for aspiring developers to easily get started creating something when they came out with the C# language. However, there are definitely some advanced aspects of the language that take quite a bit longer than others to fully grasp. Delegates is one of those types of language features. Hopefully by the end of this article you'll have a deeper understanding of how utilize delegates in your C# code. 

I, myself, had trouble trying to fully understand what the purpose of delegates were. If you were to ask me before what a delegate was, I would just give a small answer indicating that it's similar to a method template. While that's true, it does quite a bit more.

The simplest way I know to go over delegates is to just go through a small example to allow you to also do the same so you can use that to experiment around with the code.

Let's go through this a bit. The first line is where you actually declare the delegate and give it a return type, name, and any parameters if it needs any. In our Main method is where we'll initiate a couple of variables to hold the delegates. The first one, myDelegate , does so using the method syntax. Our second variable, however, we declare it using an anonymous delegate, or a delegate without a function name.

After we've declared the our variables with our delegate, we can then invoke our delegate by calling it just like a method just like in lines 15 and 16 above. We declared our delegate to take in a single string parameter, so that's how we'll invoke it. 

Built in Delegate Types 

The folks at Microsoft were kind enough to give us a few built in delegates that we can also use within our code. Let's take a quick look at them. 

The first one, which may be the most commonly used, especially if you've messed quite a bit with the LINQ method syntax, is the Func  delegate type. This one will take in zero or more parameters and will return something back to the caller. In the example above I have one parameter of a string and I return back an integer.

The second one is the Action delegate type. Like the Func type it takes in zero or more parameters, however it returns void (returns nothing).

The third one, Predicate, is a bit closer to the Func type where it takes in parameters and returns. The difference with this is that it will always return a boolean true or false back to the caller.

Invocation Lists

One of the magic things that delegates have is they keep track of all invocations of it. When we instantiate our delegates we are actually adding to the invocation list. Another way to do this is to simply add a delegate to another delegate. 

We'll see the true power of delegates and their invocation lists in the next part, when we talk about events.

Code Katas Can Be Helpful

After reading a few posts in the development community lately about code katas, I felt I should put out my own opinion about the subject. 

At work, a few of us developers decided to take a couple of lunches each week and get together to work on a code kata that we all decide on prior to the meetings. This was mainly so we can increase our skills in development, but mainly it was a way for us to use a new or not so familiar language for a fairly small coding project.

For our first shot at a kata we decided to try Poker Hands (you're always welcome to view my progress), which we had to rank two player's poker hand and determine who won and display how they won (high card or higher set of cards). Not exactly the easiest kata to do, especially when doing it in a language you're definitely not familiar with, but we thought it was one that could give us a good challenge.

Another aspect to doing katas is to do solve very small problems. One of my favorite ways to do this lately is by playing around at Code Wars. I've been messing with the JavaScript and Ruby katas there and have been learning quite a lot about the languages as each new kata I do gets progressively harder. They have a pretty slick interface, as well.

I feel this site does a lot of things right. Most importantly, once you've successfully finished a kata it will also display how others have successfully implemented it. Looking though those can help see how other people use the language to their advantage.

Sure, you can also be doing other things in order to learn, such as messing around GitHub for a project to contribute to or volunteering. However, a big benefit to doing these small katas is because they are small compared to these other types of projects. You won't feel as overwhelmed by the size of the project or try to figure out where to start. Here you just create the appropriate class or function and make sure all the tests pass. 

Of course, you want to do code katas because you believe they help and because you find them enjoyable. I feel like I'm learning new languages little by little the more I do these. I seem to have rekindled my love of programming just by doing these katas. I hope I'm not the only one.

You Are Good Enough

"I don't think I'm a good developer." 

I think a lot of developers out there think this or something similar at one point in their career. Mainly during the first few years when they started out. Maybe they just started their first job or even thinking of moving to a second job.

Here's my advice if you're one of those who think this...just relax.

Yes, I definitely have done this myself. All through college, when interviewing for my first job, during my first job, interviewing for my second, and during the first couple of months of my second. Seems like a lot of times worrying and doubting yourself, doesn't it? 

It's kind of nice that you worry about this stuff. It means you actually care, right? But just think, if you weren't as good as you may think, how would you have gotten the job you do now? How would you have been able to stay there for as long as you have? 

If you still feel the same about your skill, take this opportunity to learn new stuff. The internet has tons of stuff online to get you started. One tutorial doesn't make sense? Go to the next one.

So go on, challenge yourself. After doing that you'll become better than good enough.