programming
Best Practices For Programming, Part 1
originally posted: 2024-09-18 15:23:00
Over my decades of programming I've invented a couple of best practices recommendations. I'll describe two of them in this post.
I haven't seen either of these independently invented by anybody, much less discovering that they were long-standing wisdom. I've given lightning talks on the first one at Python conventions once or twice; the best feedback I got was from Raymond Hettinger, who if I recall correctly said "I think you're wrong but I don't have any counter-examples." ...
Continue reading Best Practices For Programming, Part 1
Bound Inner Classes For Python
originally posted: 2013-12-24 09:39:02
(This blog entry is my contribution to the 2013 Python Advent Calendar. I'm the entry for December 25th,; however, due to the time zone difference between here and Japan, I'm posting it during what is to me the morning of the 24th. Merry Christmas!)
In Python, something magic happens when you put a function inside a class. If you access that function through an instance of the class, you don't simply get the function back. Instead you get a new object we call...
Continue reading Bound Inner Classes For Python
Quick One-Positional-Argument Function Currying In Python
originally posted: 2011-11-01 14:48:12
Function "currying" in Python means pre-adding arguments to a function. If you have a function that takes two arguments, you can create a new function from it that only takes one, if you can somehow automatically set the second parameter. (My understanding is that the term "curry" isn't totally correct here; the correct mathematical term would be "partial application". Calling this "currying" is but one of the Python...
Continue reading Quick One-Positional-Argument Function Currying In Python
Floating-Point Numbers Are Precise!
originally posted: 2010-05-22 09:47:31(What they lack is accuracy!)
There's a great deal of misunderstanding about floating-point numbers. Better men than I have tried to dispell the haze of confusion that surrounds them. But let me make a start.
One source of confusion is when people think of floating-point numbers as approximations. That's muddy thinking. A floating-point number is not approximately anything; it's an exact value. The problem is that it may not be the value you wanted.
If I...
Continue reading Floating-Point Numbers Are Precise!
How To Use Mercurial For Local Source Code Management With A Public Subversion Server
originally posted: 2007-01-05 17:25:30I'm working on contributing some patches to Python. According to the Python patch submission guidelines:
If you're like most people, you don't have Subversion checkin privileges for Python. That means you're...
- We like unified diffs. We grudgingly accept contextual diffs. Straight ("ed-style") diffs are right out!
- If you send diffs for multiple files, concatenate all the diffs in a single text file.
- We appreciate it if you send patches relative to the current svn tree.
Continue reading How To Use Mercurial For Local Source Code Management With A Public Subversion Server
64-Bit Color... And 16-Bit Floats
originally posted: 2006-01-24 21:37:38Have you seen the HDR rendering in Half-Life 2: Lost Coast? That is possible because of the next big thing in graphics: going from 32-bit color to 64-bit color. But this revolution in color isn't as simple as just making everything twice as big.
32-bit color uses four 8-bit integers to represent red, green, blue, and alpha. (Alpha means whatever you need it to mean; most commonly it's used for opacity.) Thus, each of the four values can go from 0 to...
Continue reading 64-Bit Color... And 16-Bit Floats
Shrinky-Dink Python
originally posted: 2006-01-11 22:25:08About eighteen months ago, I realized that my plan for level creation for my game was just not going to be feasible. I'd planned to write all levels as FORTH scripts, and... well, not only is that a totally un-visual way of designing fun levels, but I was constantly tripping over the programming differences between FORTH and C (between FORTH and every other language under the sun, really). I'd wanted to use Python for scripting in my game, but the runtime was just too big. The Python...
Continue reading Shrinky-Dink Python
A Magical C++ State Machine Implementation
originally posted: 2005-06-14 13:54:22And by magical I mean uses heavy C++ wizardry and probably shouldn't be used. I am abandoning this approach in the interests of code maintainability; this code is clever, and these days whenever I write something clever I feel ashamed.
Here's the source code, which compiles under Windows, GCC 2 and GCC 3 under Linux, and GCC 4 on Mac OS X:
// Proof-of-concept for a magical approach to state machines in C++ // Written by Larry Hastings,...
Continue reading A Magical C++ State Machine Implementation
The D Programming Language, and my video game engine
originally posted: 2005-04-13 19:20:31I've been writing a video game for Windows for more than two years now. At its heart is a game engine of my own fiendish design. I say "fiendish" because it's, well, awful. I plan on finishing my current game, then doing another game with this source tree. After that, if I am any sort of even mild success at this, I shall throw away this source tree and begin anew—which is something I'm quite looking forward to.
In my current engine, I wrote nearly everything myself. I feel in...
Continue reading The D Programming Language, and my video game engine