Debugging Vs Printing

We’ll admit it. We have access to great debugging tools and, yes, sometimes they are invaluable. But most of the time, we’ll just throw a few print statements in whatever program we’re running to better understand what’s going on inside of it. [Loop Invariant] wants to point out to us that there are things a proper debugger can do that you can’t do with print statements.

So what are these magical things? Well, some of them depend on the debugger, of course. But, in general, debuggers will catch exceptions when they occur. That can be a big help, especially if you have a lot of them and don’t want to write print statements on every one. Semi-related is the fact that when a debugger stops for an exception or even a breakpoint, you can walk the call stack to see the flow of code before you got there.

In fact, some debuggers can back step, although not all of them do that. Another advantage is that you can evaluate expressions on the fly. Even better, you should be able to alter program flow, jumping over some code, for example.

So we get it. There is more to debugging than just crude print statements. Then again, there are plenty of Python libraries to make debug printing nicer (including IceCream). Or write your own debugger. If gdb’s user interface puts you off, there are alternatives.

Bare Metal STM32: The Various Real Time Clock Flavors

Keeping track of time is essential, even for microcontrollers, which is why a real-time clock (RTC) peripheral is a common feature in MCUs. In the case of the STM32 family there are three varieties of RTC peripherals, with the newest two creatively called ‘RTC2′ and RTC3’, to contrast them from the very basic and barebones RTC that debuted with the STM32F1 series.

Commonly experienced in the ubiquitous and often cloned STM32F103 MCU, this ‘RTC1’ features little more than a basic 32-bit counter alongside an alarm feature and a collection of battery-backed registers that requires you to do all of the heavy lifting of time and date keeping yourself. This is quite a contrast with the two rather similar successor RTC peripherals, which seem to insist on doing everything possible themselves – except offer you that basic counter – including giving you a full-blown calendar and today’s time with consideration for 12/24 hour format, DST and much more.

With such a wide gulf between RTC1 and its successors, this raises the question of how to best approach these from a low-level perspective.

Continue reading “Bare Metal STM32: The Various Real Time Clock Flavors”

No Plans For The Weekend? Learn Raytracing!

Weekends can be busy for a lot of us, but sometimes you have one gloriously free and full of possibilities. If that’s you, you might consider taking a gander at [Peter Shirley]’s e-book “Learning Raytracing in One Weekend”.

This gradient is the first image that the book talks you through producing. It ends with the spheres.

This is very much a zero-to-hero kind of class: it starts out defining the PPM image format, which is easy to create and manipulate using nearly any language. The book uses C++, but as [Peter] points out in the introduction, you don’t have to follow along in that language; there won’t be anything unique to C++ you couldn’t implement in your language of choice.

There are many types of ray tracers. Technically, what you should end up with after the weekend ends is a path tracer. You won’t be replacing the Blender Cycles renderer with your weekend’s work, but you get some nice images and a place to build from. [Peter] manages to cram a lot of topics into a weekend, including diffuse materials, metals, dialectrics, diffraction, and camera classes with simple lens effects.

If you find yourself with slightly more time, [Peter] has you covered. He’s also released books on “Raytracing: The Next Week.” If you have a lot more time, then check out his third book, “Raytracing: The Rest of Your Life.”

This weekend e-book shows that ray-tracing doesn’t have to be the darkest of occult sciences; it doesn’t need oodles of hardware, either. Even an Arduino can do it..

Bootstrapping Android Development: A Survival Guide

Developing Android applications seems like it should be fairly straightforward if you believe the glossy marketing by Google and others. It’s certainly possible to just follow the well-trodden path, use existing templates and example code – or even use one of those WYSIWYG app generators – to create something passable that should work okay for a range of common applications. That’s a far cry from learning general Android development, of course.

The process has changed somewhat over the years, especially with the big move from the Eclipse-based IDE with the Android Development Tools (ADT) plugin, to today’s Jetbrains IntelliJ IDEA-based Android Studio. It’s fortunately still possible to download just the command-line tools to obtain the SDK components without needing the Google-blessed IDE. Using the CLI tools it’s not only possible to use your preferred code editor, but also integrate with IDEs that provide an alternate Android development path, such as Qt with its Qt Creator IDE.

Continue reading “Bootstrapping Android Development: A Survival Guide”

Screenshot of Lazarus IDE on MacOS Ventura

The Case For Pascal, 55 Years On

The first version of Pascal was released by the prolific [Niklaus Wirth] back in 1970. That’s 55 years ago, an eternity in the world of computing. Does anyone still use Pascal in 2025? Quite a few people as it turns out, and [Huw Collingbourne] makes the case why you might want to be one of them in a video embedded below.

In all fairness, when [Huw] says “Pascal” he isn’t isn’t talking about the tiny language [Wirth] wrote back when the Apollo Program was a going concern. He’s talking about Object Pascal, as either Free Pascal or Delphi– which he points out are regularly the tenth most popular of all programming languages. (Index.dev claims that it has climbed up to number nine this year, just behind Go.) As a professional move, it might not be the most obvious niche but it might not be career suicide either. That’s not his whole argument, but it’s required to address the criticism that “nobody uses Pascal anymore”.

Pascal, quite simply, can make you a better programmer. That, as [Huw] points out, was an explicit goal of the language. Before Python took over the education world, two generations of high school students learned Pascal. Pascal’s strong typing and strict rules for declaration taught those kids good habits that hopefully carried over to other languages. It might help you, too.

For experienced programmers, Pascal is still a reasonable choice for cross-platform development. Free Pascal (and the Lazarus IDE) brings the graphical, drag-and-drop ease that once made Delphi rule the Windows roost to any modern platform. (And Delphi, a commercial Pascal product, is apparently still around.) Free Pascal lets you code on Linux or Mac, and deploy on Windows, or vice-versa. While you could do that on Python, Pascal gets you a lot closer to the metal than Python ever could.

Sure, it’s a modern object-oriented language now, with objects and classes and hierarchies and all that jazz– but you don’t always have to use them. If you want to go low-level and write your Pascal like it’s 1985, you can. It’s like being able to switch into C and manipulate pointers whenever you want.

On some level, perhaps the answer to the question “Why use Pascal in 2025” is simply– why not? It’s likely that the language can do what you want, if you take the time to learn how. You can even use it on an Arduino if you so wish– or go bare metal on the Raspberry Pi.

Thanks to [Stephen Walters] for the tip.

Continue reading “The Case For Pascal, 55 Years On”

CAD, From Scratch: MakerCAD

It’s likely that many of you use some form of CAD package, but how many of you have decided you didn’t like the software on offer? [Marcus Wu] did, and instead of griping, he wrote his own CAD software. It’s called MakerCAD, it’s published under an MIT licence, and you can try it yourself.

It’s written in Go, and it’s superficially similar to OpenSCAD in that the interface is through code. The similarity is skin deep though, as it provides the user with constraint solving as described in the video below the break.

As it stands it’s by no means feature complete, but it is now at a point at which it can be evaluated. Simple models can be created and exported as STEP files, so it can be used as a real-world CAD tool.

Whether it will flourish is down to the path it takes and how its community guides it. But we’re pleased to see any new open source projects in this space, which remains overly dominated by proprietary packages. If you try it, write up your experiences, we’d love to see how this develops.

Continue reading “CAD, From Scratch: MakerCAD”

The Shady School

We can understand why shaderacademy.com chose that name over “the shady school,” but whatever they call it, if you are looking to brush up on graphics programming with GPUs, it might be just what you are looking for.

The website offers challenges that task you to draw various 2D and 3D graphics using code in your browser. Of course, this presupposes you have WebGPU enabled in your browser which means no Firefox or Safari. It looks like you can do some exercises without WebGPU, but the cool ones will need you to use a Chrome-style browser.

You can search by level of difficulty, so maybe start with “Intro” and try doing “the fragment shader.” You’ll notice they already provide some code for you along with a bit of explanation. It also shows you a picture of what you should draw and what you really drew. You get a percentage based on the matching. There’s also a visual diff that can show you what’s different about your picture from the reference picture.

We admit that one is pretty simple. Consider moving on to “Easy” with options like “two images blend,” for example. There are problems at every level of difficulty. Although there is a part for compute shaders, none seem to be available yet. Too bad, because that’s what we find most interesting. If you prefer a different approach, there are other tutorials out there.