The Physical Structure of C++ Programs
Saturday June 15, 2013 18:07:35

Every programmer knows about the logical structure of the code they write, but most aren't even aware about the concept of “physical structure” in program code.

“Physical structure” problems only arise when programming languages have to use processor to include other files. The only example of this that really matters is C and C++, where the #include directive is necessary to make use of code in another compilation unit or library. Other modern languages, such as C# or Java, don't have these issues.

This article on mitigating problems with the physical structure of C++ programs is one of the best reads on the topic I've ever encountered, and is recommended if you program in C or C++.

I started work on Macaroni for C++ years ago because I was sick of copying and pasting to create header files, wasting LOC on include guards, or other grostesque preprocessor crap, and that was before I had to spend time adding boilerplate for features similar to reflection. At the time I was starting to prefer writing C++ to C#, buthaving to define so much stuff for the processor took all the fun out of it.

These days, Macaroni is finished enough that I feel confident using it on big projects.C++ still takes longer to write than Java or C#, but more because the language demands that I, as a coder, know what I'm doing and state things precisely. The benefit is the resulting code is usually more expressive and readable than Java or C# and has a staggering amount of portability.

One issue I'm now seeing with Macaroni is because it enables writing C++ code faster and more succinctly, it makes it easier to write it like C# and ignore the resulting physical structure of the generated source. This could lead to projects that resemble balls of mud and have longer compile times.

Thankfully, Macaroni also makes it easier to write well physically structured C++ code since it has tricks like the “~hidden” keyword to hide class functions in the “Cpp-only” version of the class definition, as well as the ~block keyword which makes it easy to add helper functions to a class in an anonymous namespace. Today, Macaroni makes a good effort to use forward declarations instead of #include directives if it detects the later is unnecessary, but in the future I'd like to also generate its library-wide config header files with precompiled header support for appropriate platforms.

The problem of code's physical structure is something that makes C++ more difficult to use compared to it's newer native language rivals. I'd I'd love it if Macaroni could alleviate this and make C++ a more attractive choice for non-believers.



Sublime Text user settings
Thursday May 23, 2013 04:30:07

Sublime Text is my favorite text editor of all time. Here's what my user settings file looks like:

{
	"caret_style": "phase",
	"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
	"ensure_newline_at_eof_on_save": true,
	"fade_fold_buttons": false,
	"flatland_sidebar_tree_small": true,
	"flatland_square_tabs": true,
	"font_face": "Inconsolata",
	"font_size": 12,
	"gutter": true,
	"highlight_line": true,
	"line_padding_bottom": 0,
	"line_padding_top": 0,
	"rulers":
	[
		80,
		120,
		160
	],
	"save_on_focus_lost": true,
	"sentinel": true,
	"tab_size": 4,
	"theme": "Flatland Dark.sublime-theme",
	"translate_tabs_to_spaces": true,
	"trim_trailing_white_space_on_save": true
}

These settings standardize white space, cutting back on merge conflicts. It establishes rulers to help keep code down to 80 columns (yeah it's the year 2013 and we have widescreen monitors blah blah blah but an 80 column limit just looks better. It also makes it easier to view two panels of text at once). I'm more iffy on “save_on_focus_lost”- for most projects I enjoy it, but sometimes it can cause needless recompilation in C++ (this is solved in Macaroni, as it checks to see if the destination file is different before replacing it).

Updated on 2013-11-27: I didn't Sublime could look any prettier, but changed my mind after being introduce to the Flatlands theme by my coworkers. The big change with this theme is that the folder navigation pane gets blue icons. The best part about it is that you can make both the new icons and text smaller, making it easier to navigate large projects.

I also began using the Inconsolata font which looks only a little bit better than the default font on Mac's but is gorgeous on Windows.



Retron 5 will play GBA games, output in HDMI
Sunday March 24, 2013 14:49:20

The past half decade has offered a plethora of “retro” systems designed to be clones of the SNES, NES, and Genesis. Many of these have been two or three in ones, such as the Retro Duo or Retron 3. However, most have been plagued with less than perfect game compatibility and build quality issues. Additionally, none really offered anything new, other than crappy clone controllers which felt worse than the originals.

The recently announced Retron 5 looks to fix that with a number of features unique to the retro system space, such as a wireless Bluetooth (instead of flaky infrared) controllers in addition to original controls and the ability to remap buttons for any controller to any game (this is a feat Nintendo only recently remembered how to do). It also will output to HDMI and includes graphics and sound filters in an attempt to make old games not look like garbage on new TVs.

Most importantly though is it's ability to play Gameboy Advance games! I own close to 50 GBA games so it's nice to finally see someone make a decent alternative to the Gameboy Player, which while a competent product looks terrible on HDTVs and doesn't allow for configurable controls. This last point was alleviated somewhat by Hori's Gameboy Player controller, until mine broke (one of three times I've ever had a controller break). I thankfully had bought a backup years ago for $20, but to this day am afraid to open it since they now cost $200 on e-bay.

Now the only question is whether or not this thing will play Mother 3…



Using Boost Build on the Dreamcast
Sunday March 10, 2013 20:28:03

I'm really addicted to Boost Build. So when I started getting back into Dreamcast programming I worried that I'd need to create Makefiles in parallel with Jamfiles.

However, it turns out teaching Boost Build to use a new variant of GCC is ridiculously easy! You just need to edit site-config.jam and give it the path to the new compiler. However, there's some extra complications if you're building a Windows project on the Dreamcast, since Boost Build will add flags and do things that only make sense for Windows libraries. In order to get around that, I had to make a Python script that would weed out the extra arguments and call the KOS GCC compiler without them.

In the end I was able to get to where I could cross-compile functioning bjam files that worked in Windows on the Dreamcast by simply adding “–toolset=gcc-dreamcast” to the command line.

If you'd like to use Boost Build too, I've put the results of my work up on GitHub, along with instructions on how to get started.

Notice that this enables all the C++11 features supported so far by the GNU compiler, which means “auto” can now be used in a Dreamcast program. Pretty cool, right?





<---2013-12-07 20:06:00 history 2013-03-10 18:14:00--->



-All material © 2007 Tim Simpson unless otherwise noted-