Sunday, 29 March 2015

Overcoming Introversion

I don't want to let this week go by without posting something. Last week was a reasonable exception as I was away traveling from Friday to Monday. Also sick for a while as well. I doesn't do to get back into bad habits of procrastination. I'll just have to deal with the guilt of not having something good to post this week.

I did spend time on some coding though, been looking into the Java programming language and have to grudgingly accept that it is a useful tool. Object Orientated Programming; where you treat the building blocks of a program as discrete objects fits my way of thinking about parts of a program quite well. This part is the display, the routine to update the program state goes here, this is the map data and here are the mobile units upon it. My way of writing code was a weird mix of objects and functions and I can see why purely having objects would be effective.

As far as I can tell, to make the most use of objects they should be self contained elements which handle all their own updating of state and displaying on the interface. All they should present to other parts of the code are methods of getting and setting internal, private variables. This makes the objects highly modular and enables all kinds of useful ways of using inheritance to take one kind of object with many methods and then add a few more for and extended object to implement the functionality you need. The Java swing graphical user interface library has been perfect for this.

One concept Java has been most useful to explore has been networking, by importing libraries for setting up internet connections and creating separate threads to handle different processing tasks which all need to be run at the same time you can do some fantastic things. Doing the same in C required learning the detailed structure of TCP/IP protocol and Javascript, by its nature as a web-page scripting language, is suited to communications only with the server that is hosting the page. With Java I have been able to get something up and running without having to understand exactly how it works, not how I'd do things ideally but getting something functional is much more rewarding than getting mired in implementation details.

Unsurprisingly the first idea I had for using networking was multiplayer games. It also gave me a great opportunity to play around with lots of different objects for the many parts of the code: the server that runs the game, the clients of which there can be an arbitrary number, the game objects running on the server and the representation of those objects data on the client. I was a rewarding organisation task and kept me occupied for awhile.

What I produced worked and was reasonably extensible, sadly its all in Java code so I cannot do what I really wanted to and post it here. I had hopes of setting up a Javascript client to post here but that relies on having a working server backend. I haven't worked out how to create a server so that it can be accessed from anywhere on the internet (it involves scary things with routers and port forwarding) so my motivation has sunk. What was really keeping me going was the prospect of sharing a game with friends but getting the program to that state takes a lot of work. Work that I feel guilty for not spending on other aspects of life.

I feel guilty about wasting time on these hobby projects when my life is in such a mess. Better to post something to try to gain some satisfaction from it rather than clamming up completely.

No comments:

Post a Comment