Sunday 18 February 2018

Language design: class

With my limited intelligence I had an idea to start designing my own programming language. There are some examples of the syntax in Roguetemple forums 'My language' thread that has had zero interest. I don't know, I'm pretty stoked about programming languages.

When it comes to really important stuff in a language it's how to manage data with functions and/or classes (or something else). My current understanding about class is that it's a nice theoretic idea which most often simply breaks in real life situations. That's why we have those getters and setters and the class can be exposed or it's not going to be neatly modular piece of code. Also in my experience inheritance is way harder than people think at first.

Functional style has different way to handle data which also is highly theoretic when you think about so called pure functions. In reality most functions are what experts call procedures in that they change whatever data is input to them.

My vast experience tells that both classes and functions have their problems and also both work better in different situations. The obvious question when designing a new language of course is there a way to solve those problems in some way? Or do they even need to be fixed, maybe they simply always exist no matter how you try to prevent them. It's like removing pointers from Java, did that actually fix anything important? Sometimes languages try to prevent the dumbness of programmers and they take it maybe a bit too far.

I've thought about one way to relieve data handling with something called resource block which is a collection of data that can be optionally limited to some classes. This data is like static data in C++ that it's initialized when the program is started, but it could be possible to change it. I'm using that kind of data in my C++ projects all the time, but there isn't any kind of built-in way to handle that data in C++, you have to use namespaces to hide it etc. By the way, I don't think I'm going to have namespace in my language, because I think it's fixing a problem that should not be a problem in the first place.

Thursday 1 February 2018

The daily maze news

The maze routine itself works, but it has to match in the rest of level creation. The way I accidentally solved it in the labyrinth level (the only level using maze for now) was make the maze routine "continue" from itself, the tiles it has created in previous "hives". A hive is one instance of maze diggers which are the corridors of the maze left by replicating diggers.

Sometimes it happens that everything runs into a dead end, usually a digger winding on itself. The fix for that is create hives until X number of tiles created. I found out that the number of available wall tiles divided by 3 gives a good result. The reason for that only roughly 50% of maze area is floors, the rest of it is walls. Not a surprise there. But if you divide it only by 2 it seems that the routine can't fulfill the requirement of mazes to create and runs into an endless loop.

There are some questionable things in this method where I'm first creating couple of rooms and then shooting mazes from walls of those rooms. Most important question: are rooms always connected by mazes? For number of test runs it seems to be true, but I have a feeling it could fail in some rare situations. If it happens it's still possible to check each room for connections and create them later with manual style, but I'd rather wish the maze routine work in reliable way.