All posts by kibbee

Spreadsheets as an intro to programming

Spreadsheets are a very good tool to introduce people to programming. Much more so than many other applications that try to get people started. a major problem with other popular beginner programming tools like Scratch or Logo is that they don’t really provide much usefulness in the real world. People learn basics of programming but don’t use them outside their lessons because they can’t find a good use for the skills they have learned.

For somebody to really understand the importance of programming, they must first grasp just how much easier it can make their lives. A spreadsheet can easily show how tasks can be simplified when they get a computer to do the work for them. Take a simple task of adding up a bunch of numbers. With a spreadsheet the user can very easily enter a bunch of numbers and get the computer to calculate the total of those numbers. This is a very basic task, but it shows the user the ease at which a computer can be made to do their bidding. If they change a number or want to insert an extra value to be added, then this is a simple operation, and they don’t have to add the numbers again, the computer will do it for them.

But is adding up numbers using a spreadsheet programming? In my interpretation it is. The user is giving the computer a command to perform a specific task, and letting the computer do the work. The computer will then continue to recalculate the numbers whenever the values change.

The other great thing about using a spreadsheet is the instantaneous feedback. The user can quickly and easily change the numbers and see how the result changes. The user can try out new functions and see the results. No need for compiling code or even having to press a key to make it run. Everything just happens in an instant.

Spreadsheets also offer charting features which give the user another way of visualizing the data. The user can easily create many different kinds of charts, and again the charts are updated in real time as the user changes the data.

The user can eventually move onto more complex spreadsheets where writing programs based on the data in the spreadsheet can be done with “real programming languages”. The programming languages and functionality depend on the spreadsheet software used, but Excel, LibreOffice (OpenOffice), and even Google Sheets provide support for writing custom programs that can be used to work with the data in the spreadsheet.

Spreadsheets are a great stepping stone to get people started in programming. I remember finding many good uses for spreadsheets in my highschool classes to make my work easier to complete or sometimes just to make a chart to display some data. The chart could have been drawn by hand, but using a spreadsheet makes the jobs lot easier, and it sure is a lot easier to correct mistakes on a spreadsheet than it is to redraw your chart after you realized you mixed up some values. Even if the user never moves onto more complex spreadsheets with custom functions, they have learned some useful skills that can be applied in many settings, and will have a new tool they can use to make their lives easier.

Surface Studio – A Computer With A Purpose

Are you excited? Because I’m excited. What I’m excited about is the new Surface Studio from Microsoft. Now, this isn’t your typical article about a new product because I’m not even interested in buying it. I have absolutely no artistic ability. I cannot draw well. I have no use for using super accurate pen on the display.

But here’s why I’m excited. Somebody finally designed a computer with a specific industry in mind. I don’t think I’ve ever seen that before. Apart from a few gaming machines, every computer I’ve ever seen has basically been very generic machine that isn’t really suited to one task more than the other. And even those gaming machines are not much more than mostly fancy colors and lights. They do have some interesting keyboards and mice, but they still don’t have as much innovation as we see in the Surface Studio.

I hope this starts a new trend of companies designing computers for specific tasks, instead of one-size-fits-all machines that just do a mediocre job. As a developer, I often think of what I would want in a perfect computer, built with the tasks that developers do day in and day out. Maybe what fits my view of the perfect machine doesn’t fit other people’s needs, even if they are really doing the same task. Perhaps this is why no other company tries to do this, and just ends up settling for a plain old box. Hopefully Microsoft will someday create a software developer centric machine. Something that fits our needs and gets rid of all the junk that we don’t need.

Here’s the video that made me so excited. Maybe it has something to do with the music from Charlie and the Chocolate Factory bringing back nostalgic memories, but this whole video gave me shivers. I don’t even want this computer because I simply have no use for this thing. Most of the great features would end up not getting used and it would just be a fancy $3000 monitor. But seeing a computer that was designed for a specific purpose, and seems to have just been really well thought out, just makes me really happy.

Unsave All Reddit Posts

I had a lot of saved posts built up in my Reddit account so I thought I would do a little house cleaning. Mainly by unsaving all the saved posts. Probably best to just get rid of them all and then try to only keep a list of the stuff I actually wanted, deleting stuff as I go. I had hundreds of saved posts, and going through them manually was taking way too long. So I came up with a little GreaseMonkey script to get rid of all the saved posts.  Here it is:

window.addEventListener("load", function(evt) {
var btn = document.createElement('input');
btn.type='button'
btn.value= 'Unsave All'

btn.addEventListener('click',gm_UnsaveAll)

document.body.insertBefore(btn, document.body.firstChild);
});

function gm_UnsaveAll(evt) {
$('.link-unsave-button a').each(function(i,e){setTimeout(function(){e.click();},1000)});
}

Set it up in GreaseMonkey with https://www.reddit.com/user/{USERNAME}/saved as the included page and you’re ready to go. Just navigate to that page and you should see a button at the top of the page. Don’t forget to replace {USERNAME} with your username. It only unsaves a single page at a time, but it’s better than clicking each post individually. And if you have Reddit Enhancement Suite (AKA RES) installed, then you can scroll down to load up a few pages worth of posts and unsave them all at once. This saved me quite a bit of time, and I now have a clean saved posts list, ready to be filled up again.

Don’t expect school to teach you everything

I find it amazing how many people seem to learn very little outside of what they were taught in their classes. We’ve been interviewing a few people at work over the past few months, and many people just seem to know very little beyond what they where taught in class.

To make matters worse, the kind of experience that you get in classes tends not be the kind of experience that would be very useful in the real world. It seems to be very uncommon that one would have to write something extensive for an assignment in university.  Most assignments consist of maybe 5-10 small functions strung together.  There’s no way to practice code that doesn’t repeat itself because there’s very little chance that you’d run into code that would be repeating.

I’m not saying that classes aren’t important. You can definitely learn a lot of useful things in class that will be very useful on the job. It’s just that you won’t learn the most important thing. That is, how to actually plan and complete a large project from beginning to end.

All the best experience that I got while in university was in co-op placements where I got to work on real projects.  If you are in university and there’s a co-op or internship program available make sure you take advantage of it.  This usually means it will take a little longer to graduate, but the experience you get will be very valuable.

I was also very lucky in that we had a two semester group project as one of our classes. In this class, we were required to find a customer who wanted an actual product (the professor had some people lined up, but we were free to find our own if we pleased) and do an entire project from beginning to end. We were required document what we were doing, write the code, write the test cases, and meet with the customer to discuss requirements and talk about how the project was progressing at regular intervals. This taught me not only about the technical side of software development but also how to actually work not only with other developers, but also the customer.

The other thing that I find is that a lot of students don’t have experience using real world tools. Very few students seem to know how to use a debugger coming out of university.  I don’t know how they get along without it. But I guess if you’re only doing very small projects, then they aren’t that necessary. But when you’re writing projects that are larger than you can fit in your head, it makes  the job a whole lot easier when you have a debugger and you can step through the code to see what’s going on.

My advice to anybody in college or university is to try to learn as much as you can before you graduate.  This is when you’ll have the most free time. You may think you are busy now with assignments, studying, and even a part time job,  But the truth is that now as a person with a job and a family, I find that I have much less time now than I did as a student.  I wasted a ton of time when I was a student and really wish I had spent my time more wisely.

So think of a project that interests you and go ahead and do it.  You’ll learn a lot more from doing an actual project than you will from just about any class.  And you’ll have something to showcase your skills when it comes time to interview for jobs.  You’ll definitely stand out from the rest of the applicants.

Of Bike Mechanics and Computer Repair Techs

As somewhat of a bike enthusiast, I came upon this presentation discussing bicycle mechanic salaries.  Long story short, they are depressingly low. At around $22,000, it’s pretty close to the minimum cost of living in most places.  In many places, this won’t even cover rent in a 1 bedroom apartment.

So, it seems there’s a problem in that it’s almost impossible to make a living being a bike mechanic.  Bike mechanics can be useful, and I’ve even taken my bike to a mechanic from time to time. The presentation (I use this word, because a simple 1 page article was turned into 39 slides), states that some bikes can cost $8000, and that people are unwilling to pay $80 for a tune up.

While a bike certainly could cost $8000, most do not.  I don’t have any actual data, but based on the bikes I see on the street, that the average price of bikes that are sold, is somewhere around $400.   Most people, even the enthusiasts that I know, will never spend more than $1500 on a bike.  For those that aren’t enthusiasts, and who only shop for bikes at Walmart, will probably think that $400 is way too much for a bike.  And bike prices are only coming down.  $1000 will get you a bike that’s better then what the pros were riding 10 years ago.

When you have a $400 bike, charging $80 for tune up sounds like a lot to ask.  It’s similar to a computer repair guy from the Geek Squad asking you for $80 to fix you $400 laptop.  For the price of a couple tune ups, you’re well on your way to purchasing a whole new bike, or laptop.

Fixing a bike is easy. You don’t even need many fancy tools.  About 95% of the work you will ever have to do on your bike could probably done with about $50 worth of tools.  There’s even this great site  where people will help you fix your bike for free.  And it’s also (at least in my opinion) quite invigorating, to know that you can do it yourself, when you’re 50 km from nowhere, and something breaks, it’s nice to know you could solve the problem yourself instead of having to hitch-hike home, or call someone for a ride.

This is very similar to computers, where most people could figure out how to fix their own computer if they just took some time. Actually, fixing a computer is probably more difficult than fixing most bike related problems, as actually diagnosing the problem, and fixing it without just formatting the machine and starting from scratch can actually be quite difficult.  A bike has way less parts than a computer.  And there’s very few things that actually go wrong with quality bikes

I admit, if you have an $8000 bike, and need it for racing, where seconds can mean the difference between winning and losing, then paying somebody big bucks to makes sure the wheels are perfectly true, and the gears and brakes are adjusted just so makes perfect sense.  At this point you should be spending your free time training, and not mucking around with wrenches and grease.  But if you just use your bike for transportation or recreational rides, then you really should be doing your own maintenance.

I don’t think we can solve the problem of the low paid bike mechanic.  If you want to make big bucks as a bike mechanic, you’d better start fixing bikes for people who really care about them. People who’s livelihood depends on their bike, like professional bike riders.  Just like computer techs who want to make more money have to end up going to fix computers for people who have rooms full of computers, and having a computer not working  means loosing money for every minute that computer isn’t running.

But I just don’t think there’s any money to be made in tuning brakes, tuning derailleurs, and switching out bottom brackets.  It’s too easy to learn to do these things yourself, and if you start asking for more money in the hopes of making more money, you’ll probably just drive potential customers away, who will figure out how to do it themselves, or get the local high-school bike enthusiast to do it for the price of a couple inner tubes.

Battery Powered Raspberry Pi

Since the Raspberry Pi is so small, and has a similar architechure to most phones, I was thinking it would be fun to see if I could run it from batteries. I wanted something that would give it a long run time, not something that would only run for half an hour. It would also have to utilize rechargeable batteries, otherwise, the
cost of the batteries would quickly outrun the cost of the Raspberry Pi. Also I have no abilities to build my own circuits, so it had to be something I could buy ready to use.

After doing a little searching, I was able to find this USB battery backup case. It uses 18650 lithium batteries. It’s meant for charging cell phones and other gadgets when they run out of power, so I figured it would work quite well for powering the Raspberry Pi. Most people in North America will probably be a little unfamiliar with these batteries. But I think they are great. They look like AA batteries, but are actually quite a bit bigger, are rechargeable, and run at a higher voltage. They are actually similar to the cells that are used in many laptop batteries. I had used them before for bike lights that I had purchased from that same site, and was really impressed with how much power they were able to hold. I don’t know why they don’t have batteries like this in North America. They kick the pants off anything you can find around here.

The battery backup case provides 5V at 1A and each of the batteries I purchased was rated at 2400 mAh and 3.7V. The battery backup case also doubles as a charger for the batteries. Plug into the USB Mini on the battery backup unit, and plug the other end into a phone charger (similar to what you use to power the Raspberry Pi, and it charges. The full size USB port is used for powering devices. Get a cable that is full sized USB on one end, and micro USB on the other end, and you can use it to power your Raspberry Pi. This is one of my main disappointments with the device. Had they used USB micro to charge the batteries then you could have used the same charger to recharge these batteries as you use to power your Pi, but the way it’s set up you need 2 different cables. This unit, like the Pi, comes without any cables. Luckily I had a few lying around.

My first use for the device was to test it for it’s intended purpose, to charge my phone. I charged the batteries in my old charger, as I was unaware that this device even had charge capabilities, and then put the batteries in the backup unit. Plugged it into my phone. Nothing. Pushed the button. Nothing. I really just thought the thing was completely dead. I decided to just Google for “dealextreme 129749” which is where I bought it and the SKU, and about 5 links down the page I found this page, which was somebody else who bought it and had the same problem. Of course, the page is in Polish, so what could I was stuck. Google Translate to the rescue. It did a fair job, good enough for me to figure out that if I hooked up USB mini port up to a charge or computer, that
the device would turn on, and start working. It did a pretty good job at charging my phone. It worked about as good as it does when plugging my phone into the wall. The batteries didn’t get hot at all, and there was a little bit of heat from the circuit part of the charger, but nothing worth worrying about.

Then it came time to try it out on my Raspberry Pi. I wrote a program in Python to record the current time to a file every minute, so I wouldn’t have to sit around watching and waiting for it to die. The program is as follows

import time
i = 0
print('START!')

while i >= 0:
        f = open('timelog.txt','a')
        nowstr = time.strftime('%Y-%m-%d %H:%M:%S')
        print(nowstr)
        f.write(nowstr)
        f.write('\n')
        f.close()
        time.sleep(60)
        i = i + 1

print('DONE!');

There’s obviously some testing code left in there, switch the condition of the while loop to “i < 5” if you just want to run a test and have it exit after 5 minutes. I opened an closed the file each iteration because I didn’t wanted to be reassured that the writes wouldn’t all disappear when the power cut out.

Now for the test. I started up my Pi, ran the time logging program in the background, and then let it run. I wanted to see how well it would do under minimal load. The results were pretty astounding. It ran for just under 5 and a half hours. Which once you count in the boot up time and me starting the test probably came in pretty close to exactly 5 and a half hours.

Being somewhat impressed, I wanted to now test it under full load. It would be easy enough to write a busy while loop to get it to use the CPU at 100%, but I wanted to stress out the GPU as well. So I posed a question on raspberrypi.stackexchange.com and one person suggested using Quake 3 to test it out. I figured that would use probably as many resources as possible, so I gave it a go. In the background I ran my python time logging program same as before, and in Quake 3 I ran a demo loop to max out the resources. I put the following in a file called demoloop.cfg located in the baseq3 folder for Quake 3.

set loop "vstr loop1"
set loop1 "set timedemo 1 ; demo four ; set nextdemo vstr loop2"
set loop2 "demo four ; set nextdemo vstr loop1"

Then I started Quake 3, and ran the demo loop by bringing up the console with “~” and typing:

exec demoloop.cfg
vstr loop

The demo began to loop. I had to use some commercial .pk3 files because the demo wouldn’t run with the freely available files because missing maps. I watched for a while, using my laptop on the side. I didn’t expect it to last very long with the CPU and GPU undergoing so much use. Eventually I got bored and went to bed. In the morning, I woke up and checked the results. The total run time was 4 hours 23 minutes before the log program stopped logging the time, and I presumed the Raspberry Pi lost power.

All in all I have to say that I’m pretty impressed that I got such good performance out of this battery pack. The batteries stayed cool, even when running my Quake 3 stress test. This battery pack did quite a good job, and would probably work quite well for anyone who wanted to power their Raspberry Pi off batteries.

Raspberry Pi – First Impressions

I got my Raspberry Pi a couple weeks ago, only a few short months after placing my order, and I’ve gotten a little bit of time to play with it. So far the experience has been pretty good. The speed is pretty much as I expected. I was able to get Quake 3 up and running on it. I spend countless hours playing that game in university, and it sure did bring back some memories.

I think the thing I like most about my experience so far is that I can get different SD cards set up, one for a media centre, one with a working desktop distribution, one to play around with and break, and more for whichever purpose I feel like. It’s nice having a computer you can just tinker with, where you can back up the whole system in a matter of minutes, and load on a whole new OS quickly if something goes wrong. I haven’t had a computer I can just tinker with in quite a while. It’s also nice that the Raspberry Pi doesn’t take up any space, and that I can just hook it up to my existing peripherals.

I have had a couple problems with it. My wireless keyboard that I use with my desktop doesn’t seem to work so well. Sometimes keys stick and repeat endlessly, and sometimes keystrokes don’t register. I’ll have to go and get a USB keyboard soon, but so far most of my experimenting has been connecting through SSH and VNC remotely, so I haven’t needed the keyboard for too many tasks.

I’ll be updating this blog with a few of the things I’ve figured out, just to pass on the knowledge. Most of the stuff has been pretty straight forward, but I’m pretty familiar with Debian, so most of it was the same as what I’m used to. I have to say, I’m really impressed with the way the distributions have been put together. Kudos to the people who are working on these. I expected things to be much more difficult to set up.

The root word of specification is specific

As a developer, I’ve seen a lot of specifications float across my desk. The quality differences between them is staggering. Sometimes you get a really nice specification document. Other times things are a complete mess. What bothers me most about some specifications, it that they aren’t “specific” at all. They leave way too much up to the imagination. They’ve left out way too many use cases.

The first thing I do when getting a spec is that I go over all the different use cases. I start coding the thing in my head, and start to think about all the different interactions the system will have. Most of the time, in the first 5 minutes I can come up with 2 or 3 use cases that the author of the spec didn’t even consider.

This is very frustrating, because, when the specification is a work in progress, it means that I must send back the spec to the person who wrote it up, and ask a whole bunch of questions to clarify or expand on the specification so that we don’t end up with a system that doesn’t do what it’s required to do.

When it’s not a work in progress, I just resort to slamming my head against the desk. Because what that means is that this specification has already gone across the desk of many other developers, and there’s probably very little I can do to get things changed, because then all the other implementations would have to be adjusted to fix the changing spec, and even if they all wanted to, the people in control of the spec think there’s nothing wrong with it, because everyone else has been using it for years and never come across a problem (or never bothered to complain).

Anyway, I think that the best thing you can do with a spec is to get as many people to read is as possible. Because other people reading it will find holes in the specification. They will find new ways of interpreting whatever it is you wrote, and they will make your specification more clear and more useful to other developers. Because nobody wants their project ending up like PHP.

Coding For Fun

Sometimes when I’m coding for work, I feel like it’s lost all it’s fun. At work, we sometimes have to work on boring projects. For me the boring projects are the ones where I don’t even have to think about what I’m doing. The tools, the framework, the existing libraries are enough that I can get the job done without even really thinking about it. The kind of project where you can just go straight for 2 hours of programming, compile once, run it, and it just works, no fixes needed.

Now when you can do this, you at least you know you are doing something right. Because not everything you have to do should be some kind of epic battle to get stuff done. Trudging into new territory. But that doesn’t mean it doesn’t drown your spirits when the only thing you’re doing it just going through the movements to get the code into the computer.

I really enjoy going out and exploring new tools, new languages, new language features, new anything, because it really makes me think. It opens up your mind to new possibilities. A developer who doesn’t code for fun is usually not a very good developer. If you can’t take pleasure in exploring programming, learning new techniques, discovering unexplored territory, then you’re going to have a lot of trouble staying on top of all the new technologies.

If you find yourself getting bored with coding, just go out and try something completely new. Program a type of application that you have never programmed before, in some language that you aren’t that familiar with. Exploring new avenues in development will take your mind off the day to day drudgery that your job is, and really help to bring the fun back into programming.

Don’t Fight The Tools

I’m a .Net developer by profession. So it’s only natural that I hate PHP. OK, I don’t hate it, but I find it quite frustrating. I think that the reason that this is, is because they are just so different. They take a completely different approach to accomplishing the same thing. So when I go to program something in PHP, which I don’t do that often, I try to write .Net code in PHP. This is very difficult. In the latest project I did, namely, this blog, I tried to do the exact opposite. I decided to write my PHP to make it look like PHP. To me, it seems a little unnatural. Mixing in logic and presentation. Mixing in database access code with presentation. Basically creating no layers between anything. Get some data from a database, output the data with HTML tags interspersed with the data.

PHP has added a lot of stuff to try to get away from it’s humble beginnings. They’ve added objects, namespaces, frameworks for doing MVC or other types of architectures. But I find that all of it is kind of done poorly. Without getting into too much of a rant, it seems like PHP is just trying to add features, just to be like the big boys. But in the end, it makes everything look inconsistent, and gives people a bad impression. Nobody complains that C doesn’t have classes, interfaces, and namespaces. If you want that, go find another language. PHP could have taken a lesson from that, but alas it’s too far gone.

It’s really similar to this Ask Slashdot article. The first post sums it up. Don’t try to write C++ or Java in Javascript. Similarly here. Don’t try to write .Net in PHP. And I wish PHP would just be happy being PHP.