Accidentally in Code

Archive for the ‘programming’ Category

I’m spending a lot more time teaching other people to code than I am actually coding at the moment.

Whilst I like teaching, this is not at all in line with how I want to be spending my time.

I TA a mandatory computer course in the management school, and I have a friend taking another mandatory programming course for Engineers. The course I TA teaches VB, and the Engineering course teaches C.

These students aren’t stupid, the students learning VB only have to ask you whether you use VB (of course not, does any self-respecting programmer?) and they know they aren’t learning anything that can’t be done using the built in functions in Excel. The students learning C notice that their TA’s (and the prof) keep accidentally giving them Java code. According to O’Reilly, Java has been overtaking C++ as a teaching language for over a decade. Why are these courses so behind?

I think this is a missed opportunity. Students taking Computer Science have signed up for a degree of torment-by-compiler. These students have not. Instead of a course that they hate why not take the opportunity to create a course that excites them about the potential of programming? Instead of alienating them about the whole concept you motivate them with the reasons and real world examples for why programming is a useful skill to have?

For instance: mashup creation, simple scripting, what an API is (and how to make calls to it), web apps.

Yes, it requires more creativity in course creation. Yes, it may require the people teaching these courses and the TAs to learn more skills. Maybe before it didn’t make a big difference to send a bunch of students into different fields with a hatred for programming. In the new reality though, an understanding of programming and why it is useful would potentially give them a big head start.

What do you think?

Advertisements

Tonight, I ran my first workshop in Wave. It was nice to have a space to discuss things, and unlike in a chat client it’s easy to indicate what you’re replying to. What I did was create a slide deck and make it available the day before. Then on the day, I was available to trouble shoot. The slide deck was fairly comprehensive (see it here) so I encouraged people to work through it at their own pace, whilst I clarified and helped with issues that arose.

Screenshot below shows mutiple threads of conversation happening simultaniously:

Multiple Conversations

Multiple Conversations

It’s also really easy to drag and drop screenshots, so that can help me see where people are at, and what could be going wrong.

Drag and Drop Screenshots

Drag and Drop Screenshots

Wave has nice indentations (kind of like we indent in Java!) that show a diversion:

Indentation shows the flow of the conversation

Indentation shows the flow of the conversation

Finally, trying to schedule when everyone can make the next session can be difficult – but Widgets sure make it easier!

Widgets help with scheduling

Widgets help with scheduling

So, all in all, wish Wave was faster but I think it was a success. Hopefully as people build up more knowledge they’ll discuss amongst themselves more. We will leave this wave going as people work their way through the rest of the slides (and I can help if necessary) and move to a new wave for the next session.

I’ll keep you posted about when that will be – and will put the slides up here soon!

Thanks to everyone who participated.

Tomorrow I’m running an introduction to Java via Wave. Because I’ve had a degree of interest from non-complete beginners in learning Processing, I’ve split the content so that one session will be Java: Building Blocks which will teach the very basics of Java but does not introduce Processing, and the other session will be An Introduction to Processing.

Java: Building Blocks covers the very very basics of Java – writing your first program, primitive types, conditions, and loops. At the end, we should be able to make a simple Hangman game using a framework I will provide.

An Introduction to Processing will cover getting started with Processing and be suitable for beginners who have gone through Java: Building Blocks but hopefully won’t be too dull for more advanced programmers. It will take you through creating your first little Java applet in Processing.

I’m taking suggestions for Topics, but things I’m contemplating are:

  • Java: Next Steps – covering arrays, multidimensional arrays, Objects, more on functions (passing arguments etc). Finishing with a TicTacToe or Pacman game (I have frameworks for both of these).
  • Test Driven Development and Exceptions – throwing and handling exceptions, writing code to pass test cases. Working on a Blackjack game.
  • Creating games in Processing – detecting key presses etc.
  • New Since Java 5 – Generics, enum, for each, etc.

Slides for Java: Building Blocks can be found below. As ever, I really welcome feedback!

After I gave my presentation the other week, someone asked a question. It was:

So, basically what you’re doing is data-mining?

And I said, no, well yes, but that’s not how I think about it. I see it as creating something that will help people understand their use of Twitter. The fact that I achieve this by data mining is by-the-by.

Maybe when we speak to other programmers it’s OK to say something like, “I’m data-mining social graphs in Twitter and visualizing them” but when we speak to our users, that may not mean very much to them. What’s more, I don’t think I would have come up the idea to do that if I’d gone to Twitter with the intention of data-mining. This didn’t come from me as a programmer with an interest in data-mining, or an interest in visualization (as an aside, I took a course in visualization at Edinburgh and hated it. Mostly because we were coding in Tcl). It came from me as a Twitter user, wanting a better way to measure engagement than followers/following.

Yesterday, I wrote a little bit about the journey that brought me to Ottawa. I think I’ve finally realized what I’m passionate about. It’s people. It’s users. This is why I’m so fascinated about what I’m working on right now – what’s more people than social networking? It’s also why I’m so interested in Usability. I’ve read every article on Don Norman’s website, I find usability so interesting, so important.

I’m passionate about giving users what they want – that’s usability, better ways to display data, etc. That’s creating the things they say they want.

Even more so, though, I’m passionate about giving user what they want, that they don’t realize they want yet. In small ways, that’s telling people who are emailing spreadsheets about Google Docs, or explaining to someone frustrated by their web designer about the simplicity and ease of use of WordPress. In bigger ways, it’s been taking a mess of spreadsheets and turning it into a database that can answer questions that users hadn’t even thought to ask. It’s been creating something that’s can make you really aware of your conversational network, and encourage you to talk to new people (the most rewarding feedback I got was from someone who told me they were now making an effort to speak to more people after seeing their graph). I hope these things are just the beginning.

So, what do I want to be when I grow up? I want to be a programmer who speaks fluent human. How about you?

Update: This will take place on Wednesday 18th and Friday 20th November, 7-9pm. Let me know if you’re interested.

I’m thinking to run a session on this tomorrow, with discussion going on via Wave. Will start at 10 or 11am EST and run for 2 hours, with another 2 hours in the afternoon.

Let me know if you’re interested. I know it’s short notice, so I may push back depending on when people want to do it, but this will happen in the next week or so.

What you’ll need:

  • a Google Wave account
  • Java SDK
  • Eclipse
  • Processing, free download – we won’t be using the IDE that comes with it, but try and locate core.jar

I’ll assume your computer savvy enough to install Java and Eclipse by yourself as this could take up a lot of time in the session.

What we’ll cover:

  • Your first program – “Hello World”
  • Simple types (building blocks)
  • What Object Oriented programming means
  • Getting started with processing, displaying stuff
  • Conditions
  • Loops
  • Global vs. Local variables

This is loosely based on the teaching I’ve done and I have a lot of resources that I’ve created that I’ll share. I have enough to do a whole series of these online workshops, if there’s demand. As it gets cold and nasty outside this could be a good opportunity to learn to code if you’re interested in doing so.

CA assignment 3 is now out, and in class today we were looking at the stuff we needed for question 2 (which is ex. 7.1 in the textbook). It’s to manually solve the isomorphism for the two graphs below:

Petersen Graph

Petersen Graph

So I start sketching this out, and then it occurs to me that – ooh, I could easily write some code to validate it for me after I’ve worked it out.

And then it occurs to me that all I’m doing is trying permutations of “abcdefghij” (where the position in the string is the number they’re trying to replace). And if I used Haskell and the handy “permutations” method I could just code it in a brute force manner, and it would solve it for me.

So of course that’s what I did. This is a programmer thing, I think. We work out how to automate things and then we automate them. Yes, it probably took me longer to write the code than it would have to solve the thing manually. I was quite shocked that it ended up being over 60 lines (including white-space, but still… this is Haskell) although I did include my data (the edges) and methods to validate them. I think it could be done with less code, my Haskell is a little rusty.

I find programming much more satisfying than drawing the graph countless times until you get the right answer. Also, my code is purring away now generating all the valid permutations.

In case you’re interested… here are the first 20:

(‘c’,0),(‘d’,1),(‘e’,2),(‘f’,3),(‘g’,4),(‘b’,5),(‘i’,6),(‘h’,7),(‘a’,8),(‘j’,9)

(‘e’,0),(‘d’,1),(‘c’,2),(‘b’,3),(‘h’,4),(‘f’,5),(‘i’,6),(‘g’,7),(‘a’,8),(‘j’,9)

(‘d’,0),(‘e’,1),(‘f’,2),(‘a’,3),(‘i’,4),(‘c’,5),(‘h’,6),(‘g’,7),(‘b’,8),(‘j’,9)

(‘f’,0),(‘e’,1),(‘d’,2),(‘c’,3),(‘g’,4),(‘a’,5),(‘h’,6),(‘i’,7),(‘b’,8),(‘j’,9)

(‘a’,0),(‘f’,1),(‘e’,2),(‘d’,3),(‘i’,4),(‘b’,5),(‘g’,6),(‘h’,7),(‘c’,8),(‘j’,9)

(‘e’,0),(‘f’,1),(‘a’,2),(‘b’,3),(‘h’,4),(‘d’,5),(‘g’,6),(‘i’,7),(‘c’,8),(‘j’,9)

(‘b’,0),(‘c’,1),(‘d’,2),(‘e’,3),(‘h’,4),(‘a’,5),(‘g’,6),(‘i’,7),(‘f’,8),(‘j’,9)

(‘d’,0),(‘c’,1),(‘b’,2),(‘a’,3),(‘i’,4),(‘e’,5),(‘g’,6),(‘h’,7),(‘f’,8),(‘j’,9)

(‘f’,0),(‘a’,1),(‘b’,2),(‘c’,3),(‘g’,4),(‘e’,5),(‘i’,6),(‘h’,7),(‘d’,8),(‘j’,9)

(‘b’,0),(‘a’,1),(‘f’,2),(‘e’,3),(‘h’,4),(‘c’,5),(‘i’,6),(‘g’,7),(‘d’,8),(‘j’,9)

(‘c’,0),(‘b’,1),(‘a’,2),(‘f’,3),(‘g’,4),(‘d’,5),(‘h’,6),(‘i’,7),(‘e’,8),(‘j’,9)

(‘a’,0),(‘b’,1),(‘c’,2),(‘d’,3),(‘i’,4),(‘f’,5),(‘h’,6),(‘g’,7),(‘e’,8),(‘j’,9)

(‘e’,0),(‘d’,1),(‘c’,2),(‘g’,3),(‘f’,4),(‘h’,5),(‘i’,6),(‘b’,7),(‘j’,8),(‘a’,9)

(‘e’,0),(‘h’,1),(‘j’,2),(‘g’,3),(‘f’,4),(‘d’,5),(‘b’,6),(‘i’,7),(‘c’,8),(‘a’,9)

(‘j’,0),(‘h’,1),(‘e’,2),(‘d’,3),(‘i’,4),(‘g’,5),(‘b’,6),(‘f’,7),(‘c’,8),(‘a’,9)

(‘g’,0),(‘c’,1),(‘d’,2),(‘e’,3),(‘f’,4),(‘j’,5),(‘b’,6),(‘i’,7),(‘h’,8),(‘a’,9)

(‘d’,0),(‘c’,1),(‘g’,2),(‘j’,3),(‘i’,4),(‘e’,5),(‘b’,6),(‘f’,7),(‘h’,8),(‘a’,9)

(‘h’,0),(‘j’,1),(‘g’,2),(‘c’,3),(‘b’,4),(‘e’,5),(‘i’,6),(‘f’,7),(‘d’,8),(‘a’,9)

(‘g’,0),(‘j’,1),(‘h’,2),(‘e’,3),(‘f’,4),(‘c’,5),(‘i’,6),(‘b’,7),(‘d’,8),(‘a’,9)

(‘d’,0),(‘e’,1),(‘h’,2),(‘j’,3),(‘i’,4),(‘c’,5),(‘f’,6),(‘b’,7),(‘g’,8),(‘a’,9)

This week I’ve spent a lot of time debugging other people’s code, and we had some fun bugs in class too. This was my favorite bug (I refused to fix it, but she worked out how). I’ve helped people in C, VB, and Maple – none of which are my favorite languages (I didn’t know Maple at all), and don’t have the great debugging capabilities of Java in Eclipse. As a result, I’ve come up with some tips for beginner programmers as a result of the common errors I’ve seen.

  1. Don’t take your code not running personally. Your code (or your instructor) is not out to get you! Debugging requires calm and rational thinking, the more you get upset that your code isn’t working, the less able you’ll be to fix it.
  2. Google is your friend. Lots of people learning to code have had the exact same problems you’ve had, if you can search you’ll often find potential solutions (just be careful – they may not be good, or exactly what you’re looking for). Online is also where you may be able to find that function you need.
  3. Read error messages. I’m losing track of the number of times that someone calls me over to look at a program, shows me how a compilation error pops up and then hits enter before I can read it. Read the error messages! Even if you can’t fix them yet, once you’ve learned what they mean you’ll know what to look for and be better able to fix them in the future.
  4. What are you declaring and why? Think about your variables – what to you need? What do they do? The type of the variable (String/Integer/Boolean etc) is important.
  5. Frame your problem in terms of behavior. If someone frames their problem well, I know exactly what kind of bug I’m looking for. Explain it briefly, then let me look at the code.
  6. Print statements! So useful to see what’s going on inside in the code. Don’t be afraid to use them – you can always delete them later.
  7. Small things can cause big problems. My friend spent hours trying to fix something in her code yesterday – the problem? She was using assignment equals (=) rather than logical equals (==) in an if statement (you can do this in C). Small distinctions can be really important – pay attention to them.
  8. Turn the monitor off. A blank text-editor filling your screen can distract you from the problem itself. Writing code should be the last step in solving the problem – not the first. Turn off the monitor, think about the problem, and break it down into it’s component parts. Then code it in the parts (but don’t be afraid to break them down again if necessary).
  9. The computer will do exactly what you tell it to do, in exactly the order you tell it. A lot of people forget this, but it’s so important. When the computer is not behaving the way you want it to, reflect on this. It’s important to be clear on what you want to happen first, or what you want to repeat (or don’t want to repeat) in a loop, for example.
  10. If you’re lucky enough to have a TA or friend willing to help you – take advantage of that!

Anything I’ve missed? Let me know!