The pbrain Programming Language

Note: I’m no longer updating this page. Please see the official pbrain page for more information.

The pbrain programming language is an extension I made to the Brainf**k programming language that adds the ability to define and call procedures. If you’re wondering about the asterisks in the name of the programming language, it’s because the name is rather rude. That’s why I decided to use a name for my extension that a good bit tamer. After all, my Mom and my kids still read my site from time to time.

After making a rather simplistic interpreter in C++, I decided to go ahead and make a .NET compiler as well, using C#.

Thanks to rdragon on the Undernet #c++ channel and to Daniel Cristofani for their comments and input.

A Nice IDE

There’s a nice integrated development environment written by Tim Rohlfs that includes support for pbrain. I was delighted when he added support. Go download it, try it out, and let him know how much you like it.

Some pbrain Programs

This is the pbrain program referred to in the comment header of the interpreter source.


[/codesyntax]

This pbrain program initializes a memory location to 65, the ASCII value of the letter ‘A’. It then calls a function for subsequent memory locations to copy the previous location and add one to it. Once a few cells are initialized, it prints all the cells to standard output.

The .NET Compiler

Here is the C# source code for the .NET compiler, which compiles both pbrain and traditional Brainf**k code. It performs some simple optimizations as well:

  • A sequence of + and - instructions will be
    concatenated into one operation sequence, so that a sequence like
    ++++ will add 4 to the current memory location instead of
    adding 1 four times.
  • Likewise, a sequence of > and <
    instructions will be concatenated into one operation sequence, so that
    a sequence like >>>> will move the pointer forward four
    locations rather than 1 location at a time.
  • The null loop, [-], will be compiled to set the
    current memory location to zero, since that is the practical effect of
    the loop anyway. This will allow for efficiently zeroing out a memory
    location whether it holds the value 1 or 10001.

The Interpreter

Here is the C++ source code for the interpreter. If you want to compile it with g++ make sure you get version 3.4 or later so it won’t choke on the wchar_t bits.

I don’t claim that this is a particularly efficient interpreter. I thought of it, designed it, and wrote it one evening/morning between the hours of 9:45 PM and 6:15 AM, in a single session.

This interpreter will also work with traditional Brainf**k code.

Share

Dragsens version 1.4

UPDATE: Download the latest version from the main project page. There is also a version of this utility with a graphical interface that’s easier to use.

It’s time for a new version of the command-line version of the dragsens utility, which allows one to change the mouse sensitivity for detecting mouse drag actions in Windows.

A comment posted by Mark suggested the addition of a parameter that would show the current sensitivity settings. I added a /D parameter which, when provided by itself in the parameter list, will output the current drag sensitivity settings for the X and Y axes:

This new parameter may also be combined with the existing parameters. For example, to display the current sensitivity settings, set the X and Y sensitivity to 20, and then display the new settings, enter dragsens 20 /d on the command line:

I took this opportunity to clean up the help text a little bit, too. Entering dragsens or dragsens /? on the command line will display the following:

You may download the version 1.4 executable here:

http://www.parkscomputing.com/code/dragsens_14.zip
(MD5 hash: 651A73A9D1696E41AACABDCE2C8B4633)

If you’d like to examine or modify the source code or build your own executable rather than relying on the executable above, you may download the Visual Studio 2013 project and source here:

http://www.parkscomputing.com/code/dragsens_14_src.zip
(MD5 hash: E6174040203F220D7F0041481206BBA8)

Please let me know if you encounter any problems or have any questions.

Share

Cabin Fever

Atlanta shut down for a few days as the result of a moderate snowfall. Perhaps you saw something about it on the news. Now, another winter storm is on the way, and this one is supposed to be worse than the last one.

Last time, I made a little “diary” on my Facebook page using pictures I snapped with my phone and apocalyptic-sounding descriptions of my preparations for the oncoming storm. I got so bored sitting in my home office that I put them into a little Youtube video. With apologies to Ken Burns:

Even Bitstrips was co-opted:

There’s no telling what the next storm will produce. Stay tuned.

Share

Windows Version of Dragsens

UPDATE: Download the latest version from the main project page. There is also a console-based version of this utility that’s more suitable for system administrators.

In response to a comment on the previous version of the drag sensitivity utility, I’ve created a new version of the utility that includes a graphical interface and a means of testing the drag settings in the interface.

WinDragSens Interface

This version also maintains all of the command-line parameters of the previous version so that it may still be used from scripts or batch files.

You may download the executable here:

http://www.parkscomputing.com/code/WinDragSens.zip
(MD5 hash: CC1680ED81730AA73F70BCD21F0A6CB1)

If you’d like to examine or modify the source code or build your own executable rather than relying on the executable above, you may download the Visual Studio 2013 project and source here:

http://www.parkscomputing.com/code/WinDragSens_src.zip
(MD5 hash: 3D1AF2688F9560D90CAE8FD266F48915)

Please let me know if you encounter any problems or have any questions.

Share

Updated Version of Dragsens

UPDATE: Download the latest version from the main project page. There is also a version of this utility with a graphical interface that’s easier to use.

I have built a new version of the dragsens utility, which allows one to change the mouse sensitivity for detecting mouse drag actions in Windows.

This new version fulfills a request by Zach to add the capability to set the horizontal and vertical sensitivity independently. This is accomplished through two new command-line parameters, /X and /Y. Specifying just one of these parameters will change the sensitivity in only that axis:

It is also possible to provide both parameters at once:

Providing only a number on the command line will change both the horizontal and vertical axes to the same number of pixels.

You may download the version 1.3 executable here:

http://www.parkscomputing.com/code/dragsens_13.zip
(MD5 hash: C86AC30E3A07D6D063C3F710CE65C772)

If you’d like to examine or modify the source code or build your own executable rather than relying on the executable above, you may download the Visual Studio 2012 project and source here:

http://www.parkscomputing.com/code/dragsens_13_src.zip
(MD5 hash: B510F29CFDF1F8AFCA8857ACEB7870D8)

Please let me know if you encounter any problems or have any questions.

Share

My Life With Programming Languages

A language that doesn’t affect the way you think about programming, is not worth knowing. — Alan Perlis

My first programming language was Basic on a TI-99/4A. Contra Dijkstra, I don’t think it did me too much harm. Of course, I did eventually “outgrow” that language.

Just now I was pondering my progression through various programming languages and paradigms over the 28 years that I’ve been playing around with computers (almost 23 professionally as of this writing). My attitudes toward several of the languages I’ve used over that time looked something like the following:

Continue reading ‘My Life With Programming Languages’ »

Share

Facebook and Your Grandchildren

I think most people, at some point, have tried to keep a diary. Most people also gave up after a few days. Yet Facebook is like a diary that you’ll let your 900 closest friends read, and you have to try not to constantly write stuff on your page.

That realization made me wonder what it would be like if my grandparents had had Facebook pages in their teenage years. I would love to be able to read what they would have posted, or what videos and pictures they might have shared, if the technology had existed back then (in the case of my maternal grandfather, this would have been in from the 1880’s onward).

That made me wonder what my grandchildren will think when they read my Facebook page. Now, whenever I update my status or post a photo album I think about the people that might read it years from now.

The next time you type “OMG GOT SO WASTED LAST NIGHT LOL,” do think about your grandchildren before you hit the “Post” button. Of course, if you were partying with your grandchildren when you got wasted, well… okay, party on, I guess.

Share

Bragging On the GWA Marching Bulldog Band

My elder daughter, a senior at George Walton Academy in Monroe, GA, is a member of the color guard on the GWA Marching Bulldog Band. This past weekend the band competed in the USSBA Southern States Championships in Chattanooga, TN, where they placed first in the Group VI Open competition with a score of 98.563, the highest score of the competition among all bands in all classifications. This is an amazing band that performs at a high level year after year, and I’m so proud to have gotten to know the directors, students, parents, and many others that make this band what it is.

This year’s show theme was “The Carmen Project.” The show mixed music from the opera “Carmen” with other Latin themes such as Ravel’s “Boléro” while interpreting the story of the opera. It was a grand and moving spectacle that just got better and better every time I watched it. My daughter played the role of Carmen, which of course meant she got to die in dramatic fashion at the end of the show.

Here is my recording of the winning USSBA performance. The actual show starts at the 3:30 mark; before that, you can see the band marching onto the field and doing their warm-up routine.

Share

George Orwell and Effective Coding

I spend a lot of time and effort trying to get better at the craft of software development. My goal every day is to fall asleep as a better programmer than the one that awoke that morning. While this involves a lot of reading and practice within the field, I usually learn more by studying older disciplines since software development is still such a young craft.

Earlier today I read an essay on the decline of the English language by George Orwell. The essay is excellent, and I’m already trying to apply its lessons to my writing, but there was one passage that struck me as being particularly useful for software development.

When you think of something abstract you are more inclined to use words from the start, and unless you make a conscious effort to prevent it, the existing dialect will come rushing in and do the job for you, at the expense of blurring or even changing your meaning. Probably it is better to put off using words as long as possible and get one’s meaning as clear as one can through pictures and sensations. Afterward one can choose — not simply accept — the phrases that will best cover the meaning, and then switch round and decide what impressions one’s words are likely to make on another person.

To apply the quote above to software development, replace “words” with “code” and “dialect” with “programming language.” When you become accustomed to using a particular language or coding pattern, you tend to think of any new problem in those terms. If you choose the wrong strategy for solving the problem and start implementing too quickly you may end up with a solution that is too “wordy” or that does not express the abstractions accurately.

Earlier today, before I read the essay, I put this very lesson into practice without even realizing exactly why I like to do it. Whenever I come up with an idea for a new feature that I need to implement, or whenever I need to make a radical change to some system I’m working on, I’ll get up and walk away from the PC before the idea forms too fully and I start to write code. I’ll go for a walk or do some mindless activity (today it was sweeping the driveway) while I think about the idea. I’ll consider different implementations to see what problems might arise before I commit to a solution. Though I’ve never thought of it this way, it’s the same sort of process that Orwell describes in the quote above. Now that I’ve read Orwell’s precise definition of why this is good for writing prose, I better understand why it’s also effective for writing code.

Software development is hard. The job of a software developer is to turn an abstract idea into a concrete implementation in an efficient manner. Until you fully understand the abstractions, it’s impossible to consider any concrete implementation, let alone one that is efficient. I find that I write better code once I’ve thought enough about a problem to create a sort of landscape in my mind. It really is a landscape, too. It’s almost as if I can walk though the implementation in my mind and explore its darker corners. If I can find a way to build a mental model with fewer dark corners and dead-end hallways, then the concrete implementation will usually be more solid.

As you try to become a better developer, look for lessons from other fields like writing, architecture, the building trades, or any craft or profession that has been around for a long time. You’ll find that many problems that look like they’re peculiar to software development were actually considered and solved in other trades hundreds or even thousands of years ago.

Share

You Might Be an Old Hacker If…

It occurred to me recently that I’ve been using the Internet for almost 18 years now. That doesn’t put me into any particularly elite category since there were a lot of users way before I came along, but it does make me feel old to know that there are students in college now who were born after I started using the Internet.

Are you an old hacker like me? You might be if you…

  • …Remember when the word “hacker” just meant someone who tinkered with machinery or technology.
  • …Had an e-mail address that didn’t have to have numbers in it to make it unique.
  • …First accessed the Internet through a Unix shell.
  • …Ran your own SMTP server.
  • …Remember when the web was not the same as “the Internet.”
  • …Used gopher.
  • Still use gopher.
  • …Were glad that your Netcom address didn’t have an “ix.” in it.
  • …Wrote your first web site with Notepad (or vi).
  • …Wrote your first web app with CGI.
  • …Wrote your first “web app” before that term existed.
  • …Ever said to yourself, “Make money giving stuff away? That’s stupid.”
  • …Started an Internet business, decided it was a silly idea, and then watched someone become a billionaire with the same idea. (Hi, Craigslist.)
  • …Remember the first time you used NCSA Mosaic.
  • …Kept waiting for Netscape 4.0 to just die, already.
  • …Wrote Java applets when applets were the hot new thing.
  • …Wrote an HTTP server from scratch.
  • …Wrote a DOS shareware utility.
  • …Have IRC logs older than most of your shirts.
  • …Ran an FTP server on your office PC as a nifty way to access your files from home… and nobody cared!
  • …Owned a .com domain name that began with a commonly used word.
  • …Ran Linux prior to version 1.0.
  • …Browsed a web site with telnet.
  • …Lost your job in the dot-bomb.

That last one is particularly poignant. For me, 2001 was when the Internet, and by extension the web, ceased being some kind of new frontier. Maturity of a technology isn’t measured by people making a lot of money off of it, but rather by people losing a lot of money off of it. It was kind of hard knowing that I was out-of-work in a town (Seattle) where a barista at Starbucks probably had a better technology résumé than I did… and a job!

Just last week I became the last geek in the world to get a real smartphone (BlackBerries don’t count). As I marvel at all that I’m able to do with a remarkably inexpensive piece of equipment that can fit in my pocket, for which I’ve only spent a grand total of $2.99 in third-party software, I’m really glad that I’m an old hacker who got to watch this amazing world grow up right in front of me. You young kids don’t know how easy you have it.

(I’m sure there are a lot of you out there that were hacking in and around the ‘net way before I was. Let’s hear those war stories!)

Share