Coding Reflection – Reading and Testing

Reading Reading books about the technologies that you are using is really important. It gives you something that just looking at existing code doesn’t. Over time a code base tends to...

Reading

Technology booksReading books about the technologies that you are using is really important. It gives you something that just looking at existing code doesn’t. Over time a code base tends to train developers into doing things “it’s way” and it takes an external influence to help pull the team into better ways of doing things. My Kindle has been an amazing resource, as I can have all of my technical books with me whenever I am on the train or find myself waiting in line. Then, when I’m working at my computer, I can use the Kindle app to pull up relevant sections that I remember. Searching for something that you know exists in a good technical book can be 50 times faster than looking for it on Google.

One important optimization to this is to spend time reading books about the things that you are doing. And not just “oh, I’m writing rails code, so I should read a Ruby on Rails book”. That’s a great place to start, but if you have a specific thing you will be  working on the next day, read that book. So if I was going to spend my next day writing and fixing tests, I read an RSpec book. If the stuff that I’m working on is mainly plain Ruby code, I read a Ruby book. Playing with Routes tomorrow? read the Routes section of a Rails book.

Testing

Unit testing is unit testing, not integration testing. Don’t confuse them. Tightly coupled unit tests where you create factories for 6 objects and rely on pulling in RSS or JSON from an external service make life hell for everyone. Yes, it’s more work and it seems silly to mock everything out when you’re doing it, but being militant is the only way to keep things clean. It also makes the specs a lot faster, something that makes up for the extra time you spend building a mock object instead of just using FactoryGirl.

The other benefit is that if your proper unit tests are hard to write then that’s a pretty clear code smell. Rewriting the code to make the testing easier can lead to much cleaner, less coupled code. When you have to pay attention to everything that your code interacts with (by mocking out each interaction), you become a lot more sensitive to how much it relies on that other stuff that it really shouldn’t be relying on.

 

 

 

Reflection Reboot

In my last coding reflection post I spoke about how awesome the reflection process was and how much it was becoming a habit. Seeing as that was over 2 months ago…...

In my last coding reflection post I spoke about how awesome the reflection process was and how much it was becoming a habit. Seeing as that was over 2 months ago… I guess I spoke too soon.

I did do my reflections for a week or so after that, but didn’t post them. The reasons for stopping were two-fold:

1) I was running out of “easy” reflections and had to dig deeper to get there.

2) I started Taekwondo. While Taekwondo is awesome (I’m happier and fitter than I have been in a long time) it means that instead of coding till I can’t anymore, then reflecting for a bit and going home, I now work up until practice starts (my Dojang is a block away from Red Rover HQ making it easy to work until the last possible minute). Practice then clears my head of the code (which is great… it stops the nightmares) but it also clears my head of reflective thoughts on that code.

So noting that in the time that I was reflecting my skill level went through the roof, I need to change the system so that reflection once again becomes easy.

The plan is:
ReBoot Discs

1) Instead of reflecting at the end of the day, I will do it at 5pm every day.

2) Instead of making the expectation: “think of all the things you have learnt today” I’m going to reduce the load to: “think of one thing you’ve learnt” and “create shortcut that you could have taken” (taking a cue from Yan).

3) Posts aren’t going to be numbered anymore, but themed. That way I can make each one more self-contained and coherent, while again reducing the pressure to put in too much.

4) I’m going to keep a page of “rules” that I can edit and update as I learn things, to make it easier to quickly review and scan my most importnat learning in the morning.

Coding Reflections – Week 3

Week 3 of attempting to speed up my learning process through reflection. On the reflection process: After 15 days of practice, this is really starting to feel like a habit. I’m...

Week 3 of attempting to speed up my learning process through reflection.

On the reflection process:

After 15 days of practice, this is really starting to feel like a habit. I’m starting to see the circles get smaller (the Art of Learning is a great book) in my work and when previously I could only think about things in their macro forms, I am discovering even more subtleties.

One way that I am starting  to make the circles smaller in the reflection process is by forming the habit of reflecting immediately when something happens. I think it has to do with what this article suggests, that  the habit of reflecting on mistakes as they happen can greatly increase the speed at which one learns. So instead of spending a long time at the end of the day thinking back on what I did, I am instead reflecting at the point of the mistake (which for me usually means taking too long to find a bug) and trying to find ways to avoid it in the future.

 

Programming:

Sometimes doing the smallest thing doesn’t mean starting small. Instead of building up to something big piece by piece, it can often be more effective to take a large block of code that currently works (from somewhere else in the code base or the internet) and whittling that down to only the essentials. There is skill required in making sure you got rid of all the non-essentials, but if you’re diligent, it can be really successful.

 
concentrate on differences. When faced with a complex system that works and a simpler one that doesn’t, you can either increase the complexity of the broken system until it works, or decrease the complexity of the working one in order to see what parts are truly necessary for what you need done. An example is that this week I had a component that when given a hash with 10 entries would work, but that wouldn’t work when I fed it my own hash with 3 entries. I then methodically added things to my hash until it was exactly the same as the complex one and the function still didn’t accept it. Finally I went the other way and stripped the 10 item hash down to 3.. and the function still accepted that hash. Now with much less complexity I could look deeper and see that the difference wasn’t in the entries, but in the hash type (the one that worked was a “HashWithIndifferentAccess” instead of a normal Hash)

 

Look for more than one example. When you are working with a large code base and have to do something that is done somewhere else in the application, look hard for other places where things are used. Remember to check more than one place instead of assuming that the code is DRY and it’s all done the same way throughout the application. If you do find that there is more than one way to do something, be sure to use the best way possible and then go back and update the bad example.

Kitteh used Scratch!!  Its super effective

 

Write things down. The tactic of writing out all the possible causes has been proving really effective. Like super effective! I’m constantly amazed at how well it helps me spot the areas where I should be focusing on. Tracing out the actual flow of a piece of code across functions and source files is way better out in the open than in your head, your mind makes false leaps and assumptions that the cold hard light of a whiteboard marker uncovers easily.

 

Code in flow state more often. I’ve spent a lot of time building my trigger… now I just need use it more often.

 

 

 

 

Coding Reflections – Part 2

Continuing with my attempt to increase the speed at which I master the craft of programming, here is my second week of reflection. One part of the reflection process that I...

Continuing with my attempt to increase the speed at which I master the craft of programming, here is my second week of reflection.

One part of the reflection process that I noted was that reminding yourself of the previous reflections is crucial. Toward the end of the week I found that rereading me reflections from earlier really helped me to not repeat those previous mistakes.

Week 2:

Always make the minimal amount of changes to go from working to not working. Yes, I know i started with this one last week, but it bears repeating. This week I did a lot of building new things and again found myself being slowed down by making too many changes and then having to figure out which one of those changes didn’t work as they were supposed to. Starting with the simplest thing takes discipline. I’m not sure why that is, but our brains seem to want to see big effects and use those to trip us up. In order to practice the simplest thing we need to be continually vigilant.

Pay careful attention to any error trace. Often the answer is buried deeply and even though after making changes it may look like the trace is the same as before, there could be changes in where the error came from a few lines down from the top of the trace.

Write bad code. One problem that I’ve been having (probably magnified by the fact that I’m working  in Ruby on Rails) is that everything I read really concentrates on writing and architecting really good code. The problem with that is that it is really hard to know what the best code is as you go along. As you code you get paralyzed by the different design choices. You then spend hours trying to make what you think may be good design work, only to throw it away because the direction of the code means that another design pattern actually makes more sense. Instead, if you write crappy code that just gets the feature complete as quickly as possible, you end up with a complete feature and time left over to refactor (of course this only works if you’ve written tests to ensure that everything stays working after the refactoring is finished). I think it’s a lot easier to see where to fix bad code than it is to ponder over what the best code is to write. Of course, a big part of this strategy is the commitment to go back and actually do the refactoring. Code review helps a lot as sheer embarrassment can be a great motivator for going back and making sure your code looks good!

Danbo conoce a Domo - Danbo meets Domo

 Follow the Law of Demeter. There are many complex aspects to this law, but the heuristic that I’ve been using is thinking about it as “don’t take your toys apart”. If your context has a class, then you can call any of it’s methods or attributes, but you cannot “break the toy apart” and call methods of that toy’s attributes. This article does a good job of explaining why breaking the Law would seem silly in a real world context. When you buy something, when the cashier asks you to pay, they don’t “break you apart” by grabbing your wallet (your attribute) and taking the money straight out. Instead, they ask you for the money and you give it to them. They don’t even have to know about your wallet, maybe you don’t have one and just shove your money into your pockets, that would make a waiter trained to take money from wallets very confused and would be a very awkward end to the evening. Throughout the week I found that code following the law was super easy to debug and refactor, code that didn’t wasn’t, with fun little errors popping up like “you called x on nil”.

 

Coding Reflections – Week 1

Working full time as a developer again, I’m trying to apply my years of thinking about learning to my programming. Learning in school is one thing, it’s supposed to be the...

Working full time as a developer again, I’m trying to apply my years of thinking about learning to my programming. Learning in school is one thing, it’s supposed to be the point of school after all. Learning at school became even easier for me once I reached the all important “learning matters far more than grades” conclusion. Learning while working full time is very different though. You have to explicitly decide to learn, to take extra steps to learn, otherwise learning stagnates and you find yourself stuck at the same skill level for years. I’m determined to not let that happen, so will be making every effort to keep up the pace of my learning.

Of course, there are many ways to practice “continuous learning”, but the one that I’m going to be attempting is just reflection. Sure, learning “the hard way” and other techniques may be more effective in the short run, but using them while at the same time producing as much good work as possible is hard. Using reflection as a tool for learning has the benefit of not taking time away from other important tasks and is arguably a more sustainable learning habit to create.

So the learning plan is as follows:

Every day after work, I reflect on what happened. Where did I make mistakes, where was I brilliant? what did I learn?

At the end of every week I can review the learning and summarize it. I will try and post these summaries here every week. Some of it will be new learning, some of it will be things I’ve forgotten some will be things I didn’t do because of lack of sleep and some will be pure guesses as to what will help make things better. I will break things into sections, general programming  and language specific learning.

Week 1

General Programming:

Much of this week was spent refactoring old code, in order to make a new set of features easier to implement. The process took me much longer than it should have. Here are some ways that I think can make the process of refactoring less painful.

Always make the minimal amount of changes to go from working to not working. My method was to first change the main attributes to be named correctly, then to watch for where things broke when they called for those attributes. Terrible idea.

The last thing that one should do is rename badly named variables and attributes. The first thing to do should be to DRY up the code as much as possible, only after everything is working and the code is as elegant as possible, should you worry about renaming old bad names. a “rename_column” migration is a hell of a lot cheaper than hunting through bad code for all references to a badly named variable/attribute.

On the subject of renaming attributes never use “find and replace all”. Check each instance of something that gets replaced. If there are too many of them, then it means that you haven’t done the DRY work that you should have first. If you do use “find and replace all” then every bug that you encounter for the next hour should have you thinking… “could this have been because of that find and replace all that I shouldn’t have done?”

Basic debugging:

Resist the temptation to just mindlessly trace variables when there is a problem. After the first or second tweak to try and make things work, stop and take a breath. Start enumerating the things that could be wrong. Don’t trust your brain to hold all of these elements, write the various causes for the error down (yesterday I stuck a large strip of dry-erase roll on my des to help with this). Doing it without looking at the code too much helps as well, it gets you thinking more abstractly and actually allows you to put those years of listening to Computer Science lectures to use. Think of all the different ways that you can actually test to see which one of these causes it is. Once you have a list, rank them by probability and work from there. As Steve Wolfman told me on my very first CS lecture at UBC, “Computer Science is the science of clear thought”. Writing things down is the easiest way to make your thoughts clear.

 Ruby on Rails:

use validates_presence_of to ensure that variables that you need are there. Make sure you actually need those variables.

The before_validation callback can be really useful to consolidate and double-check that everything your model needs is there.

Spend every effort as a team to make the specs fast. Every extra second that a test takes, gets multiplied by the number of developers running tests by the number of times it’s run over it’s lifetime. Those extra seconds can easily add up to hours on a big complex project. Slow specs lead to less testing which leads to broken code.

Single table inheritance in Rails is easy. It can be done simply by making a class a subclass or another ActiveRecord::Base class. The caveat is that that superclass’s table needs to have the “type” attribute, in which Rails will automatically store the type of the subclasses.

When converting a non-ActiveRecord model to an ActiveRecord model pay careful attention to methods that may be overriding ActiveRecord methods. Deal with those first.

Rails AntiPatterns is a really good book. I’ve been trying to force myself to read and watch as much as possible on programming in Rails and this book has been by far the most engaging!

New York

New York Panorama

Guest post: Making web education better

Ironically, as I prepare to teach my first “for profit” online course on Matygo I was sent this guest post by Marina Salsburg with some very legitimate concerns on for profit...

Ironically, as I prepare to teach my first “for profit” online course on Matygo I was sent this guest post by Marina Salsburg with some very legitimate concerns on for profit education. I think that Matygo is one of the few companies that is offering education online with the right intent, disrupting the very notion of accreditation.

Take it away, Marina:

Online education is often touted for its convenience and flexibility. Students dream of being able to work on their own timetables under their own direction, and web-based education can make that possible. However, as with everything, there are both good and bad online learning options. Online education is the wave of the future, and as it continues to grow, educators must find ways to make it better.

One common concern is quality. In some cases online classes for college are taught by the same faculty who teach the conventional campus-based versions of the same courses, and are of equal caliber. However, it’s often true that web-based classes, especially in a fully online university, are not taught by full-time teachers. Part-time instructors often work for relatively low pay, without benefits, and sometimes don’t even have their own offices. As a result, it may be difficult to employ quality instructors in such positions, and those who do take the jobs may have to teach an inordinate number of classes simply to survive.
Traditional colleges and universities can address this by actively encouraging full-time faculty to take on online classes as part of their teaching loads, perhaps by offering increased pay or other incentives. Another solution would be to incorporate online components to existing classes, so that students taking an online class simply view lectures and submit assignments remotely, but along with the classroom-based students.

The huge number of for-profit online schools are also a common concern. These schools rely heavily on mass marketing to entice students to enroll, but the quality, adequate academic support, or even fundamental goal of actually providing sound education may simply not be there. Many of these schools are essentially diploma mills, taking tuition from students, providing perfunctory education, and awarding degrees that may or may not be of any real value. Even well-established and relatively well-respected online schools like the University of Phoenix have been accused of predatory recruitment, regardless of quality of education. Kaplan University, for instance, made almost 90% of its 2009 revenue from collecting taxpayer-backed financial aid.

One particular problem has been the targeting of military veterans by the recruiters at such schools, motivated by the lucrative financial aid benefits the veterans bring with them. Donald Overton, Jr., executive director of Veterans of Modern Warfare, claims “These schools are after the monetary gain of a healthy benefits package, not necessarily what’s in the best interest of students.” As it stands, existing online schools that really have this mindset have no incentive to change. One way to correct that would be to have greater regulation of federal education aid funds, particularly those earmarked for veterans, and greater accountability on the part of the schools themselves. Indeed some legislators are calling for just that.

There are, however, positives to web-based for-profit schools. In some cases, they’re on the cutting edge because they’re not limited by topheavy administration, as are many brick-and-mortar schools. As such, they’re better able to be forward-thinking, designing classes and degree programs that more effectively meet the needs of students, as well as providing flexibility in scheduling that many traditional colleges can’t accommodate. Some, like University of the People, aim at the even higher ideal of providing college education freely online. Modern educators who truly wish to provide superior education should see the advantages technology provides, and embrace them by creating new online programs that benefit students, and can compete with schools that may not actually have education as a fundamental ideal.

As technology continues to develop, new options are becoming available in education. Students are no longer content to settle for the limitations of the status quo in higher education, and are looking for schools that meet their needs. Web-based education is increasingly able to entice such students, but may not yet be in the best interests of students. Educators must continue to look toward the future, and avoid being tied down by outdated ideas, while at the same time ensuring education doesn’t simply become another money-making venture.

Marina Salsbury planned on becoming a teacher since high school, but found her way instead into online writing after college. She writes around the Web about everything from education to exercise.

 

 

Learn to build a sexy website!

I am going to be co-teaching a course soon, titled “Learn to build a sexy website” with Andrei Pop. It’s going to be offered online, on Matygo and it’s going to...

I am going to be co-teaching a course soon, titled “Learn to build a sexy website” with Andrei Pop. It’s going to be offered online, on Matygo and it’s going to be kick-ass.

 

So why am I teaching a course despite the hecticness of my imminent move to New York

  • Matygo is an awesome company run by awesome people. I think that their model is definitely going to be step in the right direction for education and I want to be a part of that.
  • Programming is not a mystical force, it’s just a skill that can be learnt and the world will be better off if more people understood it.
  • I’m tired of making websites for people who are smart enough to make them for themselves :P .
  • I spend so much time mouthing off about better ways of teaching and learning that it really is time I put my money where my mouth is and do some teaching myself.

 

The next question I guess is what is this going to look like?

The course will run for 6 weeks. It will be taught in Matygo, which has some elements of an LMS (without many of the downsides). It will be limited to 9 participants, as the live, interactive parts will happen on Google Hangouts.

Hangouts will happen at  7:30 to 9:00 PM on Tuesday evenings starting on October 27th.

 

After the 6 weeks, if you complete all the course material that you will be able to build a great website in WordPress and have a deeper understand of how the internet works and be able to write and hack basic programs.

 

So if you want to learn to code (and hang out with me online over the next 6 weeks) go check out the course page!

The nature of success

On the surface, watching this video is incredibly inspirational:   How Bad Do You Want It from Greyskale Multimedia LLC on Vimeo.   However, as I watched it, there was a rush of...

On the surface, watching this video is incredibly inspirational:

 
However, as I watched it, there was a rush of conflicting thoughts and feelings. One part of me was saying, yes he is right, Andre, you need to be better. Work harder, cut out more distractions, become great. The other part was asking, is that really the way? Will I accomplish my goals in life through single-minded perseverance, or is it in the moments of relaxation, in the serendipitous conversations and in allowing the heart and mind to wonder to where it wants to go that will get me there?

Or, is it simply the right balance of both?

Goodbye Vancouver, Hello New York

I’ve been in Vancouver for just over 5 years now. I came to this city and to the University of British Columbia as a result of the promise of beautiful surroundings...

I’ve been in Vancouver for just over 5 years now. I came to this city and to the University of British Columbia as a result of the promise of beautiful surroundings and an interdisciplinary learning environment. On both counts, this city and UBC have more than exceeded my expectations.

The formal instruction that I received at UBC helped to provide me with many of the technical skills and the conceptual knowledge that I will need to be successful in the future. My work for UBC, with the Office of Student Development, Department of Computer Science, Center for Teaching, Learning and Technology and the Library has taught me the value of continuous learning and has  allowed me to develop my passion for education.

Now however, in the spirit of continuous learning I will be moving to New York City to work with Red Rover, helping them to build out their engagement platform. I will be learning how to write code at the highest standards by working alongside some of the top developers in New York City. I will also be learning about what it takes to have a company be successful.

Most importantly though, if we as a company get things right, I will have the opportunity to create software that have an actual impact of the learning and engagement of hundreds of thousands of people.

Goodbye Vancouver, I’m off to continue my learning. Hello New York, I’m coming soon, get ready.

 

LEARN on Vimeo on Vimeo

via LEARN on Vimeo.

Page 1 of 10123»