A little while back, we were talking about utilizing compiler warnings as first step to make our C code less error-prone and increase its general stability and quality. We know now that the C compiler itself can help us here, but we also saw that there’s a limit to it. While it warns us about the most obvious mistakes and suspicious code constructs, it will leave us hanging when things get a bit more complex.
But once again, that doesn’t mean compiler warnings are useless, we simply need to see them for what they are: a first step. So today we are going to take the next step, and have a look at some other common static code analysis tools that can give us more insight about our code.
You may think that voluntarily choosing C as primary language in this day and age might seem nostalgic or anachronistic, but preach and oxidate all you want: C won’t be going anywhere. So let’s make use of the tools we have available that help us write better code, and to defy the pitfalls C is infamous for. And the general concept of static code analysis is universal. After all, many times a bug or other issue isn’t necessarily caused by the language, but rather some general flaw in the code’s logic.
Continue reading “Warnings On Steroids – Static Code Analysis Tools”
Mankind’s fascination with airplanes is unbroken. Whether you’re outside with your camera, getting an actual glimpse of the aircraft, or sitting at home with your RTL-SDR dongle and have a look at them from a distance, tracking them is a fun pastime activity. Provided, of course, that you are living close by an airport or in an area with high enough air traffic. If not, well there’s always real-time tracking online to fall back to, and as [geomatics] will show you, you can build your own live flight tracking system with a few lines of Python.
As it’s usually the case with Python, a lot of functionality is implemented and readily available from external modules, which lets you focus on the actual application without having to worry too much about the details. Similarly, plenty of data can be requested from all sorts of publicly accessible APIs nowadays. If you are looking for a simple-enough example to get into both subjects with a real-world application, [geomatics]’ flight tracker uses cartopy to create a map using Open Street Map data, and retrieves the flight information from ADS-B Exchange‘s public API.
We have seen ADS-B Exchange mentioned a few times before, for example with this ESP8266 based plane spotter and its successor. And if you’re more curious about the air traffic in your direct surroundings, it’s probably time for a DVB USB dongle.
Dividing by zero — the fundamental no-can-do of arithmetic. It is somewhat surrounded by mystery, and is a constant source for internet humor, whether it involves exploding microcontrollers, the collapse of the universe, or crashing your own world by having Siri tell you that you have no friends.
It’s also one of the few things
gcc will warn you about by default, which caused a rather vivid discussion with interesting insights when I recently wrote about compiler warnings. And if you’re running a modern operating system, it might even send you a signal that something’s gone wrong and let you handle it in your code. Dividing by zero is more than theoretical, and serves as a great introduction to signals, so let’s have a closer look at it.
Chances are, the first time you heard about division itself back in elementary school, it was taught that dividing by zero is strictly forbidden — and obviously you didn’t want your teacher call the cops on you, so you obeyed and refrained from it. But as with many other things in life, the older you get, the less restrictive they become, and dividing by zero eventually turned from forbidden into simply being impossible and yielding an undefined result.
And indeed, if a = b/0, it would mean in reverse that a×0 = b. If b itself was zero, the equation would be true for every single number there is, making it impossible to define a concrete value for a. And if b was any other value, no single value multiplied by zero could result in anything non-zero. Once we move into the realms of calculus, we will learn that infinity appears to be the answer, but that’s in the end just replacing one abstract, mind-boggling concept with another one. And it won’t answer one question: how does all this play out in a processor? Continue reading “Creating Black Holes: Division By Zero In Practice”
If there’s one thing C is known and (in)famous for, it’s the ease of shooting yourself in the foot with it. And there’s indeed no denying that the freedom C offers comes with the price of making it our own responsibility to tame and keep the language under control. On the bright side, since the language’s flaws are so well known, we have a wide selection of tools available that help us to eliminate the most common problems and blunders that could come back to bite us further down the road. The catch is, we have to really want it ourselves, and actively listen to what the tools have to say.
We often look at this from a security point of view and focus on exploitable vulnerabilities, which you may not see as valid threat or something you need to worry about in your project. And you are probably right with that, not every flaw in your code will lead to attackers taking over your network or burning down your house, the far more likely consequences are a lot more mundane and boring. But that doesn’t mean you shouldn’t care about them.
Buggy, unreliable software is the number one cause for violence against computers, and whether you like it or not, people will judge you by your code quality. Just because Linus Torvalds wants to get off Santa’s naughty list, doesn’t mean the technical field will suddenly become less critical or loses its hostility, and in a time where it’s never been easier to share your work with the world, reliable, high quality code will prevail and make you stand out from the masses.
Continue reading “Warnings Are Your Friend – A Code Quality Primer”
Telling time by using the current position of the sun is nothing revolutionary — though it probably was quite the “life hack” back in ancient times, we can assume. On the other hand, showing time by using the current position of the sun is what inspired [Rich Nelson] to create the Day Cycle Clock, a color changing light box of the Philadelphia skyline, simulating a full day and night cycle in real time — servo-controlled sun and moon included.
At its core, the clock uses an Arduino with a real-time clock module, and the TimeLord library to determine the sunrise and sunset times, as well as the current moon phase, based on a given location. The sun and moon are displayed on a 1.44″ LCD which doubles as actual digital clock in case you need a more accurate time telling after all. [Rich] generally went out of his way with planning and attention to detail in this project, as you can see in the linked video, resulting in an impressively clean build surely worthy as gift to his brother. And if you want to build one for yourself, both the Arduino source code and all the mechanical parts are available on GitHub.
An interesting next iteration could be adding internet connectivity to get the current weather situation mixed into the light behavior — not that it would be the first time we’d see weather represented by light. And of course, simulating the northern lights is also always an option.
Continue reading “Decorative Light Box Lets You Guess The Time”
Java isn’t everyone’s cup of tea. With all its boilerplate and overhead, you’re almost always better off with a proper IDE that handles everything under the hood for you. However, if you learn a new language, you don’t really want to be bothered setting up a clunky and complex IDE. If only you could use a simple, standard Windows program that you are most likely already familiar with. This wish led [RubbaBoy] to create the MSPaintIDE, a Java development environment that let’s you write your code in — yes — MS Paint.
If you’re thinking now that you will end up writing your program with MS Paint’s text tool and create a regular image file from it — then you are right. Once set up, MSPaintIDE will compile all your PNG source files into a regular Java JAR file. And yes, it has syntax highlighting and a dark theme. [RubbaBoy] uses a custom-made OCR to transform the image content into text files and wraps it all into few-button-click environment — including git integration. You can see a demonstration of it in the video after the break, and find the source code on GitHub.
One has to truly admire how far [RubbaBoy] went, considering the tongue-in-cheek nature of this project. And all joking aside, if you’re interested in OCR, this might just be simple enough to begin with. Or you could expand it with some text to speech functionality.
Continue reading “A Whole Other Kind Of Graphical Programming”
In case you happen to have an ocean nearby, you’re probably familiar with its rising and falling tides. And if mudflat hiking is a thing in your area, you’re also aware of the importance of good timing and knowing when the water will be on its way back. Tide clocks will help you to be prepared, and they are a fun alternative to your usual clock projects. If you’re looking for a starting point, [rabbitcreek] put together an Arduino-based tide clock kit for educational purposes.
If you feel like you’re experiencing some déjà vu here, this indeed isn’t [rabbitcreek]’s first tide clock project. But unlike his prior stationary clock, he has now created a small and portable, coin-cell version to take with you out on the sea. And what shape would better fit than a 3D printed moon — unfortunately the current design doesn’t offer much waterproofing.
For the underlying tide calculation itself, [rabbitcreek] uses just like in his previous project [Luke Miller]’s location-based library for the ubiquitous DS1307 and DS3213 real-time clocks. Of course, if you also want to keep track of other events on your clock, why not set up calendar events for the next rising tide?