New Gamecrash course: Calgary in May!

Calgary, Canada (courtesy of 117Avenue, Wikimedia)

After everything learned in Gamecrash Austin last month, we are now bringing it in a new and better edition to Calgary (Alberta, Canada). The course will take place from May 27 to May 31 (Monday through Friday) at the Residence Inn Marriott Airport.

The concept is simple but very powerful: you can come on Monday at 8am as a developer who has never done games, and leave on Friday at 8pm as a developer who already knows how to make games, has learned all the main fundamentals, and has even written their first cool game!

You can get all the details at JP Boodhoo’s announcement, and register for on-site attendance here. If you register in the next two weeks, you can save $500. Attending the course is probably the best way to jumpstart your game development career in one week!

This time, we are also offering the possibility to attend online with a Gotomeeting setup (we’ll stream both the screen’s content and audio), for which you can register here. That way, you can get started writing games from anywhere in the world.

With all the experienced learned after the last edition, we’ve revised the course contents – streamlining the learning path, maximizing the content covered while making sure everything is explained properly and making sure all concepts are understood both in theory and using them in practical sample games. You can access the updated contents here.

We will be publishing more information here, a quite informative video is due out very soon, and of course feel free to ask any question – we’ll be happy to respond, and if something seems useful to a larger audience, I will post about it here on the blog.

I look forward to a very exciting game-making 2013 for everyone!

Gamecrash Austin was great!

So I’m finally back home after having had a blast with the Gamecrash – Develop with Passion® course last week in Austin, TX! (Note: check at the bottom of the post how to help us decide where to hold the next edition.)

The course was a great experience! It was a small group of highly-motivated developers, and we were able to cover a lot of ground: basic game loops, OpenGL, textures, rotations and matrices for general transform in 2D and 3D (using homogeneous coordinates even), game physics, animation, sound and music support, tile-based maps, pathfinding, character behavior, and even some actual 3D graphics and gaming on the last day!

By the end of the course, all attendees were convinced that writing a game is a very doable project, and so I feel proud and happy with how it went! Two of the attendees, even, were working on their own games by the end of the week (a zombies game and an infinite runner). I’m really eager to see what they come up with, and I’ll be the first promoter for their games as soon as they’re published.

The language choice proved great: we used C without pointers, which is as readable as code can get, and we lost exactly zero hours to issues with the programming language during the whole course. It was all games, games, games and games!

Here are some pictures from the course:

I went to the back of the room while people were concentrated stabilizing their hand-written physics engine.

The mini-game with platforms, tile-based map, parallax, fog, coins, particle systems, animations, music, sound, physics, cool character control and blinking eyes ended up looking great! About 1,500 lines of highly-focused C code can create a really great experience.

By the last day, you can see in everyone's faces that we were already all game developers in some measure.

Most of the time I was standing writing examples, algorithms and equations on the flipchart, but I had to sit down and rest every once in a while.

And you could always replenish energy with the Texas-shaped waffles at the hotel breakfast buffet. Seriously, I loved Austin, which is an awesome city, and it was a great location for the first Gamecrash!

We have already started to plan the next edition of the course, to be held about a couple of months from now. And instead of arbitrarily choosing where to do it, we are trying to learn from the people interested in attending where to hold it. So please go to JP’s Develop with Passion® blog, and select where you’d like us to host the next course. We’re considering Canada, San Diego, NYC or London s the main options. We’ll announce it as soon as we can have enough feedback and we start setting things up. Hope to see you there!


PS: Graphics courtesy of the following artists: Tyrian and other graphics by Daniel Cook (http://www.lostgarden.com/), Fuzed graphics by Marc Russell (http://www.spicypixel.net), Zombie sprites by Clint Bellanger (http://opengameart.org/content/zombie-sprites). Thanks guys!

Gamecrash: learn games programming in one week!

A few months ago, I was discussing new opportunities over Skype with Jean-Paul Boodhoo from Develop with Passion® fame. He came up with an intriguing concept I wouldn’t have thought of: why not offer developers from different backgrounds a hyper-intensive bootcamp on games development? A one-week bootcamp at that? And have developers who have no background in games programming become actual game developers n one week?

See, JP has been teaching greatly successful bootcamps on advanced development techniques for years. Over 1,000 students across the globe can attest to the efficiency of such a course – feedback often ranges from “amazing” to “life-changing”. The concept is great: you set everything up at a hotel or similar venue, and decide to dedicate EVERYTHING during 5 days to transmitting the relevant knowledge. Days last 12 hours or more. The idea is that people should leave everything aside, and put all their effort into advancing to the next level in their software development skills and careers. With a passionate and experienced instructor, and focused and motivated students, it can truly be an amazing learning experience.

JP suggested that with my games background, it could be an interesting idea to offer such a course, to teach games development to developers from other fields. With JP’s experience in setting up such courses successfully, and my knowledge of games development, we could provide something incredibly valuable that hasn’t be available before. This meshed up nicely with a lifelong interest of mine, which is teaching. Back in the day, I taught an assembly-language programming course online, and then turned it into a book, actually, the book I would have liked to have when I was learning assembly language myself. Then, I’ve taught courses several times, and starting last year, I have been directing a Master’s degree in games development in a new high-end university in Madrid.

There were several principles neither JP nor I were willing to drop:

  • We want to get students to master fundamentals. We don’t want them to learn any tool are method that is useful today, or for limited-scope projects, and have their skills be useless when technology advances or they tackle larger projects.
  • We want to have students create actual games at the course. Even if fundamentals are about understanding the theory and the basics, we want them to actually apply the skills, and especially in games, you want to see an actual game using those principles. Nothing like teaching the geometry of how entities collide, and then writing an example that shows balls realistically bouncing around the screen with sound effects!
  • We want the games students create to be a realistic first step towards writing games that can be published. We don’t want to work with a language which is great for learning (say, Python), and then, have very few options of turning what they write into an actual product. Be it free or commercial, players will need to download and install the games on the platforms they usually play on. So Python, no matter how much we love it (and I really love it!), is not an option.

We wanted to create a course that would provide incredible value in fundamentals of games development, and practical tools to create games that can actually be published. We wanted to set students on their path of writing games. All this, for students with no previous experience in games. And what’s more, all in one week! Definitely a tall order. Could we find a way? Such goals required choosing very carefully the set of concepts that are included, limiting the scope so that we can cover things well, but not limiting it so much that we don’t obtain the course goals. Some aspects were key to a successful course:

  • Game type: definitely, the games covered have to be 2D games. It will already take quite some time to cover the math/geometry/graphics tools to write rich 2D games – there is just not enough time to cover 3D. The good thing is that all the game fundamentals are the same, and students will be able to apply them to 3D games when they take up 3D math/geometry/graphics. And, also, even today, many of the most popular games are 2D, so it’s clear that 2D is a rich enough medium for great games!
  • Programming language: it took a while to reach a good solution here. Very nice and very high-level languages such as Python are not a viable medium to write a complete, redistributable game. For C# or Javascript, there are options to use specific frameworks, but then you are completely tied to that framework. HTML5 is eternally almost there. Also, if you want to write games for most platforms, and even work your way towards a career in games development, most real work is done in C/C++. But this is a problem: we couldn’t count on students knowing C/C++, as they may come from a background like Java, C#, VB, PHP… And it’s simply impossible to teach C++ classes, inheritance, etc… in a short amount of time. A first strange thought made me think of using C, as a way of simplifying things. But even if we go for C, this involves pointers, and it’s not easy for people to pick up pointers. I don’t want students wrapping their head around pointers for a week, I want them wrapping their head around games! What could we do? I spent many hours pondering this, and came up with an option that sounded radical and weird, but which seemed to solve the problem: we could use plain old C, and get rid of the biggest obstacle, pointers, by simply not using them. We would need to use arrays for most things, and code can be a bit more verbose because of this, but C without pointers is simple enough to use and understand for developers of any background. And not only that, using pure C, you can write games for Windows, Mac, iOS, Android, and even for consoles! Students can complement this in the future by learning more advanced C and C++, and this is much easier to take up on their own once they are actually writing games. So, the answer was clear, the course was going to use the weird but wonderful C without pointers.
  • Platform: desktop platforms are the most immediate platforms to work on for a first stint in games programming. Both Mac OS X and Windows are great environments for developing games, and not only that, you can use C for both of them. Together with OpenGL for graphics and OpenAL for audio, you have a quite nice common platform. A bit of system-dependent glue-code is necessary to set up OpenGL and read input events on each platform, but this is about 100-200 lines of code which can be easily covered. Thus: Mac OS X and Windows are our chosen targets. Good thing: we can have some students working on Macbooks and other students working on Windows laptops, and apart from a a couple of hours at the beginning for each of them to write their OpenGL set-up code, all the rest of the course is 100% identical!

One important comment with regards to the platform: mobile platforms are probably the most attractive platform to develop games for right now, but setting everything up for iOS or Android development on the course, for people without previous experience, would not be feasible in the time available. I took the following approach: I’ve made sure that you can easily jump to mobile development after the course. Games for both iOS and Android can be written in the type of C we are learning. Once you set up the development environment, and learn how to adapt from standard OpenGL to the mobile dialect (OpenGL ES), you will be writing games for mobile in no time.

With these three big decisions (2D games, written in C without pointers, running on Windows+Mac OS X), it seemed like the main axes of the course were ready. I had to prepare the content and all example code to make sure things fit and make sense. For the past few weeks, I have been preparing the course contents, detailing the core concepts to focus on, and writing all these tiny, little, beautiful samples and mini-games, using only C without pointers, and making sure everything can be grasped by the intended audience in the limited time available.  It’s been a pleasure to work on the code, writing in C without pointers has turned out to be surprisingly a pleasant experience, and the samples look good, too! It’s good to know that during the course, students themselves will be able to write these (or variations thereof). Here are a few cool screenshots:

Newtonian physics, collisions,  sound, and character jumping around

Newtonian physics, collisions, sound, and cute character jumping around!

Fire particle effects for fun and profit

Fire particle effects for fun and profit

Hard-to-control spaceship clearing a minefield

Hard-to-control spaceship clearing a minefield

Software development in general is still a young and informal discipline. Unlike architecture, where it’s mostly well known what you have to do to plan and build a building that won’t top over, in software development we are still figuring what the key elements are to build a solid system. I hesitate to call it “software engineering” since, well, frankly, I don’t think it can still be called “engineering” most of the time, more than cooking can be called “meal engineering”.

Thus, the way knowledge is communicated is over informal media: web sites, blogs, work experience, and good habits communicated from one generation to the next. This is even more so for games than for other types of software. Even today, if someone asks me what they should study to become a good games developer, I would have a hard time choosing what materials to recommend.

But what remains true is that many developers, no matter if they work on web projects, internal company IT applications, or mobile applications, would LOVE to develop and create their own games. Games are a really exciting medium: as an entertainment just for playing them, as a commercial product that can be either a direct revenue generator or  an industry where to build a career, and as a creative medium to enjoy delving in.

Games development has remained a difficult area. It can be quite hard to get started, with a myriad options of languages, engines, APIs and platforms to choose from, some math to learn too which can be intimidating if you don’t know where to start, and many other difficulties inherent in a medium that covers creativity, graphics, physics, music, sound, and so many other disciplines. But if you knew exactly what road to go, it’s attainable, and not necessarily too time-consuming.

All in all: I think there are many developers out there who have the inclination, the motivation, and the background to tackle games programming, but who haven’t really done it because the way to get started is not easy or clear. And I feel we can really help them jump-start their games-development career.

I think we have found a very interesting area here, a type of project that can be very interesting and satisfying for us and for students, and that Gamecrash courses will be very successful, turning scores of students into game developers with this ambitious but realistic plan. I’m really eager for the day I’ll be posting an article here announcing a game released by one of the students. And I’d say that is just a few months away!

We are holding the first edition of the course in Austin, Texas, from February 18 to February 22, just two weeks from now. Several students have already registered, but there still are seats available. You can sign up here. If you want to develop your own games, and you have a non-games background as a developer, I can’t think of a faster or better way to do it. You’ll save a ton of time exploring the wrong ways to do things, and get started straight with the approach that works. If you’d like to attend online, virtually, we are thinking on offering it too at a discounted pricing – let us know. Get in touch with us if you’re interested in attending, online or virtually, or if there is any other areas where you’d like to get our input!

More info:


PS: Graphics courtesy of the following artists: Tyrian and other graphics by Daniel Cook (http://www.lostgarden.com/), Fuzed graphics by Marc Russell (http://www.spicypixel.net), Zombie sprites by Clint Bellanger (http://opengameart.org/content/zombie-sprites). Thanks guys!

The Gamecrash is Near!

Plane tickets to Austin, TX: purchased. Macbook Air: loaded up. Hotel: booked. Instructions to students on how to prepare their laptops: sent. All cool Windows & OS X example code: up and running. Everything ready for Gamecrash on February 18th!

Here are some screenshots from the samples you will be coding during the course (the first ones, I’ll post more advanced ones in a few days) (and of course you will have creative freedom to do your own variation of these!):

Spaceships. OpenGL graphics. Simple “C without pointers” so that we can focus on programming games instead of neverending mumbo-jumbo. Bubbles. OpenAL audio. Game physics. Bouncy balls. Characters walking, jumping, shooting. Keyboard and mouse-based controls. Zombies. AI. Worlds and levels. Explosions. Graphics effects. What else can you ask for?

There are still seats available, if you want to learn games development in the best way possible and in the shortest amount of time, you should definitely join here! (All the course details here.)

I’m enjoying incredibly programming all these minigames. Even more so doing it in this refreshing, simplified C. It is an incredibly valuable language for learning, and it also feels like getting rid of a lot of cruft and going back to the really valuable roots!

PS: Graphics courtesy of the following artists: Tyrian and other graphics by Daniel Cook (http://www.lostgarden.com/), Fuzed graphics by Marc Russell (http://www.spicypixel.net), Zombie sprites by Clint Bellanger (http://opengameart.org/content/zombie-sprites). Thanks guys!

Gamecrash: writing games using “C without pointers”!

The concept for the Gamecrash course was clear from the first moment: really focused course to get people to actually learn to develop games in one week. Focus on fundamentals, such that people learn the core skills. But be sure to create an actual game – this is not a theory-only course, we need results! Of course you can’t write the latest advanced 3D consoles first-person-shooter with amazing AI in a week. But the core game-development skills and the skills to write 2D action/puzzle games can definitely be taught in one week, and they can be the best foundation on which to build future knowledge for more complex types of games (3D, etc…).

It’s clear that if you want to create a one-week course that really gets students to the “next level” you are going to have to be very precise on what things you want to cover and which ones you want to leave out. You have to make sure the whole contents are a solid structure that holds itself together well, that can be used without any extra content to actually develop games, and which can later become a great base upon which to build a full professional career if students want to pursue that road.

A key question here was the base language and technology to use. There were several options: most professional games are done using C/C++, but more and more frameworks and libraries allow you to write games in Javascript or C#. Also, languages such as Python are easier to pick up than C/C++, maybe we should go that way?

Also, students will come from different backgrounds. All of them will have software development experience, but not games development experience. That means that some of them will be fluent in Java, others in Ruby or Javascript, and some others even in PHP. We have to make two things very sure: (1) that it is possible to attain the goals we have set out to cover, and (2) that we actually choose the contents and design the course such that we actually get everyone to be developing games by Friday.

First, it was easy to dismiss options such as using Python with some games/graphics library, or similar high-level languages. They are a great environment, but it’s difficult to actually build a full game of production quality using those. Many commercial games embed Python or similar for the scripting of the game content, for which it’s great, but the games itself is usually written in C/C++.

Second, Javascript would be one language to think of, but developing a game for the browser has it’s own challenges: it’s still a games-platform struggling to become established! Also, we are after creating the type of games that people actually play (and pay for!) every day on Windows, Mac, mobile, consoles, etc…

Third option, frameworks such as Unity and the like allow you to develop cross-platform games in not-hard-to-pick-up languages such as C# or Javascript. But I didn’t want to center the course around a specific framework, technology or library: we want students to learn the fundamentals, to take their game-development career to the platform they are interested on, to have freedom to develop their own games in the way they like – and this requires another approach.

Finally, everything seemed to point towards using C/C++ with OpenGL, which are actually used for most games development out there, and with which, apart from games, you can build a professional career if you feel so inclined. But this road had its own difficulties: programming in C and C++ is notoriously hard. Learning classes, inheritance, templates, etc… for C++ development is just not doable in one week. On the other hand, even if you go for C, which is simpler but equally powerful, there are difficulties. Most developers have had contact with C, and have been bitten by its quirks, mainly, the dreaded pointers. For those of us coming from assembly language development, pointers come naturally, but for a Java developer joining the course, covering pointers would be hard. And not only that – I don’t want to waste a full dear day out of just five that the course consists on!

And so, I started considering how I could simplify things, and I came up with an intersting idea: is it maybe possible to write a complex program such a game in C, using only a subset of its features, and mainly, avoiding the use of the dreaded pointers?

It seemed a bit shocking, I don’t think I’ve ever seen or written C/C++ without using pointers, but it still seemed like it could work. This meant using just variables, functions, arrays, and structs (for non-C-ers, they are something like records/dictionaries where you can pack several related values in a new type for your variables). Nearly all developers will be familiar with these concepts, are they are the basic building blocks of programming in any language.

So I started writing some sample code using this approach, and it turned out it is amazing! Really simple to write and to comprehend, using simple arrays and variable types, but still able to express everything games development needs.

The advantages are twofold:

First, that it’s really easy to pick up. I expect to dedicate a grand total of about two hours to teaching “C without pointers” – and thus have all the rest of the time to actually create and develop games.

And second, really importantly, what you learn is pure, actual games development in the way that commercial games are done on nearly all platforms! It’s not a toy language or technology, C and OpenGL are the base of everything, and it turns out our best didactical choice is also a great choice career-wise. After the course, you can add more C and C++ knowlege, which is not that difficult to do on your own, and you are progressively becoming an experienced games developer that can work in creating commercial games, be it “indie” or in the games industry.

After this awesome didactically-motivated discovery, I’m happy I’ve found “C without pointers”, a great tool that I’ll be using for many years to come in Gamecrash courses and similar initiatives. And I look forward to the feedback from students when they start using it!

Gamecrash Austin course venue & hotel discount

Two important pieces of news: we have changed the venue for the course to a hotel right next to the Fickett center where the course was initially going to take place.

This is the hotel:

Marriott Fairfield Inn and Suites Austin North | Parmer Lane
12536 N. IH35, AUSTIN TX 78753
T 512.687.6315 F 512.833.9656
http://www.marriott.com/hotels/travel/auspl-fairfield-inn-and-suites-austin-north-parmer-lane/

The hotel and its installations are great, and the second important piece of news, we have been able to secure a great room rate ($85 per night!) for course attendees. We will send you the discount code so that you can book your room upon registering for the course.

Several people from Austin and other places have already registered, hope to see you there!

Stirring up some interest for the Austin Game Crash course

We’ve started announcing the Game Crash bootcamp due on February 18th in Austin, and we’re finding there’s quite a lot of interest out there! Here are some selected reactions and questions:

“I’m very interested, in fact I’m just a few clicks away from signing up, but I wanted to check and see if the cost of the hotel is included in the course registration fee, or if we have to make our own arrangements. Thanks!”

Actually, the cost of the hotel is not included in the course fee. There are several nice hotels 2 minutes away from the venue where the course will take place, and we’re trying to see what they can offer to attendees, we’ll post about it here too.

I’m curious about the facility, so I’ve looked it up. Apparently this is the Boy Scouts facility;

http://www.bsacac.org/about/fickettcenter [EDIT January 12: we have changed the actual course venue to a hotel right next to this center, where we also get great room rates for attendees, see details at http://jonbho.net/2013/01/12/gamecrash-austin-course-venue-hotel-discount/]

That looks like a nice size training room but if you filled it it could get tight especially if spending 12 hours a day shoulder to shoulder. How many people are you maxing at?

I may spend the night right there at that Marriot. Do we get a discounted/group rate?

We are maxing at 16 people, since we don’t want the group to be too large, for best results of the course. In JP’s experience, that’s the right limit for this type of course.

We are right now talking to the hotels nearby to see if we can get a discounted rate for course attendees, we’ll post here as soon as we have the info.

[EDIT We got great rates, $85/night at the Marriott, all details here]

“This sounds really really exciting. If there is enough interest in the Australia/New Zealand area to warrant a course, I would definitely be very interested. What about a Webinar type course for those of us in far places?”

Of course, if there are enough people, we’re more than happy to visit the kiwi land and the land down under. And we are considering offering live assistance to the bootcamp too, we’ll announce it here.

“How very awesome, Commandos was my favorite game, it’s the only games (1 and 2) I still have on my shelf, the rest I have either sold or given away. So your development have had a deep impact on me, hehe.

This course is in Austin Texas as far as I can understand, are you planning any courses in Europe? (as far as I understand you actually live in Spain right?)”

Indeed, I’m based in Spain, and we will be offering courses in Europe down the road. Let us know exactly where you’d be interested in attending, we’ll organize courses as we find enough people wanting to attend in each area

Just a quick note that I’m definitely interested in this course if it comes to UK/London.

In the event it does – do you an idea of what the approximate cost would be?

It’s most likely we will be offering it in London quite soon, we’ve received several requests from different places in Europe, and London is probably where most interested people concentrate. The full price for Develop With Passion® bootcamps is $3,000 in the US and $4,000 in Europe, due to the higher cost of everything in Europe. For the first few iterations, we are offering the Game Crash course for $2,000 in the US and $3,000 in Europe, and signing up early gets an additional $500 discount, so it will be $2,500 in Europe – about £1,600 (making sure you sign up early for the first course we offer in London!). For other EU countries – about €1,900 with all early discounts (of course, variable exchange rates making this an approximate figure).

What is “C without pointers”? Static declarations, pass everything byval and no arrays?

Indeed, something in that line: module and global variables, structs and arrays only. It results in quite simple code, while it is usable, we can use OpenGL, and it can be used for developing production-quality games. I’ll do a full post on this choice in the next few days.

Hopefully we’ll be able to offer this in many other cities and countries in the coming months!

Gamecrash: new hyper-intensive game development boot camps

I am happy to announce that I have joined forces with the awesome Jean-Paul Boodhoo, of Develop with Passion fame, and we are going to start offering a revolutionary new type of crash-course on games development. Combining his concept of highly-intensive one-week bootcamps, and my game development and teaching skills, we are going to start offering extremely high value courses for general developers to gain all the core game development skills as quickly as humanly possible.

The focus will be on combining a strong grasp of the fundamentals of games development with a highly practical approach. The goal is that developers with no previous experience in games or graphics programming will come to the course on Monday at 9am with all the motivation and energy, we will turn on the turbo and work for 12+ hours a day until Friday, and they will be leaving having learned and actually applied all the main elements of game programming on Friday evening, with a simple but nice and working game under their belt (it’s best if you bring your own graphics!), and with all the necessary core skills to develop your own games personally or professionally!

We’ve decided to work using OpenGL, basic C without pointers, and work on 2D games, so that any reasonably proficient general developer can become productive as a games developer in one week. You will need to be ready to put in all the necessary effort and energy, but if you know your way around variables, loops and functions, you will be developing games by the end of the course!

The first course will be starting on Monday February 18 in Austin, Texas, and it will last until Friday, February 23. This first edition of the course is offered at a discounted pricing for Develop with Passion courses, so take advantage of being an early adopter! We plan to offer the same course in other cities in the US, Canada and Europe. If you’d be interested in having this in your area, let us know and we’ll try to address that.

You can see JP’s announcement here, all the Gamecrash course details and contents here, and you can see the Eventbrite event page with the location and pricing details and the sign-up options here, and I will be happy to respond by email to any question you may have. We will be posting more details over the coming weeks. Be sure to sign up if you want to turbo-boost your game development skills. See you in Austin!

Is your compiler throwing onions in the varnish?

In a by now well-known anecdote, Primo Levi, an Italian chemist-become-writer from the early twentieth century, was reviewing how varnish was produced in an industrial facility. The recipe, involving many chemical components, included instructions to throw in a raw, peeled onion in the varnish. This was puzzling to him: he couldn’t figure out why the onion could be needed, or even how such a small amount of material could affect the resulting varnish. Nobody he asked at the factory knew why it was needed. Seemingly, it had been done like that forever.

Intrigued, he researched where this came from, and after some heavy digging, he discovered the reason: in earlier times, when varnish was produced in a less industrialized fashion, varnish-makers would throw in the onion, they would look at it, and when it become brown from being fried, they’d know the varnish was in the right temperature for the next step. When the production system had gained thermometers and automation, someone had just kept on throwing the onion out of habit, and thus it had become an ingredient of the varnish.

Compilers?

As an example of a modern varnish recipe, let’s have a look at the canonical MAX function: let’s see how you would find the maximum out of a list of numbers in any modern imperative language:

max = a[0];
for (i = 1; i < n; i++)
    if (a[i] > max)
        max = a[i];

This loop finds the maximum value in the input array and returns it.

And you may ask, what is the problem with the above code? Isn’t it just pretty conventional code to walk an array and extract some information from it? Isn’t that how programming is supposed to be done?

The problem is the fact that we are writing the detailed steps on how to do something, at a very low level, instead of describing what we are trying to attain. And this has three key negative properties:

  • The actual goal of the code is lost. The code does not contain or embody it, it only lists the steps we concluded we needed. Someone reading it needs to deduce the thinking and the goal, the “spec”, is not actually there. The runtime (whatever it may be: interpreter, compiler or just-in-time trace-compiler) understands too little of what it’s doing. What it’s doing is like following step-by-step directions without a map, or like a blind man taking each step without any knowledge of the environment. Given this, it has limited possibilities to find shortcuts or improvements.
  • Code becomes very repetitive, verbose, and takes a long time to write. Current programming practice involves reinventing the wheel too often. After programming for a few years, it often seems as if you are rewriting the same code over and over again. Libraries and frameworks help somewhat, but they become a kind of “straitjacket”, you can benefit from them, but it comes with a huge extra cost in conventions and other conditions you have to adhere to.
  • Writing code this way is very prone to errors. It’s very easy to think you are writing the steps for a given result, while you are making a mistake and getting something else. Too often, this only apparent when running the code, and even worse, only in edge-cases when unforeseen circumstances take place.

When the compiler is generating the code to compare two values, for example, it is doing exactly the same as the worker who threw an onion in the varnish. The compiler doesn’t know what it is for, it is just blindly following instructions, which may or may not be correct for the desired goal. There are none in the example above, but actually, you often find “onions” in real code out there: pieces of code that serve no purpose, but that are being run because they’ve been there since some time they were useful. And nobody, not the developers, and especially not the compiler, has bothered to review their value in light of the current state.

I believe there is a better way to express computation, a better way to describe the function to compute the maximum, which can sidestep the drawbacks listed above. And this requires getting to the bottom of the issue, understanding the essence of what the “maximum” function above is supposed to do. Let me give it a try.

The essence

This is what I think the core of the MAX function is: the maximum of a set of numbers is the number out of them that is larger or equal than all the others in the set. This is the essence of MAX. We are not saying how it can be calculated, we are defining what we understand as the maximum value in a list or set: just the value that is larger or equal than all others in the set.

When you see the imperative code above, you see a sequence of steps that will allow you to find the maximum value as defined above. But it’s a specific method, a recipe, and it doesn’t describe either what the final result is, or why we took those specific steps. There are actually other ways to find the maximum, but the definition is unique.

Of course, we, as the developers who wrote the code, know why the steps are there. But by the time the compiler/interpreter/runtime-system reads the steps, the reasons are lost, and only dumb instructions remain, without the reasons why they should be followed, and of course without any possibility of adjusting further.

If we could find a way to embody this essence, we could have something much more valuable than the imperative code above.

Don’t imperative and OO programming cover this with their libraries and frameworks?

Imperative programming is the canonical “all information is lost” approach. State is stored in variables or objects (object-oriented programming is a kind of imperative programming), and each step is free to alter any state it wants. Actually, not only can any statement in the example above botch the calculation, but it can crash the program too. I believe this is the reason programming sometimes feels to me like walking barefoot amid pieces of broken glass.

Even more importantly, there is a brick wall that this is hitting: due to the loss of information, it’s nearly impossible to reorganize this kind of code automatically at all. One big loss here, very relevant for the coming years, is that it’s nearly impossible to automatically parallelize imperative code. Those 64-core processors that are coming out soon? You’re out of luck if you want the code your team wrote during the last 5 years to benefit from them.

Many a developer will just say: “duh, the standard library in $MY_FAVORITE_LANGUAGE already has a MAX function, so I don’t even have to think about it – and I’m sure it will parallelize things the day my desktop has 64 cores”. And the answer is: yes, your current language may help with this, but it doesn’t help with the many variations of the MAX function you are going to have to write for your code. Of course, if your favorite environment has a standard call to do something, you will do well in using it. But pretty soon, you will deviate from the exact needs the environment covers: instead of the MAX function, you may need the largest value below a certain threshold, or the first value after some given one, or whatever variation. And right then and there, you will have to start writing code like the above, which won’t benefit from the 64 cores unless you put in serious extra work.

We need to find something more powerful than imperative calls and standard class libraries.

Does the current trend towards functional programming cover this?

Functional programming is touted as one of the possible solutions to the parallelism problem. Functional programming definitely has some benefits, but I think it has a big problem, as that is the fact that is based on lists.

Lists in functional programming are a weird creature. In all common functional programming languages, they are defined recursively, with a head that is the first element of the list, and a tail that is another list, the “rest” of the original list. This seems completely normal to functional programmers. If you are not familiar with it, it definitely looks asymmetric and weird. I’d say it actually is weird, this is not how us humans think about sets and sequences. The advantage is that such lists provide a simple and formal way to structure and think about computation, which is why they’re so widespread.

Here is the canonical definition of MAX in most functional programming languages:

max (head:tail) =
 if (head > mt) head else mt
 where mt = max(tail)

There are variations of this, but they are all basically the same. As in imperative programming, we are just walking down the list, recursively, and doing the comparisons that we know will let us find the maximum value. To begin with, its recursive nature makes it more difficult to understand. I’d say our brains are better wired for iteration than recursion.

But apart from that, it is still missing the same information as the imperative version. This doesn’t show anywhere the core property that we understand as being the max value, that is, being larger than all other values in the set or list!

How about Prolog and declarative programming?

Prolog takes an initial promising approach, with declarative code, but it very quickly gets off-track. The language lacks expressiveness for really strong declarative power, things like “cut” turn off the guaranteed validity of programs, and the canonical definition of MAX in Prolog is as poor as those in imperative and functional programs:

max([X],X).
max([X|Xs],X):- max(Xs,Y), X >=Y.
max([X|Xs],N):- max(Xs,N), N > X.

This is tied to the fact that sets in Prolog are represented as lists, and lists are defined recursively as a head that is an element, and a tail that is a list. This all but forces the definition of MAX above.

So how would it look?

Here is a pseudocode draft of how I believe the code should look in order to contain the essence of the “maximum” concept:

max (set): element-in set
 where
   foreach x in set
     if x != max
       max >= x

This is a radically different way of definining the maximum function. It is not saying how to calculate the maximum value: it is saying what the maximum value of a set is. It is describing what we understand when we think about the maximum. And it is doing so in formal terms, just a set of properties and constraints that describe the solution:

  • The maximum of a set is one of the elements of that set
  • This element, which we call “max”, fulfills some properties
  • The properties are related to the other elements of the set: for every element in the set other than this one we call “max”, their value is less than or equal than the value of max.

As you see, we are doing exactly the opposite to all the other examples above. We’re defining the WHAT, and leaving out the HOW.

As far as I know, there isn’t a programming language out there that works like this. If you know of one, I’m interested, be sure to let me know!

The bad news

The bad news is that, even if the sample code above has all these beautiful properties about describing the solution, there is something that it is missing: it is not describing how to reach that solution. And thus, the next challenge is born: devising a runtime (compiler, interpreter, interactive dashboard, whatever) that can take code like the above, and turn it into something that can actually be run.

This is a tough and large problem, but one I believe is very worth attacking.

And why is this important?

Say you write the MAX function in a way as described above. Describing its essence. And the runtime environment has the brains to run that code, that is, to compute its results. What would that mean?

  1. The code is guaranteed correct with regards to the spec! There is no possibility of an off-by-one error leaving you lost in those rare cases where the last value in the list is the maximum and it is missed! If you defined the properties correctly, the runtime will reach the right result.
  2. The runtime or compiler understands much more of what it’s doing. It can cache partial results, it can decide what is safe to cache and what not. It can restart computations. It has much more information to manage how it runs the code.
  3. Parallelism! While a dumber runtime will decide to iterate over the list to find the highest value, a smarter runtime may decide to break the list in chunks, calculate the maximum of each chunk in a separate core, and then calculate the maximum of the partial results. With only the definition above, and knowing the transitive property of the >= operator, the runtime could reach this conclusion in a formal way. The possibilities that this opens are endless.
  4. Even if it won’t be easy to write a really smart runtime, we could write a dumber runtime that could take “hints” in order to get good efficiency, and then write the hints separately from the code itself. This type of runtime is an easier target, and at the very least, this approach allows much better separation between defining WHAT we are after and HOW we are going to get it. Similarly to SQL databases, it would separate the problem of defining the data model with tables and queries, and optimizing execution deciding the indexes to keep, how to keep them, etc… ensuring that the optimization will never introduce any bugs, and possibly allowing much better separation of work between different people with different skill sets.

Help is welcome!

I’m trying to address this somehow. I’ve thought a lot about it. I’ve written a bit about it. I’ve even written a bit of code. I have some insights on how to tackle the issues that come up defining such a beast. And there are many reasons I would be grateful for your help:

  • First things first: I think I’m following some valuable insight, while going after some practical, realistic, attainable goal. But I may be delusional? So, be sure to let me know if I’m missing some key point that invalidates the whole enchilada!
  • I have an eminently practical background, not theoretical or academic. I think I’ve done my homework, but I may be missing something out there. I know there are researchers in the different related areas: Coq for theorem proving, constraint-system solving, compiler research, static code analysis, etc… if you have a background in this area, and you can point me in the required directions, I will be grateful. Especially, if someone is already working in a system like this, or pieces of a system like this, I’d definitely like to know!
  • If some of these things are already done, and the whole project turns out to be a matter of putting existing pieces together, let me know! It will take less effort that way.
  • At least to me, this is a fully new approach to computing and programming. It requires expertise in compilers, languages, type systems, optimizers, constraint-system solving, etc…. how could I not need all possible help?
  • If you are practically minded, as I am, you can help me make sure we create something that is useful for day-to-day work and can make developers’ lives less miserable, instead of a research project (much respect to those, but that’s not my goal here).
  • I have little time and I have to dedicate a lot of my time to mundane things like earning a living and paying off debt. So of course, my resources are limited, and all help is appreciated.
  • In general: I’m sure I’ve missed things. Let me know which ones!

This is a long-term project. I doubt much advance can be done in the short term. But hopefully, given enough years, eyeballs, neurons and hands, we will be able to program in much nicer ways in the future.

And we will do away with a lot of onions!

The undecidability of the halting problem is not very important

Many a programmer, when confronted with a difficult computational problem, claim that it doesn’t make sense to investigate it further, since it is just a special case of the halting problem, and as proved by Turing back in the day, this is just not solvable in the general case. But I will try to show tha this is not a very useful or smart way of looking at things.

There are two important and opposite approaches that show the little utility of this thought process. They are two distinct attacks to the same area, both demostrably valid, and I hope to make them both easy to understand in this blog post.

The first issue involves the fact that, even if something is not tractable in the fully general case, it doesn’t mean there are not many useful cases where it’s not only perfectly tractable, but also well worth doing it. Let’s take static code analysis for example. Here is a nice piece of C code to find the maximum value in an array of unsigned integers:

unsigned int val = 0;
for (int i = 0; i < N; +i)
{
  if (array[i] > val)
    val = array[i];
}

This code has a subtle but important bug: it will just never terminate. It’s actually an infinite loop. Why? Because the loop counter is not incremented. There is a typo, we missed a “+” sign in the “++i” expression, and thus the expression meant to increment the counter does nothing. Thus, the loop counter will stay at zero, and the code will loop until the sun goes nova.

Turing showed that, in the fully general case, it’s impossible to determine whether a given piece of code will terminate or not. But he did not determine, at all, it is impossible to write a tool that would detect this case, and diagnose, for sure, that this code is wrong and will crash the program that runs it.

Of course, most modern compilers will emit a diagnose of the simple typo above: “expression has no side effect”, or something similar. But this is not the point – there are many subtler cases of the same phenomenon, which can’t be easily detected by a compiler’s peephole code analysis, but which can be analyzed by sufficiently advanced tools. Fortunately, John Carmack recently bringing up static code analysis will hopefully help with interest, attention and funding towards this useful area, Gödel and Turing notwithstanding.

Now, let’s go to the second angle from which the though process described at the beginning of the post should be questioned. Let’s imagine designing a language that doesn’t allow non-terminating programs. By definition, this can’t be Turing-complete. And so we should be safe from programs that crash or hang indefinitely. Leaving aside the difficulty of even defining what “correctness” is for a program, we could think that we would have advanced a lot towards this goal. At least, our programs will be determined to complete. Following this direction, and trying to find ways to prove that certain classes of programs terminate, advanced terms and distinctions such as data and codata have been invented. A program that responds to an input stream should actually be allowed to run at least in proportion to the length of the input, and still be called correct!

Anyway, if this gets you excited, let me pop you bubble by introducing you to the beautifully named Ackerman function. I won’t go into the mathematical details, it’s just a perfectly well defined functions (or family of related functions, if you will), which can be simply calculated for any input, which involves some recursion. The beauty of it is the following: for small values of the input (say, 0 to 4), the function returns normal low values (1, 3, 7, 61…). But as soon as you try to calculate the function having as input 5, 6, or something higher, the result explodes, and there just aren’t enough atoms in the known universe to even print out the result. Actually, even if it is guaranteed to terminate, its calculation will keep chugging along the infinite loop seen above until the sun goes nova.

Isn’t it beautiful? As computer theorists, the first example loop and the Ackerman function with 10 as an input are completely different beasts. One is a demonstrably infinite loop that is guaranteed by theoretical reasons to arrive nowhere. And the other one is a demonstrably finite loop, which is also guaranteed by practical reasons to arrive nowhere.

We are still in the infancy of the field of computation and software development. We have achieved very little compared to what can be done, and many of today’s approaches need a lot of rethinking before we can move forward. The boundaries of functional programming, declarative programming, partial evaluation, speculative computation, etc… are often very hardly defined, and seem to leave very little room for improvements over current techniques. But the real value lies in the gaps between those, in combining the practical approaches of each, and thus it is really difficult to really see the shape of this “new programming”. But slowly, we advance, and in a few years, it will be obvious how 2012 is the stone age of programming.

We already have the words, we just need to find the way to put them together to read like “Hamlet”.

PS: I believe even genius Roger Penrose himself fell prey to a similar faux-pas in the central argument in this book “Shadows of the mind”. But this is fodder for another post some time in the future.