Entries Tagged 'python' ↓

vestigial syntax: programming languages don’t need tails anymore

This weekend I was helping out a friend when he pasted me some of the code from his latest project that happens to be written in C#:

(the only change I’ve made was to rename the identifying feature to XYZ)


namespace XYZ.Core
{
    static class Entry
    {
        static void Main(string[] args)
        {
            using (Game game = new Game())
            {
                game.Run();
            }
        }
    }
}

I know that monitors are getting bigger and bigger, but vertical space is still a precious commodity, so let’s try turning the above code into something that looks more like


namespace XYZ.Core

static class Entry:
    static void Main(string[] args):
        using (Game game = new Game())
            game.Run();

This code is shorter and easier on the eyes, and I’m even ignoring the whole issue of having a class that simply has a static void main, as the authors of the cool Boo language point out, the people who came up with “public static void main” were kidding, it’s just that a few million Java/C# programmers didn’t get the joke.

For those of you that didn’t know where this was going, the above is just a few steps away from being valid Python (or for you .NET junkies perhaps Boo). Other people have addressed the myth of significant whitespace and I won’t go into great detail here, but I will say that Python essentially injects INDENT/DEDENT tokens that function in the exact same way as { and }.

What is often used as an argument against Python and other indentation-scoped languages is therefore really an advantage. {} are no more useful than the human appendix or other vestigial structures, the only reason that modern programming languages have them is that they inherited them.

If languages like Java/C# thought it was a good idea to free themselves of explicit memory management why not also free themselves of useless syntax that does nothing but clutter up code?

This divergence seems to only be growing wider, with languages like Python already free of these vestigial quirks, whereas languages like C++, Java, and C# continue to make their syntax more and more obfuscated. (eg. the tortured C++ lambda syntax)

This discussion on what syntax could be thought of as vestigial sparked some debate, some other potential candidates others suggested include the ++/– operators and PHP’s use of ->. I’d love to read comments with examples of other developers favorite vestigial syntax.

edit: A commenter over on reddit points out that the Lisp community had this right years ago. It does say something that one of the oldest languages is so free of the cruft that the traditionally more dominant curly-brace family has adopted. The idea that those who forget lisp are doomed to reinvent it is surely at work here.

Popularity: 9%

a spring update

If you’re one of the 20 or so regular readers, you noticed that the theme here just changed. I went with something a lot simpler than the other theme. Hacking on the previous theme became tiresome, I’ve switched to the much more generic copyblogger that is known for it’s clean code and therefore is easy to bend to my needs. Another mistake I made with the previous theme was not keeping my changes in revision control, so now all my changes are in a bazaar repository. If you have any trouble with the new site post a comment here and I’ll take a look at it.

I also wanted to take a minute to plug Steven Jackson’s blog here, which has been added to the blogroll.  I should have had this on here earlier, he’s one of the developers I correspond with the most, and someone I run ideas by constantly.  Most of his content is gamedev/gamedesign related.  I know Steve from my sordid past as an member of the amateur game development community, he’s a freshman in college but has a pretty impressive skill set, and is one of the most determined developers I know.

As he mentioned on his blog I was working with him on an entry in PyWeek 6 which I’m sure even though it was my idea was somehow his plan to get me back into gamedev. Neither of us ended up having the time we would have liked to complete our idea, but we’re still talking about following through on it.  It gave me an excuse to learn Pyglet and Cocos, two excellent python libraries.  Most likely something (whether it’s our initial game or not) will come out of my having picked them up.

(This would also be a time to give a shoutout to his indie gamedev shop, Snowfall Media, that he’s set up with one other developer.)

Popularity: 6%

C++: I’m not coming back

For a long time my primary language was C++. I know this is uncommon for someone of my age (21) but C was actually the first language that I learned. (Keep in mind although this wasn’t that long ago, it was hard to find good advice online so I bought a book on a language I’d heard was commonly used and spent a couple months digging into C.)

When I went to college I had to learn Java, on my own I got into Perl, Python, and Lisp. I fooled around with PHP, learned to respect Javascript as a real language, and even wrote some Ruby. When it came time to explain what I did to my then-girlfriend it was Python not C++ that I helped her write a small game in.

Despite all of this linguistic infidelity I have faithfully kept up to date on C++, following the draft standard and reading Herb Sutter’s fantastic GotW. But something that’s been coming a long time happened when I read GotW #88: A Candidate For the “Most Important const”.

In this posting he discusses the difference between assigning to a const reference and a non-const reference. Spoiler alert: in the examples he provides it is only legal to assign to a const reference.

I’d actually played around with this “feature” so I was still able to follow along, and then it hit me. I simply don’t care.

I used to think that part of programming was memorizing these syntactic quirks (be sure to put a space between the >’s in a nested template declaration!). As a C++ developer I always kept them in mind but accepted them, surely other languages must have their own. I suppose this is still true, and a handful of others do come to mind.. but what has changed in my way of thinking is that they are a necessary part of a language.

So getting down to what I need to say.. C++, I know when I put you down years ago I said I’d be back - that these other languages were fun but you were the one for me. I just think we’ve grown apart, it’s best we both move along. It’s time I made an honest language out of Python and admitted I’m a Python programmer.

Popularity: 6%