If you've subscribed to my YouTube channel you'll know that I have lots of lessons on programming C, Java, Delphi, Ruby and more. Over the past few months I've been posting a series of videos to help people get up to speed with C# programming. These lessons can be followed in order if you are new to C# or you can just jump in to watch whichever lesson is of interest. This is the latest video...
Monday, 5 October 2020
Tuesday, 22 September 2020
Recursive programming is surprisingly hard to learn for something that, in essence, is really quite simple. A recursive function is one that calls itself. So, you might have a function called x() which somewhere inside its code calls itself x() rather than some other function such as y().
Recursion is a very valuable technique when you want a function to do an operation a certain number of times until it’s run out of things to do. For example, if you want to count all the files in a set of subdirectories you can use recursion to keep looking for more subdirectories until there are no more subdirectories (or subdirectories of subdirectories) to recurse. Then you can count the files in each subdirectory. This sounds like it should be easy to do – and in essence it is. But unless you really understand how recursion works, it can be tricky.
I teach a whole course on recursion and I also have a book. Either one will teach you all you need to know to understand recursion – what the stack is; how frames are added to and removed from the stack whenever a function is called; how to save values from recursive functions; how to return values; how to avoid infinite recursion and more…
My course normally costs $45 but if you click this link you can enroll for just $19 (plus any local taxes applicable): https://bitwisecourses.com/p/recursion-for-programmers/?product_id=778235&coupon_code=RECUR01
(Valid until end of October)
Alternatively, you can buy my book, The Little Book Of Recursion, from Amazon:
Amazon (US) https://amzn.to/2JjrJtq
Amazon (UK) https://amzn.to/2YCYx5N
Or search for its ISBN: 978-1913132057
The code examples in the course and book are mainly given in C and Ruby. However, recursion works in a similar way in all mainstream languages. To prove this, I’ve translated most of the C code into Java. You can get all the free source code (C, Ruby and Java) just by signing up to my mailing list and I’ll send you the download link: www.bitwisebooks.com
Meanwhile, here’s a short lesson explaining how to write just about the simplest possible recursive function in Java…
Tuesday, 8 September 2020
Why I used to love Delphi – but not so much now…
So I loaded up Delphi (Community Edition) this morning and I saw an unhelpful dialog box telling me that the software had expired and prompting me to enter a valid serial. I found my serial number, entered it, but it wasn’t accepted. What was I to do? The damned dialog box didn’t give me any other options.
Time to Google. Lots of other people had the same problem. Advice was to go to the Embarcadero site and download a new copy of the software: https://www.embarcadero.com/products/delphi/starter/free-download
I did that. Or tried to. Every effort I made to log in failed with a warning that my session had expired. Maybe my browser (Chrome) was the problem? OK, so I tried in Firefox. Same error. In desperation, I tried the Microsoft Edge web browser. Amazingly, this time I managed to log in.
I now had to download the latest version of the software, uninstall my old version, install the new one, wait for a new serial number, enter that… anyway, eventually the installation went again successfully.
Look, I like Delphi. I’ve used its Object Pascal language ever since Delphi was first launched and before that I used its predecessor, Turbo Pascal, since the early 1980s. But, come on, chaps, this download-and-install palaver is nuts. You provide a free edition of Delphi (good) but you make it bomb out after a year and then you go to some lengths to make the reinstallation as painful as possible. It’s a positive incitement to use the open source Object Pascal alternative, Lazarus instead: https://www.lazarus-ide.org/index.php?page=downloads
The history of the free edition of Delphi is an odd one. From the launch of Delphi 1, way back in 1995, I was the Delphi columnist for PC Plus Magazine in the UK. I wrote Delphi programming columns every month for over ten years and readers could follow along using the free copy of Delphi that its developers, Borland, supplied on the PC Plus cover disk. Whenever a new version of Delphi was released, we had a new free copy on the cover disk.
Then the Borland programming team split away to form a company called CodeGear and they were quickly bought up by another company called Embarcadero. Sadly, Embarcadero didn’t seem to understand the importance of providing a free edition. I asked for one so that I could teach a course on Delphi. And for the first time ever, my request was refused. So I based that course on Lazarus.
In the meantime, Microsoft had decided that it would be a jolly good idea to provide free copies of its IDE, Visual Studio, to anyone who wanted one. Visual Studio doesn’t support Pascal as standard but it does support C# – a very good language that was created by Anders Hejlsberg, the man who had previously been responsible for Delphi before Borland made the unfortunate error or losing him and other members of his team to Microsoft.
Now let me be ruthlessly honest. Delphi/RADStudio is a fine programming environment. But it’s not as good as Visual Studio. Visual Studio is simply the best. Embarcadero must have noticed that the Delphi market was dwindling while C# was very much in the ascendant. Rather (too) late in the day they decided to release a free Community Edition of Delphi. OK, so better late than never.
But then they go and implement this incredibly infuriating expiry, download and update mechanism. This doesn’t stop you carrying on programming with Delphi after one year is up. All it does, is make you very annoyed with the software and the company for making the update process as inscrutable and infuriating as possible. I have no idea why they do that. It’s bad PR, it’s bad marketing, it’s just really bloody annoying.
OK, so I finally have Delphi reinstalled. But I now feel so ill disposed towards it that I think I’ll spend the rest of the day programming in Visual Studio!
Tuesday, 1 September 2020
As a passionate adventure game player and programmer, from the 1980s onwards, I’ve decided that the time has come to help other programmers embark on the noble quest of developing retro-style adventure games. I’ve already taught a course and written a book (available on Amazon US, Amazon UK and worldwide) on writing adventure games in C#. But if you’ve never written a game before you might still find it hard to implement all the features needed. Wouldn’t it be great if someone had already written a library of classes that encapsulated all the essential behaviour needed for a game – a parser to interpret text commands, Rooms to create a map, Treasures to create objects, actions to let the player look at objects, take, and drop them or put one object inside another one?
Welcome to BIFF!
BIFF is short for The Bitwise Interactive Fiction Framework. I’ve spent much of the last year writing this framework in Java and now I’m starting work on translating it into C#. The Java version of BIFF is currently more complete – it can handle reasonably complicated commands such as “Put the small golden egg into the big carved wooden box” or “Unlock the treasure chest with the magic brass key”. I will make BIFF for Java freely available later in the year.
Since many people have already read my C’# book or followed my course, I decided that, rather than wait until the C# release of BIFF has all the features in the Java version, I would release BIFF for C# in incremental stages so that existing readers and students can carry on developing their games using the new features. This necessarily means that the early releases will always be substantially incomplete. However, if you want to deepen your understanding of game programming, this is a great opportunity for you to try to modify the latest release by adding on additional features. You are free to modify BIFF as required as long as you leave my copyright notice in the comments of the source code.
To download the code of my C# adventure game book (whether or not you’ve actually bought it!) as well as the current release of BIFF for C#, juts sign up to my mailing list at www.bitwisebooks.com. Meanwhile, here is a short introduction to BIFF…
Friday, 28 August 2020
If you’ve read my book or followed my course on adventure game programming in C#, you will already know how to create a map of linked rooms which the player can wander around in order to take or drop treasures. You will be able to communicate with the game using simple English language commands such as “Take the sword” or “Put the coin into the box”.
But what happens if there are several swords in the current location? In that case, when the player enters: “Take the sword” you want to game to reply:
“So you mean the gold sword, the silver sword or the Elvish sword?”
And when there are multiple coins boxes here, the player should be able to enter:
“Put the small silver coin into the big carved wooden box.”
In order to do that, we need adjectives – “big, small, gold, silver, carved, wooden” and so on. To implement that I’ve begun to extend the code that was supplied with my book. My aim is to create a reusable game framework of ready-to-run classes that you will be able to use to program your own games. This code is in its very early stages at the moment. The main new feature is the addition of adjectives to the parser. I have not yet defined properties to match those adjectives for the treasures. That is, while you can say “take wooden box”, the game doesn’t yet check if the box you want to take really is wooden. I’ll add that in a future update.
The game framework is called The Bitwise Interactive Fiction Framework (BIFF) for C#. I’ll also shortly be releasing a version of BIFF for Java. To keep up to date with developments and download the source code for BIFF (and for my any of my books and YouTube tutorials), just sign up to our mailing list on: www.bitwisebooks.com.
Saturday, 8 August 2020
In my recent review of the screencasting suite, Camtasia 2020, I said that “The latest release of Camtasia is less focussed on adding big new features than making the existing features easier to use”. Since writing that review I’ve become aware of one feature that makes Camtasia harder to use – well, for long-time Camtasia users at any rate. Because the new release no longer supports old Camtasia file formats. That means that if you made some recordings a few years ago and you want to load and edit them with Camtasia 2020, in all probability you won’t be able to do so.
Put simply, Camtasia 2020 no longer supports older Camtasia project files (with the extension .camproj) nor screen recording files (ending .camrec). I Googled for help on this and the only solution I found (in the Techsmith forums) was to use Camtasia 2019 to convert .camproj files and then load those into Camtasia 2020. But even if you do that, the individual clips (.camrec files) are invalid so in effect the conversion fails. I contacted Techsmith to see if the company had a solution to this problem. This is what the Camtasia project manager replied:
“You are correct that both camproj (projects) and camrec (recording) formats were retired in 2020. We replaced both formats many years ago (I believe TREC was introduced sometime in 2014 in version 8 of Camtasia) to introduce cross-platform project and recording support between Windows and Mac. You are also correct that the solution for opening camproj files is to open them in 2019 and then convert them to the tscproj format. Unfortunately, there was no easy or fast method of handling this for camrec to TREC format. We investigated to see if this would be worth the investment, but only a very small percentage of imports (something like 0.05%) were camrec format.
“Probably the easiest workflow for getting these older videos into 2020 will be to install Camtasia 2019, which will install the camrec shell extension. With this, you can right-click on camrec files in the Windows File Explorer and extract the video as an AVI. You can then bring this video into Camtasia 2020 (note that this will not include any cursor data though; if you need the cursor, you will have to produce the video from Camtasia instead).”
Friday, 31 July 2020
Monday, 8 June 2020
|These are some of the downloadable templates that can be used when starting a new project|
|Here I'm editing on a dual-monitor PC. I've detached the timeline so that I can use it fullscreen (left) on my 2nd monitor|
|The Recording toolbar|
Tuesday, 14 April 2020
Monday, 9 March 2020
Wednesday, 4 March 2020
To watch this series of videos from the start, go to the playlist: https://www.youtube.com/playlist?list=PLZHx5heVfgEtHeS6O2ePOkr3f-agvPxi6
Friday, 28 February 2020
Delphi was the successor to Borland’s hugely successful DOS-based Turbo Pascal and its less successful Windows Pascal (even I can hardly remember that – I think it was called ‘Borland Pascal With Objects’ or something equally unmemorable). At the time, Delphi was, in my view, far the best visual (drag-and-drop, design-and-code) environment for Windows. Its only real competition was Microsoft’s Visual Basic. The trouble is that no matter how visual you make Basic, it’s still Basic. Whereas Delphi used a very nice version of Pascal that had a reasonably modular unit-based system, good Object Orientation and also had low-level features for anyone who might be missing C.
Anyway, Delphi is still going strong. It’s owned by Embarcadero these days and you can get a free copy here: https://www.embarcadero.com/products/delphi/starter/free-download
To celebrate Delphi’s 25th birthday, I’ve just released a book for new or intermediate Delphi programmers. It’s called The Little Book Of Delphi and it’s available in paperback or as a Kindle eBook from Amazon.
The book covers:
- Fundamentals of Delphi
- The Object Pascal language
- Object Orientation
- Variables, Types, Constants
- Operators and Tests
- for loops and while loops
- Procedures and Functions
- Parameters and Arguments
- Arrays and Lists
- String Operations
- Case Statements
- User-defined Types
- Constructors and Methods
- Creating and Freeing Objects
- Inheritance and Encapsulation
- Virtual and Overridden Methods
- Text files and Binary files
- Streaming and Serialization
- Errors and Exceptions
- ...and much more
Here are the links:
Tuesday, 25 February 2020
In the interview, I discuss everything from The Golden Wombat Of Destiny – the game I wrote back in the '80s – to my recent book, The Little Book Of Adventure Game Programming. There are numerous other articles in the magazine that should be of interest to anyone interested in retro/classic ‘Interactive Fiction’ games.
Monday, 24 February 2020
Tuesday, 28 January 2020
I've recently started a YouTube series on programming games in Java. This complements my book, 'The Little Book Of Adventure Game Programming' which uses C# as the primary language.
Anyway, here's the latest video.
Tuesday, 7 January 2020
Memory leaks are some of the trickiest things to track down when you are writing programs. Somewhere you allocate a chunk of memory and then later on, that memory isn’t freed when it’s no longer needed. Small memory leaks might not be a problem but when a program allocates huge amounts of memory, you can run into trouble. In a long programming career, I’ve seen people spend weeks trying to track down obscure memory problems. It’s usually quite easy to track down problems that cause your program to crash every 10 minutes. But once every ten days? Not so easy at all.
Of course, in modern garbage collected languages like C# and Java, memory leaks are no longer a problem – or are they? It’s certainly the case that garbage collection makes life a lot easier. In general, you don’t have to bother about freeing up memory – it’s done automatically. However, you can still get problems if you call system APIs or libraries written in another language where memory is not managed.
If you have (or think you have) a memory leak problem, then a tool to track down the source of the leak might be useful. One such tool is Deleaker. This comes with a 14 day trial period where you can use the full functionality of the tool. Deleaker helps you find and fix memory leaks in your C, C++ or Object Pascal programs developed using either Microsoft’s Visual Studio or Embarcadero’s RAD Studio/Delphi.
When installed, Deleaker can either be run from a menu item in your chosen IDE or it can be run as a standalone application so that it is available on a PC without the IDE installed. The licence allows a single user to run Deleaker on multiple PCs which is convenient if you need to use it both on your desktop computer and also on a laptop.
|Here I have docked Deleaker into the Delphi IDE. You can keep its window ‘free-floating’ if you prefer.|
We tried it out on some very simple programs with a couple of memory leaks and it worked great. At the end of the run, Deleaker will identify the leaks and indicate the source of the leak. However, it doesn’t (and can’t) tell you where you should have freed the memory. But it’s a good start and with some extra coding diagnostics, you should be able to track down memory leaks reasonably easily.
In my experience, though, simple memory leaks are not the huge problem that they are sometimes made out to be. First, from my own experience early on in my programming career seeing other programmers get in real deep trouble, I’ve been absolutely fanatical about memory allocation. Because of that I’ve never had a serious problem. The other memory problem that Deleaker can’t help with is where you have accidentally reused some freed memory: you have two pointers to the same memory address and you’ve forgotten about the second pointer when you called free on the first. These can be very tricky indeed to track down.
But where Deleaker does score is keeping track of system resources such as GDI device contexts, handles and the like. It is surprisingly easy to lose track of these because they tend to exist for a long time in the program and the effects of not freeing handles are not obvious – you don’t see memory creeping up and your program slowing down dramatically until the whole of Windows starts to seize up.
|Here Deleaker has produced a report of some leaks in a Visual Studio C project.|
At the end of the day, while you have been careful about memory allocation and resource tracking (and in my case paranoid about it) – how you do you know that you have no memory leaks? Without something like Deleaker you won’t - and here Deleaker does shine in acting as a quality check keeping track of memory and non-obvious system resources: it’s always a lot cheaper to fix bugs before releasing software and any tool such as Deleaker that helps produce bug free software is well worth the money.
For this review Dermot Hogan reviewed Deleaker for Visual Studio (Huw Collingbourne tested it with Delphi)