Monday, July 25, 2011

Technical Podcasts That'll Make You A Better Developer

I have a rather lengthy drive to work each day (~1 hour each way) while listening to the nonsensical ramblings of my local sports radio one day it hit me like a ton of bricks: why was I listening to this dribble when I could be spending this time making myself a better developer.  Thus began my search for some good technical podcasts to fill up my iPhone with.

I'm primarily a ColdFusion/Java developer and you'll see that none of these focus on either of those.  I'm a big believer that no matter what language you primarily use there are tons of things to learn from other languages.   I've used many things I've learned from listening to these in my day to day development.

While this list is far from complete its based on what I've discovered so far.  If you have a favorite podcast that you think I missed please comment and let me know.  I'm always looking for more good ones to listen to.

Software Engineering Radio (http://www.se-radio.net/)
I don't recommend listening to this one before you've had your coffee.  This podcast can be quite dry at times but it is packed with excellent technical information.  If you can get past the sometimes monotone delivery there is a lot to be learned from every episode.  The topics covered here cover an extremely wide range of topics, I'd highly suggest looking through all their back episodes for topics that may be interesting to you.

Herding Code (http://herdingcode.com/)
Herding code is a .NET focused podcast that contains mostly interviews with other developers.  The guests on Herding Code are usually top notch, and I frequently find myself going to the show notes on the website and researching a lot of the topics that come up.  The hosts are also extremely knowledgeable and usually ask their guests great thought provoking questions.  The topics discussed cover both open source and Microsoft specific topics which is a bonus in my book.

Pragmatic Podcast (http://pragprog.com/podcasts)
This podcast is another interview style podcast from the publishers of the Pragmatic Bookshelf books.  This podcast is a great change of pace from the strictly programming related podcasts I usually listen to.  Most of the time the interviews are for development specific topics, but I find the real gems are the ones that don't focus on development.  For instance, Andy Hunt's chat on Pragmatic Wetwear (http://pragprog.com/podcasts/show/13) or Chad Fowler's chat on "The Passionate Programmer (http://pragprog.com/podcasts/show/26) were some of the best overall podcasts I've listened to.

Polymorphic Podcast (http://polymorphicpodcast.com/)
The Polymorphic Podcast is another .NET focused podcast.  The host, Craig, does an excellent job of talking about things at an architectural level that will benefit developers from any language.  This podcast also does a good job at providing its listeners with enough high level programming best practices and techniques that its worth listening to even if you are not a .NET developer.

On Software (http://www.informit.com/podcasts/channel.aspx?c=dadf92ca-3bdc-484e-9cd8-cbfe0cfc0de6)
This is a short video podcast that covers a very wide variety of topics.   From JavaScript to Rails to Ubuntu this podcast covers it all.  The episodes are all on the shortish side ~10 minutes or so and since they are video podcasts I don't recommend listening to them on your commute, but they are great for watching while you are eating your lunch.

Pluralcast formarly Elegant Code (http://www.pluralsight-training.net/microsoft/pluralcast/default.aspx)
Admittedly I haven't listened to nearly as many episodes of this one as the others, however, the ones I've listened to have had excellent technical content.  Again, its another .NET podcast but David does an excellent job in breaking down the technical aspects of what he's talking about and seems very detail oriented which helps when explaining something in an audio format.

Railscasts (http://railscasts.com/)
This Ruby-On-Rails specific videocast may be unmatched in its technical content. Like the prior sentence implies, this is another video cast that is a great watch during your lunch hour.   Even if you never have any intention to write a line of Ruby you'll be hard pressed not to take some of the ideas Ryan presents and try to implement them in your day to day development.  Ryan also does an excellent job preparing for his shows and the delivery of the content is second to none on this list.

The Changelog Show (http://thechangelog.com/)
This is the latest podcast I've started to listen to.  Wynn Netherland and Adam Stacoviak host this weekly show that focuses on Open Source projects and culture.  Each week features an Open Source developer talking about their project and the open source landscape.  This podcast does have a pretty Ruby-ish feel to it as both of the hosts are Ruby developers and most of the interviewees (at least through the episodes I've listened to but I still have about 12 to go before I'm current) have a Ruby background.  Regardless I find this show informative and entertaining and I almost always find myself watching at least one project or developer on GitHub after the show.

News Based Podcasts
While learning new things is always one of the more important things a developer can do its also important to stay up on the current news and trends.  While the following podcasts don't give you the amount of technical information as the ones I mentioned above these focus on keeping you up to date on their platforms of focus.  While I downloaded every episode of the others the ones below I usually only download the latest shows so I can hear whats new and exciting.

The Java Possee (http://javaposse.com/) does a great job at keeping me up to date on what the Java community is doing (this podcast does also have a fair share of great technical information but It's just not on the level of the others). The JavaScript show (http://javascriptshow.com/) is a newer show which is brought to you by the same hosts as The Ruby Show (http://rubyshow.com/) and is formatted the exact same way where the hosts just go over a list of technology specific news and projects.  Both of these do a superb job in giving you the latest and greatest news as well as point out projects that are doing exciting things.  These shows are nice because they give you their content in a direct and concise format and leave it up to you to get further details.

For jQuery you can't go wrong with The Official jQuery Podcast (http://podcast.jquery.com/).  I also wish I could speak intelligently on the yayQuery Podcast (http://yayquery.com/) becuase it seems like it will be full of excellent information as well. I do have episodes 0 - 22 queued up in my play list bug I just haven't gotten around to listening to them yet.  Once I do I'll update this entry with more information.

While this list doesn't cover all of the podcasts I listen to regularly, it does cover the ones I tend to glean the most information from.  Like I mentioned earlier, if there are others you know of that you think deserve mention in this post please leave me a comment and I'll give them a listen, and I'll try to keep this post up to date as I discover more good podcasts.

Monday, July 18, 2011

Mocking Java Objects In ColdFusion Unit Tests

I've been working on a project lately that has a few CFC's that rely heavily on a java object for much of their functionality.  This was making my unit tests act more like functional tests since I was using the return values from the Java object to make my assertions.  This didn't feel very good to me so I went to StackOverflow for some help. Edward Smith (Edward if you are reading this and would like me to link to something other than your stack overflow profile send me a comment and I'll update it) knocked it out of the park with his answer.  I used what he said to implement the solution that this post is based off of.   He mentioned that his company had used the Java mocking framework Mockito to mock Java objects in their ColdFusion unit tests.  Brilliant!  I already use Mockito for all of my Java unit tests, I just had never put it together that I could actually use it in my ColdFusion unit tests as well.

The first step in implementing this approach is to download the mockito jar file from http://www.mockito.org.  For my implementation I'm using Mark Mandel's excellent JavaLoader project to create instances of java objects so I copy the jar into a lib folder in my application's root folder.  Another approach would be to add the .jar file right to my ColdFusion server's instance, however I don't have any experience with this approach so I stuck with what I knew.  This article on the Adobe blogs by Christian Cantrell might help you out if you'd rather use this approach.

Now that I have the .jar file in my project its time to make them available to my mxunit test. To do this I need to make them available to my test by loading them using JavaLoader and then to create an instance of the Mockto object so I can start mocking the Java objects.  Its important to note that when using the JavaLoader approach you must also inititalize the .jar file of the object you mocking and ALL of the dependencies.  Once the JavaLoader object is initialized with all of .jar files our objects need we need to create an instance of the mockito class for our test to use:


The next step is to create our mock Java objects.  Since the component I'm trying to test is more or less a ColdFusion implementation of the java object I decided to recreate the mock before every test so I knew I was working with a clean copy of the mock.  This means that I placed my mock code in my unit test's "setUp" method like so:


The syntax for creating a mock object in Mockito is pretty simple:  variables.mockito.mock(variables.classLoader.create("com.sudios714.cfevernote.CFEvernote").init("123","S1","232","sandbox.evernote.com","mock").getClass()); Here I am calling the "mock" method on my Mockito object.  The first parameter to the mock method is a Java class.  In order to get a class I'm  using the JavaLoader object's create method to create a new instance of a Java class and calling the getClass() method on that class to get the actual Java class to pass into Mockito.  The last step is to inject it into my component. Now we have a working mock object injected into my component lets take a look at a test that puts my mock to use:


There are a few important things to note here.  First is that the data that I'm creating for my mock is using a native Java object, in this case java.util.ArrayList.  Since this is a part of the core Java language I don't need to use the JavaLoader to create an object for this data type.   The next step is to do the actual mocking behavior.  The statement variables.mockito.when(mockCFEvernote.listNotebooks(12)).thenReturn(retArray); is telling Mockito WHEN the listNotebooks method is called with a parameter of 12 to RETURN retArray which is the java.util.ArrayList object we created above.

Mockito can also be used to verify behavior, however this comes with a large caveat.  Even if the verify statement is surrounded a try/catch statement (at least in my Win64/IIS7/CF9/Java 6 environment) if the verify statement fails, meaning that the method was not called with the expected parameter, the server will throw a 500 error.  If the behavior verifies OK the test will run as expected.  Knowing this if you'd still like to verify some behavior it can be accomplished by writing a verify statement like so: variables.mockito.verify(mockCFEvernote).listNotebooks(12); Here we are telling Mockito to verify that in the mockEvernote object the listNotebooks() method was called with a parameter of 12.

Monday, April 4, 2011

Writing better CFML Series - Part 1: Booleans

Boolean values are one of the most basic programming building blocks.  Basically boolean values they are switches that can hold only two values, true of false.   Just like a light switch can only be in two poisitions: "on" or "off".

In ColdFusion we are given a lot flexibility of what a boolean is.  ColdFusion will recognize the string values "yes or no", the boolean values of "true and false", and numeric values "0 and anything but 0" as booleans values.

To demonstrate I've written a simple function called outputBooleanValues as shown below:
<cfscript>
function outputBoolValues(boolean yesNoBoolean, boolean trueFalseBoolean, boolean numericBoolean){
 if(arguments.yesNoBoolean){
  writeoutput("Yes/No Boolean is <strong>true!</strong>" & "<br>");
 }
 else{
  writeoutput("Yes/No Boolean is <strong>false!</strong>" & "<br>");
 }
 
 if(arguments.trueFalseBoolean){
  writeoutput("True/False Boolean is <strong>true!</strong>" & "<br>");
 }
 else{
  writeoutput("True/False Boolean is <strong>false!</strong>" & "<br>");
 }
 
 if(arguments.numericBoolean){
  writeoutput("Numeric Boolean is <strong>false!</strong>" & "<br>");
 }
 else{
  writeoutput("Numeric Boolean is <strong>true!</strong>" & "<br>"); 
 }
 
}
</cfscript>

One thing I'd like to point out right away about this script is how booleans are handled.  One of the most common mistakes that new programmers follow is comparing a boolean variable to its boolean value.  Lets look at line 2 of the above script:

<cfscript>
 if(arguments.yesNoBoolean){...}
</cfscript>

A lot of new programmers would write that line as follows:

<cfscript>
 if(arguments.yesNoBoolean eq true){...}
</cfscript>

One of the nicest things about working with boolean values is that we don't have to compare them to their value when writing if/else statements.   Remember that when writing an if/else statement you are comparing an expression to its boolean value.  This means is that you can evaluate just the boolean variable.  Comparing it to its boolean value is redundant and not needed.

Now that we've gotten that out of the way, lets demonstrate how ColdFusion uses many different representations of true/false.   When I run the following code through the outputBoolValues function:

<cfscript>
 outputBoolValues("yes",true,584);
</cfscript>

I get the following output:








One thing that's important to note here is that the value "584" returns "true", in fact any number that  is not "0" returns true.  This can be really powerful when evaluating array's and in other numerical operations as I"ll show later.   Now lets switch the true values to false values and run the function again:

<cfscript>
 outputBoolValues("no",false,0);
</cfscript>

Now you can see that all my values are "false":






Now that we've got a good understanding of booleans we can start having fun with them and seeing how they can be used in our everyday coding.  One common way to use numerical booleans is to check if lists and array's have any elements or not.  Lets create an array with zero elements and check if has any elements:

<cfscript>
 myArray = [];
 
 if(arrayLen(myArray)){
  writeoutput("My array has elements :-)");
 }
 else{
  writeoutput("My array has NO elements :-(");
 }
</cfscript>
 

Running that script would produce "My array has NO elements :-(".  Now if we change the script to add an element to the array :

<cfscript>
 myArray = ["Red"];
 
 if(arrayLen(myArray)){
  writeoutput("My array has elements :-)");
 }
 else{
  writeoutput("My array has NO elements :-(");
 }
</cfscript>

We now get the output "My array has elements :-)".  The same type of logic can be applied to lists, queries, and mathematical operations.

What if we wanted to evaluate many boolean variables at once?  We can use AND statements to tie many boolean values together like so:

<cfscript>
 if(true AND true AND true AND true){
  writeoutput("Its all true");
 }
</cfscript>

If we change any of those values to "false" the statement "Its all true" would not print.  When evaluating more than one boolean variable using "AND" statements every item must evaluate to true for the entire expression to be true.  We can even combine the different ways of expressing booleans:

<cfscript>
 if(1 AND "yes" AND true){
  writeoutput("Its all true");
 }
</cfscript>

I hope this has helped you get a better understanding of booleans and how ColdFusion uses them.  Since this is my first post in what I hope will be many more I'd really appreciate your feedback.  Was this information too technical, not technical enough?  Was it presented in a logical way?  Was there anything I could have done different to more clearly present the concepts?

Thursday, March 17, 2011

Is your ego getting in the way of your career?

If you saw the title of this post and thought to yourself  "Of course its not, how could being the smartest guy in the office hold me back." your ego might be getting in the way of your career.   If you are a great teacher but not a great listener your ego may be getting in the way of your career.   If you don't wake up every day thinking that you could fill Texas Stadium with what you don't know your ego may be getting in the way of your career.  As programmers we are typically very smart people, we solve complicated and abstract problems and others tend to marvel at our skills.  We all know that look of amazement on somebody's face when we tell them that we are a programmer.  So who could blame us for being a little "self confident".  

The key to a successful career as a software developer is to not let that ego get in our way.  I feel that there are two types of programmer egomaniacs: the "Kobe Bryant" and the "Kwame Brown".  I'm sure that most of you who read this will know who Kobe Bryant.  However, Kwame Brown is a name that most of you probably won't know.  That's because he is one of the biggest busts in NBA history.  A former number 1 draft pick who never realized his full potential and now has a hard time staying on an NBA team.

Lets start by talking about the Kwame Brown.  I was a Kwame Brown so this part will be highly introspective.  Kwame Brown was a number one overall draft pick in the NBA right out of high school.  In high school he was a big fish in a little pond.  He was talented but not as talented as he thought he was.  Since he had a relative amount of success in high school never put in the work that took to succeed at the next level.  

ColdFusion seems to breed more of these types of developers than other languages.  That is likely because its so easy to achieve a relative amount of success with ColdFusion.  The Kwame Brown doesn't like frameworks because they think then can roll their own, the Kwame Brown writes mostly in components and feels like they know all there is to know about object oriented programming.  This person picks up a technical book, reads the first two chapters and thinks to themselves, "I already know this stuff" and puts the book down. 

Its hard to say exactly what snapped me out of my rut.  I think it started when I had to open up my code to a outside consultant.  Something finally clicked inside me where I asked myself, "Is this something I'd be proud to show somebody else?"  I was somewhat confident in my approach (of course I was, I was a Kwame Brown) however this consultant started asking me things like, why aren't you using coldspring?  Why didn't you just use ColdBox or Model Glue?  Finally I decided to open up to and learn about these things he was talking about.  And the more new things I learned the more I realized that I didn't know.  IoC, unit testing, MVC, refactoring, design patterns, I was in trouble! 

The developer I am today is a completely different person than that one from two years ago.  Today I wake up each day thinking about how much I don't know and how much fun it will be to learn something new.  I actively explore different programming languages, and I read, a lot.  I read books cover to cover now.  I approach early chapters as an opportunity to learn something new about something that I may or may not I feel that I already know.   I try to blog about what I learn, nothing tells you if you understand something or not like sharing it with others.   I love looking at others code now, I pull a lot of open source projects from github and try to understand the code behind these.  I went so far as to enroll back in school to pursue a Computer Science degree to make sure that I had all the fundamentals I needed to become the best programmer I could.  One of the unexpected side effects of this is that I have a renewed passion for my job.  Each and every day I look forward to coming into work and challenging myself.  I have bad days for sure, but the number of good days I have now far outnumber the bad ones. 

This brings us to the "Kobe Bryant" type of ego maniac.  This person is the "superstar" programmer, a natural talent.  This person reads a book on regular expressions and is churning out complex pattern matches the next day.  They are usually the smartest person in a room full of smart people,  and they want you to know it.  This type of person rarely laughs at others jokes but will heartily laugh at a bug they discover in someone else's code and not hesitate to tell that person about it but rarely offer to sit down with that person and help them learn how to fix it. They hate sharing their knowledge because they get easily frustrated explaining things to others who don't "get it".  This type of developer also hates listening to others suggestions.  When a Kobe Bryant has use a module written by another developer the first thing they do is rewrite the code. 

I've worked with many of them before and I've rarely seen them become anything more than executors.   This is because that the people higher up the food chain can see how others react to these types of developers. Their team members will rarely go out of their way to sing this person's praises knowing that it will only feed their ego.  Instead their peers will watch them closely for any mistake and make sure they point it out to them and everybody else on the team.  Typically the Kobe Bryant developer is so self assured that they either don't see how others react to them or are so confident that their superior knowledge will surely allow them to rise to the top regardless if others like them or not.  Also the people doing the promoting know that they'll have to work more closely with this person and will balk at the notion of having increased interaction with this type of egomaniac.

So what can you do if you have some "Kobe Bryant" in you?  First learn to listen to others and sincerely try to value others input.  Here your reputation can work to your advantage.  If you are known as being a know it all telling someone else "that's a really good idea, thanks for sharing" can go farther than if it was said by someone who is constantly throwing around compliments.  Also actively seek out others opinions.  Even if you have no intention of listening to what they have to say just ask someone, "would you mind looking this code over for me" will make others feel that you value their opinion.   Lastly know that its OK to laugh at a stupid joke, nobody will question your intelligence if you laugh at the latest "Two guys walk into a bar" joke.

 If you suffer from either of these conditions its not too hard to turn things around and become a "Tim Duncan".  Tim Duncan is liked by others, is always working hard on his game, and is a true leader on a championship team.  That's the kind of developer I want to be, however I know that I have to work hard each and every day to achieve it and not fall back into my Kwame Brown ways.

Saturday, March 12, 2011

Writing better CFML Series - An Introduction

Personally I feel that a lot of the negative comments pointed towards ColdFusion are due to the fact that its so easy to learn, and like any language, tough to master.  I think a lot of people pick it up, write a site that works, and consider themselves "programmers".  While this in itself  isn't a bad thing because the ColdFusion community needs as many developers as it can get.   I think that this leads to  a lot of poorly written CFML out there and that that it tends to give ColdFusion a bad reputation.  Instead of getting into a flame war with everybody out there bashing ColdFusion I decided to do what I could about it and write a series of blog posts that are aimed at helping entry to mid-level developers write better CFML.

One of the problems with a lot of the resources out there is that they are either too high level or to advanced.  I think there is a large void in best-practices or mid-level tutorials and articles.  Everybody wants to write about complex or advanced topics that will wow the community and have others lauding over their knowledge (who wouldn't).  

In addition to writing about the many things I have planned my goal is to put out at least two posts a month covering topics like:
  • Object composition: writing useful, well constructed objects and minimizing an objects API
  •  Writing maintainable code by looking at an object's functions and properties and a quick look into refactoring to make messy code more readable
  • A deeper dive into MVC and what "separation of concerns" really means also some guidelines to where objects should live in the MVC pattern.
  • Loosely coupling objects and why its a good thing  along with a brief overview of dependency injection.
  • What in the world are interfaces and why you should implement them and use them for a functions return type and parameter types?
  • Some best practices when writing ColdFusion
If anybody else has any suggestions for things they frequently see in poorly written CFML please let me know, I'd love for more ideas on things to write about.
Fork me on GitHub