Programming for fun, not profit

Back in high school I liked writing programs.

But all I knew was BASIC.

I’d like to toy around with programming again. I have absolutely no ambition here, I just want to get a feel for a contemporary computer language (or two) and write some toys.

What kind of toys? I don’t know. Back in high school my crowning achievement was writing a “Tron” game (no AI) and that would be kind of cool.

If I could try my hand at an AI for such a thing that would be cool too.

No fancy graphics necessary for anything I want to do.

I also used to have a program (a little later) that let you program a kind of a “robot” to fight other robots.* Is there anything like that around today which models itself after contemporary programming languages?

-Kris

*Boring story about that. I tried to write a sort of ‘evolving’ program somewhat as follows. (I don’t remember the exact details.) I wrote a robot program which concerned itself mostly with defining a way to interpret a set of symbols in a line of data as robot instructions. I then gave two versions of this robot two different initial lines of instruction-data, and let them play a battle. Each robot would then randomly change one bit in its line of data, and fight another battle. Each robot would then compare its performances in the two battles, and “mutate” one bit from the line of instruction-data that version of it had used, and fight the next battle using this mutated version of itself. Next it would compare the new performance with the performance of the version it had spawned from, and make a mutation from the better performer, and so on.

(I’m making some of the above up because I don’t remember exactly how the language worked or how my robots worked, but it was something along the lines of what I’ve described. BTW the program in question was called “Robot Battle.”)

It pretty much did what I wanted it to, in the sense that it did the whole comparison/mutating/fighting cycle correctly. But evolution did not happen. I just got a bunch of robots that stood there doing nothing. Even after one million battles, played over a period of 24 hours or so, nothing interesting evolved. Ah well. Seems like it could have worked. :confused:

There are any number of great, free compilers and interpreters out there. Chances are you already have at least one installed on your machine (your web browser probably includes a Javascript interpreter - you can do a whole lot of fun stuff with that).

Here’s a good place to start looking:

Microsoft have got lots of free development tools available here

http://www.microsoft.com/express/

What you described is a genetic algorithm, and yes, they do work, albeit very slowly (they’re essentially hill climbing algorithms). The problem you had probably had to do with your low population size (only two robots - try fifty, it may converge a lot quicker).

I’d suggest either Java (or C#, they’re nearly the same, but C# has more features) or Haskell. Those are what a lot of universities use to teach first year computer scientists about programming.

What about Python , and the PyGame framework. Easy to use, easy to read (the language syntax enforces readability) and very popular.

IDEs are available for Windows, and ActiveState have a really good package.

Si

Good for you!

I second Dominic’s suggestion. I took up C# earlier this year and have had a great time with it. I keep thinking, Wow, that’s a good idea, what a clever way to do that, I can see how that would be useful, etc etc. Microsoft has a free version of VisualStudio on their web site, with your choice of compiler, and C# is one of the options.

Also, I keep seeing books about game programming (in which I’ve never been interested), in Borders and similar chain bookstores. It looks pretty easy to dip your toes in that water.

I would emphatically not suggest trying to take up Haskell. I’m an experienced programmer and I still never been able to fully wrap my head around the concept of a Monad. If you’re going to go the functional language route, ML is quite similar to Haskell in terms of syntax but I think that it would be much easier for a beginning to pick up.

On the more traditional imperative side of things, Python is a popular suggestion these days(personally, I’m not a big fan but then I’ve never actually used the language). I like Java but I’m not sure how good the libraries will be for hobbyist stuff.

Python is cool. It is really powerful. You can do things with it in 15 lines of codes that might take 150 lines or even 1500 lines of code in other languages. I wanted to learn a new programming language about a year ago and I picked Python. Like you, I had no pint in mind. Even though I work in IT, we don’t use anything close to Python around here.

I work in IT, and we actually DO use Python a lot, specifically because it’s so easy to write new tools in that language. As one of my colleagues once said, “Any task you give me, I can write in Python in half the time and one quarter the lines as it would take me in C.”

Ed

I second or third Python. It was what got me back into hobbyist programming after a long hiatus - I kind of dropped out of coding when object-oriented languages came along. But Python is fun and easy to code in, and I was creating my own classes before long. Features like list comprehension are cool and were new to me.

And the language is interpreted, so you get instant results and can try things out interactively. But it’s powerful too, there are big, serious applications out there written in Python. Modern IDEs are so far ahead of what I used to use years ago, too. They do take some of the drudgery out of coding.

I wrote a neat little card game in it as a sort of familiarisation exercise. Not using PyGame, which perhaps I should have, but the more general purpose wxPython, with which you can easily create cross platform applications.

Thanks for the suggestions everyone. I think I’ll look into Python first.

-Kris

Indeed, as I said we use Python as well as C where I work. Python for all our new coding because it’s so much easier. Yet we make large applications out of it. I just checked and one tool has over 10,000 lines of code. (In C it probably would have been 60,000 lines.)

Ed

I have a question for the python lovers.

What the hell possessed the creators of python to give white space syntactical meaning? This bugs me a lot. Didn’t they learn their lesson trying to figure out what was wrong with a makefile?

Other than that it seems like a pretty decent language. I really like the high precision math part of the language. That is a really useful thing to be put into a language.

A makefile? That’s something you use when you have to compile programs before they can run, right? :wink:

gazpacho, there’s a great book out there called The Best Software Writing I: Selected and Introduced by Joel Spolsky, and the 1st (I think) essay is about why we should enforce whitespace convention - as in prettyprinting - in languages as syntactical and not just stylistic. I loved this essay and most of the book.

The idea is that following a good and consistent whitespace convention is very helpful in understanding what you write and relating it to what you mean.

The downside to most languages is that whitespace conventions aren’t syntactical and so they represent a whole separate channel of information that we’re supposed to manage and the compiler’s supposed to ignore. So, why not speak the same language, and use the whitespace we’re already trying to manage?

Sounds like a good idea to me - though I don’t use Python.

I dabble with a little Python for my XBMC stuff. I hate it. Godforsaken white space actually meaning something. Makes me think it’s a learning tool, not that there’s anything wrong with that (I miss Object Pascal with a passion).

Because I only dabble (with other people’s code, at that; no from-scratch projects by me), I have a hard time understanding why it’s easier and/or faster than other languages (not including C; I’ll give you that). Is there a standard library that abstracts a lot of things, or is it just more compact in the sense that Objective-C or Pascal, etc., is more compact than C? Hell, everything’s more compact than C for all but STDIO stuff.

I read that article Napier. It made some good points. I think he is over estimating the costs of people working on the project with competing styles.

I guess my real complaint is 8 spaces could be seen as different than a tab.

Obligatory Python link.

There are a few systems out there that do more or less what you described in your Robot Battle program. Core War and its variants are probably the most direct implementation of the concept. See Core War - Wikipedia if you’re interested.

As for programming languages, I would recommend you use a high-level language that’s reasonably well structured, lets you develop quickly and supports multiple paradigms (especially, it shouldn’t force you to do everything in a functional or object-oriented style, but it should support both). As far as I’m concerned that means Java, the Visual Basic variants and C# are out. If you’re thinking of ever switching to a Mac or Linux VB and C# should be out anyway.

Python has been mentioned here a lot, and it’s probably a good fit; it’s fairly fast, easy to develop in and has a pretty large number of extension libraries (so when you decide you do want fancy graphics, you can). It also seems[ to be fairly newbie friendly.

I personally like Ruby better than Python, but that’s really because I think Ruby looks better. Ruby seems to attract programmers that want to warp their language into doing crazy things, while Python seems to be much more strict in how you should implement things. I’ve only used Python a little bit, so I may be wrong.

The main point against Ruby is that the documentation is OK but not great (so you do need a book to get a handle on it) and does not really care about being “safe” for “inexperienced” programmers, only that everything it can do should be easy to do. All the really cool/subversive stuff is right exposed and very tempting to use (and hang yourself with). For some people (me included) that’s a big plus. For others, not so much. I know experienced Java developers who are absolutely horrified about Ruby.

:smack: Sorry, Core Wars does not do what you’re describing at all. Still, you may want to check it out. It’s a very interesting take on “programming for fun”.