Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Monday, 14 July 2014

Mike Hall's Asteroids

Every few years I get some excuse to re-examine the Java source code for Asteroids by Mike Hall. This time it was preparing some Java lessons for CoderDojo.

Two things have always really impressed me about this Java app:
  1. It is SUCH a good reproduction of the original game
  2. The code is so nicely done
 Mike Hall has a website called brainjar.com.

As well as writing Asteroids, he also did some great work on Dynamic HTML back in the day, including:
I wonder what Mike is doing these days. The footer of his website says "(c) 1999-2014 by Mike Hall" but to be honest I don't think it has changed much since the early 2000's. And things have moved on quite a bit since then!

Anyway, I would recommend playing the game and reading the Java source code to anyone.





Saturday, 14 June 2014

BASIC is 50 years old

The BASIC programming language turned 50 on the 1st of May this year.

BASIC was first successfully used to run programs on the school’s General Electric computer system at 4 a.m. on May 1, 1964. It was invented by John G. Kemeny and Thomas E. Kurtz of Dartmouth College in Hanover, New Hampshire. They are shown in the photo below with one of their students.

BASIC is an acronym, standing for "Beginner’s All-Purpose Symbolic Instruction Code".

You can see the manual for this first version of BASIC here.I particularly like the section on the use of "teletype typewriters"! That first version had a very limited number of commands, including the infamous GOTO!

But, in my opinion, BASIC played a critical role in the Personal Computer revolution. Every computer came with some form of BASIC. My own first computer, an Apple II, came with "Integer BASIC" in ROM (written by the genius who is Steve Wozniak) and "Applesoft BASIC" (written my Microsoft) on cassette tape. And everyone who bought a person computer entered programs in BASIC (often transcribing them from books and magazines).

Without BASIC, what would have been fuelling this desire to write programs on your own computer? COBOL? Pascal? FORTRAN? Forth? Logo? ALGOL? Lisp? It's hard to imagine. (Java, by the way, wasn't to make an appearance until many years later in 1995)

And of course Assembler would be out of the question (too complex, and no practical ability to share code across different computers).

There is a nice video on this part of computer history on the Dartmouth website here.


Friday, 18 April 2014

Scratch Competition Finals

I mentioned in my last post how proud I am of my son who got his junior black belt in karate.

Well this time I need to mention my daughter Ellen who got through to the finals of the 2014 Scratch competition!

This seems to be the fourth year that this competition has been run.

Apparently there were almost 1000 entries from all over Ireland and 5 are going through to the finals in each of 5 categories.

In CoderDojo Malahide we encouraged the kids to enter the competition and I'm delighted to say that we have a second finalist: Joshua Murray who is in the 4th year to 6th year category.

Ellen's entry can be seen here and Joshua's here.

Well done Ellen, Joshua, and CoderDojo Malahide!

More details of the competition and the finalists are available here. The finals will be held on the 2nd of May.


Monday, 6 January 2014

Scratch 2 - Renaming a Sprite

I have forgotten this a few times so I'm going to blog about it to remind myself!

In Scratch 2, renaming a Sprite (or changing its other properties) is no longer intuitive.

To do it, you need to:
  1. Select the sprite in the Sprites pane
  2. Click on the little "i" in the top left hand corner
  3. Make whatever changes you need
  4. Click on the arrow head to return to the normal Sprites pane

No idea what they were thinking when they made this design decision.


Thursday, 8 August 2013

The 10 Most Influential Software Programs

A blogger took it upon himself to try to name the 10 most influential software programs ever.

Here is his list:
  1. SABRE (IBM, 1964)
  2. Maze War (1973)
  3. Adventure (1975)
  4. VisiCalc (VisiCorp, 1979)
  5. WordStar (MicroPro, 1979)
  6. Hypercard (Apple, 1987)
  7. Photoshop (Adobe Systems, 1988)
  8. Lotus Notes (IBM, 1989)
  9. Mosaic (NCSA, 1993)
  10. Minecraft (Mojang, 2009)

I think it's a really good list.

I am particularly impressed by his inclusion of Hypercard and Lotus Notes.

The omissions as I see it are:
  • Sidekick (Borland, 1983)
  • Turbo Pascal (Borland, 1983)
  • PageMaker (Aldus, 1985)

PageMaker was the product that made companies want to buy a Mac. I was working in just such a company. I fell in love with the Macs, of course (I had an Apple II at home by then) and spent the rest of my time there trying (without success) to convince my manager than I should switch from an IBM clone to a Mac.

I discovered Hypercard on the Mac and (even though I only ever played with it) I thought was very exciting product with huge potential.

Turbo Pascal (which I never used although I did use Turbo Basic) brought tremendous innovation in the area of the Integrated Development Environment (IDE): the forerunner of today's Visual Studio and Eclipse.

Saturday, 25 May 2013

Scratch 2.0 - Where I think they have gone wrong

I have a number of issues and reservations about the new version of Scratch - Scratch 2.0.

1) Use of Adobe Flash

The first issue is that the development environment is now online and is based on Adobe Flash.

This continues a trend which we saw with the previous version of Scratch where the online environment moved from using a Java Applet to view games to using Flash. You could still switch to the Java Applet but the default was to use the Flash player. In 2.0 the support for the Java Applet on the Scratch website has disappeared completely.

The Flash player is a technology which is on its last legs, IMO. The beginning of the end was when Apple release the iPhone and there was no flash support. YouTube responded by providing an alternative to Flash for iPhone users. The middle of the end was when Steve Jobs wrote his "Thoughts on Flash" open letter in April 2010 and then Adobe announced in November 2011 that it will no longer develop Flash for mobile platforms. Mobile is everything these days. The end of the end cannot be far off.

Interestingly, the  University of California at Berkeley has created SNAP! (formerly known as BYOB for "Build Your Own Blocks") which is described as an "extended reimplementation of Scratch". It doesn't use Flash. In fact it just uses JavaScript. The amazing thing is that it actually runs in iOS. I have used it on a iPad (even though Apple try to limit people's ability to develop code on an iPad). To be frank I think that UCB have outsmarted MIT. You can access SNAP! here.

2) Lack of "offline client"

The Scratch site says that an offline client will be available "early in the summer". This is a little vague for my liking. I think being able to work online is great, but being able to work offline is essential. That's how IDEs are supposed to work, IMHO.

When we teach Scratch in CoderDojo, we like everyone to be able to run Scratch independently. We don't want to have to give all of the kids Internet access.

As if that weren't enough, Scratch 2.0 uses a different file format. So while you can still develop in Scratch 1.4 and upload programs to the Scratch website, you can no longer download them to work offline.

So pending the release of the new offline client, you can no longer download and remix other people's programs using the offline client.

In summary, I think the Scratch team has lost its way a little and they have made a couple of pretty serious strategic and tactical errors with the current release. How damaging they will be remains to be seen.

Tuesday, 21 May 2013

Scratch 2.0 Released

After what seems like an age in "Beta", Scratch 2.0 has been released.

Perhaps the biggest change is that you edit the programs online now (using Flash). The new version of the offline editor is due "this summer" apparently.

Other changes include:

1) You can clone a sprite. This has great potential for people who want to write "Space Invaders", for example (I have great admiration for the people who wrote version of this game when you couldn't clone sprites). I'm not entirely sure how this would work in practice though (there are no class variables, no way to pass parameters to a constructor, and no way to "block" other threads when updating a variable).

2) You can create your own blocks. This is obviously good as it gives you the basis of writing your own methods/subroutines.

3) You can store numbers in "cloud variables". This is useful for having high scores which work across all players, for example.

4) You can access the user's webcam. Sounds good in principle (you could write games a little like on the PS2 EyeToy) but I haven't really had time to play with it yet.

I guess that covers some of the good news. I'll cover some of my negative thoughts in my next posting.

Monday, 11 March 2013

CoderDojo Mentor T-Shirt

Mentors in CoderDojo in Malahide will be sporting these t-shirts from now on.

Good idea, and not a bad looking shirt either!

And lots more ideas in the pipeline.


Sunday, 10 March 2013

What I would change in Scratch

If I could wave a magic wand and change one thing about Scratch...

It wouldn't be any of the things I have mentioned previously: FOR loops, FLOOR and CEILING functions, different method for handling layers.

It wouldn't be the facility to clone sprites. It wouldn't be the facility to write subroutines and functions.

Note: Some of these have been addressed in Scratch 2.0 which is currently in Beta and all of them would be on my wish-list.

Instead it would be to reverse a decision which I'm sure the designers made with the best of intentions. It would be to allow you to move a sprite completely off the "stage".

The designers decided obviously that having a sprite which if off the stage would be confusing for kids. So if you instruct a sprite to move off the stage it will only do so partially - the x/y coordinate will simply refuse to increase/decrease past a certain point.

This is annoying where you want to:
1) Have a sprite glide onto or off the stage
2) Work with scrolling backgrounds

So yes: if I could do one thing then that would be it.

And no: this has not been changed in version 2.0.

This picture shows how you cannot get the Scratch Cat to exit the stage no matter how many times you press the space key:

Friday, 8 March 2013

Scratch Programming - Layers

All sprites in Scratch have three coordinates: x, y and z.

The x and y can be set directly:
The z cannot be set directly but can be adjusted by changing the sprites layer. This is not as intuitive as it might be (well it certainly confused me for a while).

I imagined that a sprites layer number would work in a similar manner to the x and y coordinates. So a sprite which has been told to "go back 5 layers" would be behind one which has been told to "go back 3 layers".

The reality is that every sprite has a unique layer. When you tell a sprite to "go to front" it does just that. It takes a position in front of all other sprites (let's call this layer 1). The sprite that was on layer 1 moves back to layer 2 and so on down the line.

When you tell a sprite to "go back 1 layers", it basically swaps places with the sprite that was behind it.

When you tell a sprite to "go back -1 layers" (you can use negative numbers) it swaps places with the sprite that was in front of it.

So basically all layers are relative, not absolute.

I added the following code blocks to a sprite in a 2 sprite program:

When you press "a" the sprite goes behind the other sprite.

When you press "b" it comes back to the front again (you do not have to press "b" twenty times!!)

Monday, 11 February 2013

Scratch - What's Missing

In this posting I want to talk about two things that are missing from the current version of Scratch (I'll also mention the upcoming version).

Before I start I want to acknowledge that the designers of Scratch were anxious to keep the environment simple so that newcomers and kids would not find it too confusing. So the omissions that I am highlighting here were no doubt conscious decisions by the designers. But for people who are used to other languages they are very surprising (and quite annoying to be honest).

The first is that there is no FOR loop.So if you want to perform a loop X times while changing a variable from 1 to X with each iteration, you have to do that yourself. So you need to set the initial value, check against the limit, and increment the variable by hand each time yourself.

In Whack-a-Bird I needed to a nested FOR look to move across the 3x3 matrix of holes while drawing them. Here is now the code ended up (this would have been a lot tighter if there were a FOR block):
In the new version of Scratch (2.0 - currently in beta) there is still no FOR loop!

The second omission is that you can only convert a floating point number to an integer using the ROUND block. There is no block for truncating or rounding down. This is a big omission for games writing.

For example, if you want to convert a number to two components to work with a 4x4 matrix, you will use division and the modulo function to get the two components. In Java it would look like this:

     int y=number/4;
     int x=number % 4; // % in Java is the remainder or modulus or modulo operator

Here is how that would look in Scratch. The second line will work as expected but unfortunately the ROUND block will change the answer by rounding up the result when you don't want it to:


The good news is that this HAS been addressed in Scratch 2.0 which, in addition to a ROUND function, has both CEILING and FLOOR functions.



Second Scratch Game - Whack-a-Bird

The second Scratch game I wrote, and the first I "shared" on the Scratch website, was called "Whack-a-Bird".

I've always liked whack-a-mole games (both the real and the computer versions) and I thought it would be a nice one to do with sprites (controlling position, appearance and detecting clicks).

I decided quite early on that the "mole" should be one of the red angry birds. Then one of my kids reminded me that there should be some targets that you should not want to hit and the black (exploding) angry bird was the obvious candidate.

I used to play a game called "Boulder Dash" back in the 80's and the main character ("Rockford") used to tap his foot if you didn't get on with the game. This made me think that I should animate the splash screen in some way so I put on of the birds onto it and I had him look from left to right continuously. Then I was wondering where to put the instructions so I had him "say" them randomly while waiting for the game to start.

In my version you have 2 minutes for the game, things speed up as time runs down, and then game ends if you miss 10 birds. You can play it here.

Once I had "finished" the game, I decided that an important element was missing - the possibility to have multiple birds popping up at the same time. The obvious solution to this is to have 9 sprites - one per hole. This would be the right solution if you could "clone" sprites during the game but (since you can't in the current version of Scratch) you would need to duplicate the sprite in the designer. I though this was a bit of a cop-out. In the end I created 4 copies of the sprite and I position them randomly into the 9 positions. This version of the game is much harder/more challenging. You can play it here.

Saturday, 9 February 2013

My first Scratch game

The first game I wrote in Scratch was called Tank and was extremely simple.

I decided to take advantage of the fact that sprites could turn in any direction, and move in that direction, and could be resized.

The idea is to steer a tank to fire on targets which appear in random positions.

The game, as I said, is simple and only has 6 sprites (3 being the tank, the target, and the missile) and 22 scripts. There is a timer which counts down from 60 seconds and you can move from level 1 to 5 as your score increases (with the target getting smaller each time).

You can steer and move with the arrow keys. Late on in dveelopment I added the facility to aim the tank using the mouse (and in so doing created my first checkbox!).

There are still a couple of bugs in it (you can still control the tank even after the game is over, and the target can appear behind the variables at the top of the screen).

Even though it is simple, my kids enjoyed playing it. You can play it here.


Scratch - A great programming environment

Scratch is a programming language/environment which was developed in 2006 at the MIT Media Lab.

It was designed to help kids to learn to program by allowing them to get results fast. It supports "Sprites" and when you launch the program it starts with this sprite already loaded:

In Scratch you don't write code by typing it in. Instead you drag "blocks" from the "Block palette" into the "Script area" and you join them with other blocks.

Here are some very simple examples of how easy it is to get your sprite to do something. The one on the left is the classic "Hello World". The one on the right will simply move your sprite to the right. Both are triggered by clicking on the sprite:

The great things about Scratch in my opinion are:
  • It is easy to create and manipulate sprites, and to respond to events
  • Because you are dragging in code blocks, you can't really make syntax errors (although you can still have bugs of course!)
  • It is easy to integrate sound (audio files, drums, and other instruments)
  • The development environment is very good
  • You can get results quickly
  • It's fun!

But that's not all. The third item in the drop-down menu (after File and Edit) is "Share". Scratch is designed to allow you to share your projects with other people and to run the programs which they have written. You can search for other programs and you can even run them directly on the web page (thanks to Flash and Java players). And if you see a program that you think you could learn something from, then you can download it and see how it works. And you are free to enhance the program which you have downloaded and to upload your own version. Genius!

Scratch can be used to create interactive stories, animations, games, music, and art. You can do simple things with it, and you can also do complex things. Here are links to some classic games written in Scratch which you can run directly from the web page with no download:
Pacman
Space Invaders
Asteroids

To finish up this posting, here's a little piece of code which should make sense even if you don't know Scratch:

Teaching Kids Programming

A few months ago I went looking for some kind of environment to give my eldest daughter some exposure to programming. As she has a iPad I was really looking for something that would work there. I quickly found (to my surprise) that Apple do not want people writing code on iPads!

What we ended up using was Cargo-Bot. This is a free game which teaches some of the basics of solving programming puzzles. The idea is to control a robotic arm which can lift, move, and put down boxes. You are given a starting position and a desired ending position and have to work out an algorithm and then write the "code" by dragging-and-dropping icons for instructions. But to be honest it is more of a puzzle and less of an aid to learning programming. Perhaps we should have downloaded Codea which is the language which Cargo-Bot was written in. But that called for a $10 investment and we just couldn't make up our minds.

In the end, of course, CoderDojo came our way and we discovered that Windows and Scratch was (for us at least) the way to go. My next posting will be on Scratch.

BTW: It seems that Apple are relaxing these rules about not allowing people to write code on the iPad. Perhaps Codea itself is a good example of this.

Here is a picture of a user trying to solve a puzzle in Cargo-Bot:

Friday, 1 February 2013

CoderDojo - Computer programming for kids

CoderDojo is a "movement" which aims to introduce young people to software development ("coding").

It was started in Ireland (in Cork to be more specific) by James Whelton and Bill Liao. There are now 22 countries listed as having CoderDojo clubs.

My daughter started to attend the local club in Malahide late last year and she really enjoys it.

They start people off learning "Scratch" which is a really cool language for developing games, animations, etc. I will return to Scratch in future postings.

A few weeks ago I signed up as a mentor.

In my first class there were 40 kids in the Scratch groups (I counted them!). They were others in other groups (e.g. learning website development).

All of the kids (ages from 8 to 17 in theory but most of them were towards the lower end of that range) sat down at tables and took out their laptops. The parents stayed with the younger kids.

I had never stayed for a class before and wasn't entirely sure what the expect. How could 2 mentors cope with 40 kids for 2 hours?!

But the truth is that most of the kids just worked away independently for the 2 hours. They seemed completely happy.

So the great things are:
1) It's great to see kids developing games rather than just playing them!
2) It's nice to think that we are encouraging the software developers of the future.

If you want to start your own club then take a look here.


Saturday, 15 December 2012

Programming Languages

I was at the open day at Coder Dojo in Malahide this morning with my three kids.

Very interesting presentations on hardware and programming. And demos of cool stuff including a Raspberry Pi and a JavaScript-controlled helicopter!

The organisers asked the kids to name programming languages. The kids duly came up with Scratch and Java. One of the kids asked me if I could name any more. That got me thinking.

So here I am going to name all of the programming languages I can think of in alphabetical order:

Algol, APL, Assembler, AutoIt
B (I think?), BASIC
C, C++, C#, COBOL
D
E
Fortran
G
H
I
Java, JavaScript
K
Lisp, Logo, LotusScript
M
N
O
Perl, PHP, Processing, Prolog, Python
Qt
Rapid-Q, RPG, Ruby
Scheme, Scratch, SNOBOL, SQL
T
U
VB, VB.NET
W
X
Y
Z

That's 31 by my count.

There are lots more than I know of but can't remember, and lots more that I have never heard of.