Creating my Own Language - Functions

In my spare time I have been working on creating a new lightweight, general purpose programming/scripting language. I have no real intention of doing anything with the language beyond experimenting but I find that trying to create something can often help you understand why things are the way they are. I really wanted to create a syntax that embraced modern programming features (such as type inference, lambdas and concurrency) as part of the language’s foundation and not as boilerplate additions.

Originally the syntax for my functions looked a lot like a hybrid between Python and Actionscript (The language is optionally type inferred so the explicit types are purely there to fully illustrate the syntax formatting):

func Add(const x : s32, const y : s32) : s32
	const result : s32 = x + y
	return result

I was pretty happy with the syntax as I like the enforced coding style of Python with the syntax of Actionscript and I felt there was consistency between the variable/const declarations and the function declaration. However, once I started thinking about lambda functions (i.e. anonymous functions) I felt that the consistency between functions and variables started to break down. In most languages (C++ and ObjC in particular) the syntax for lambda functions is horrendous and I wanted to avoid the discord between function assignment and variable assignment. So I started to think of functions more like variables, constants or expressions (which are frequently passed anonymously). That train of though lead me to this syntax:

Add : func = (const x : s32, const y : s32 -> s32)
	const result : s32 = x + y
	return result

The above syntax is very similar to creating a variable or constant and it should be very clear how to use anonymous functions or how to assign functions:

Add : func = (const x : s32, const y : s32 -> s32)
	const result : s32 = x + y
	return result

SetDelegate(Add)

or

SetDelegate((const x : s32, const y : s32 -> s32)
	const result : s32 = x + y
	return result)

By encapsulating the entire function signature inside the parenthesis it is now very easy to add support for multiple return types:

GetAuthDetails : func = (-> string, string)
	return "username", "password"

const username, const password = GetAuthDetails()

My next big task is to address concurrency and multithreading.

There's More to This Than Unity

Over the past year in particular many of the graduates applying for programming positions at Tag Games have portfolios that consist, in their entirety, of Unity 3D projects. It seems that many of the applicants coursework, games and out of hours projects are made solely using Unity.

Now I like Unity; it’s a great tool and when used in the correct scenarios allows for rapid development of 3D games and prototypes. However Unity also has its flaws (like any tool) and despite popular thinking is not always the best solution for every single problem in game development.

What worries me most is that some (not all) of these potential candidates’ programming and game development knowledge starts and stops with Unity and even more alarmingly the industry seems to be encouraging this.

A couple of my colleagues attended the recent Develop conference in Brighton and one of the main themes of the seminars seemed to be use Unity for everything; it’s cheap, it’s powerful; why use anything else? Is the mobile industry becoming overly dependent on Unity? If Unity was pulled from the virtual shelves tomorrow what impact would that have on the App Stores? This may seem a hypothetical question but this kind of scenario has happened before most notably when RenderWare was bought by EA . Recent rumours even suggest that Unity were subject to a bid from Autodesk; imagine if Apple bought Unity and only licensed it to Apple developers, does that sound so far fetched? Imagine the huge blow that would deal the Google Play Store literally overnight! This isn’t just true of Unity, but the risks are magnified as many companies entire livelihood is dependent on a single piece of closed-source software and one that doesn’t have many viable alternatives. It’s one of the reasons why at Tag Games we have our own in-house engine that often wraps different middleware tools from FMOD audio to Bullet physics. If for any reason we need to switch middleware we can without have a huge impact on our game code (however that doesn’t stop us using Unity if the task requires it).

Obviously I am not suggesting that every developer should create their own engine; one of the main benefits of using a standard tools is that new employees are often already familiar with the tech. However the fact that so many companies use Unity is possibly one the reasons that so many graduates spend so much time learning the engine. In my opinion this should not be at the cost of general, core programming techniques. Unity should be a tool that people learn much in the way you would learn SVN and GIT or C++ and Python. If Unity no longer existed a candidates entire CV should not be reduced to nothing more than scrap paper.

When presented with a portfolio recently that included a lighting demo in Unity one of my colleagues asked what was so impressive, “doesn’t Unity do that for you?”. He really wanted to know if the applicant understood the algorithms for calculating lighting and the skills for programming an efficient shader but ultimately all the applicant had learned was how to add a light component to a Unity scene. Unity should be used for demonstrating high level achievements such as making a game or for showcasing techniques for which rendering is just an aside (if you are creating algorithms for mimicking realistic smoke you don’t want to spend 20% of your time creating a particle renderer).

Another issue with only developing in Unity is that candidates often only have a knowledge of C# or Javascript. Personally I like applicants to know a wide variety of languages and ideally with different methodologies (functional, procedural, statically typed, dynamically typed, etc) and I have no issue with them demonstrating only managed languages as long as they understand the pros and cons. I often inquire about why they prefer C# to C++, expecting answers such as it speeds up the development process; instead the most common response is that “you don’t have to worry about memory management” (*alarm bells*). Newsflash…when developing for mobile you ALWAYS have to worry about memory management (read this article if you disagree). Garbage collection is not a silver bullet it is simply one method of memory management. Even Android Java developers (as mentioned in the Android documentation) have to be careful with memory allocations. With languages, like every tool and engine, it is important to pick the correct one for job and to play to its strengths. Managed languages are great at reducing development time but at the cost of performance (particularly on mobile). Selection is always about trade-offs.

So continue to use Unity to make games and tech demos but also understand what it is doing under the hood. Understand the basics of rendering, shaders, scene management, etc and remember that contrary to popular belief not every company is using Unity. In-fact I’d wager that most games are still written in C/C++. I just wonder whether the mobile industry should be investing more time in open-source technologies in case EA decide to get their wallet out again!

As an aside I wonder if Unity themselves are finding it difficult to hire candidates with the appropriate skills?

The Unimaginarium of Dr Downie

Bored

For a long time I have wanted to make something cool. Something useful and unique that people would use and say “Wow, I’d never have thought of that”. Something truly special. In short I want to make the coding equivalent of Reggae Reggae Sauce.

However I have come to realise that I am an unimaginative, code monkey; and worst of all I’m OK with that!

This weekend I set out to make a quirky and elegantly simple game for the Ludlum Dare game jam and for the life of me could not come up with a single achievable idea. Much to my chagrin, one of my work colleagues produced a beautifully addictive and simple little flash game and most horrifyingly it is not the first time he has done so. I, on the other hand; can only seem to think iteratively. Take some existing idea and make it bigger and better. Even during the Tag game jams (one of which my team emerged victorious) our ideas are always creaking under the burden of their own feature sets and inevitably the time required to read the tutorial far exceeds the original development time. I seem to be much more “Zoom Zoom Zoom!” than “The car in front is a Toyota”.

Yet give me an idea or a design and I can provide simple, elegant and innovative coding solutions and derive a great deal of pleasure in doing so. The world needs artists and ideas but it also needs mechanics and brickies.

So until I stumble upon the next best thing has anyone got anything they need me to be getting on with?

It Helps to Know your Times Tables...

This week I watched a video called “What Most School’s Don’t Teach”. I actually only got about halfway through the video before I had to stop and have a wee lie down. I found the video to be patronizing, belittling and oddly a tiny bit smug?!? While having my little lie down I started to think about the sentiments behind the video and something that seems to be advocated by a growing number of industry bigwigs - should everyone learn to code?

Is that not the equivalent of saying everyone should learn to plumb or everyone should learn to engineer? In fact I think plumbing and engineering would be more useful than being able to program. Certainly if my job didn’t require me to learn to code I would be much more useful round the house if I could do DIY for instance. There is a reason that not everyone is a plumber or engineer or pilot or tree surgeon or musician and that is because these are skilled jobs requiring years of training, determination and commitment. Not to mention, more often than not; an initial aptitude. I’m sure you could become proficient at any profession relatively quickly but I wouldn’t trust a hobby electrician to wire my house nor would I hire a sometime pilot to fly my commercial airliner. So would I commission a hobby programmer to create an application for me? Would I buggery is the answer!

So if people aren’t learning to code to start a fledgling career as a software engineer then why are they learning to code? The first half of the video didn’t even approach a reason why. As far as I could tell the video wanted me to be a programming celeb, and not for the accolades or respect from my peers but because programming could make me rich! I think business makes you rich! Ideas make you rich! Steam, Facebook, Windows; these are all good ideas that filled a gap in the market. Programming is a means to an end and is often no better paid than bus driving, teaching or nursing. Most programmers I know fell into programming. They had a game they wanted to mod or make, they had a piece of software that didn’t quite do what they wanted it to. In short they had a problem. The solution to that problem required some programming. Programming is a means to an end; not a get rich quick scheme.

I have my own reasons why I think learning to code can be beneficial: I found it improved my maths skills by allowing me to think more laterally in order to solve problems. Coding allowed me to get a job in a dynamic and creative industry. Coding allows me to work with motivated and like minded individuals. Programming often gives me euphoric highs and in certain moments of epiphany a clarity that results in an underwhelming “Oh! That’s it”. On the other hand I’m pretty sure programming is responsible for many of my sleepless nights as my sub-conscious attempts to solve some half finished problem and when sleep does come often it brings the dreaded (and notoriously strange) coding dreams. For most software engineers coding is not something that can be turned on at 9 in the morning and off again at 5 in the evening. That being said programming can be fun (often masochistically so) and rewarding to those who persist through the initial trials and challenges.

The video states (and I’m paraphrasing here) that programming is easy. Basically no more than addition and subtraction! Certainly most programmers are by no means mathematicians and nor are we required to be. However I didn’t do 4 years of addition and subtraction at Uni I can tell you that much. Apparently you don’t even need algebra, communication skills or problem solving; who would have thought it! Maybe coding is easy for Mr Newell, Mr Gates and Mr Zuckerburg; but my experiences are somewhat different. Programming has stages ranging from ‘How do I do this’ to ‘How do I get this to work’ to ‘What is the best way to do this’ and each stage brings its own challenges and rewards. I would agree that the fundamentals of programming are simple, but simplicity and difficulty are two very different beasts. The difficulty in programming is making the complex look simple; much like a sportsman or a magician make a skill or a trick appear effortless. Striving for simplicity in a world of complexity, flexibility and change is a constant battle.

So do I think everyone should learn to code? No. Learn to code if you enjoy problem solving, if you like being part of an active community, if you want to make a game, a mod or an app. Learn to code if you love computers and have an aptitude for learning and a thirst for knowledge. Learn to code if you have a problem and no other solution. Otherwise learn to put up shelves and fix the washing machine…your partner will be much happier.

Hello, World!

Welcome to the new blog! Blogger served a purpose for a while but I finally decided to go with something that gives me a bit more control and allows me to unify the blog and my codefolio. I really let the last blog slide but I’m determined to post here more frequently and more relevantly! I’m going to use the site as a platform for hosting new ideas and projects and for sharing my opinions and experiences; at least for myself if no-one else.

With all that in mind I have some objectives for my posts:

  • Post at least once a month
  • Share experiences and tutorials
  • Always learn something (no angry rants that accomplish nothing)
  • Do something useful

Clearly this post is the exception…