Monday, 26 August 2019

Unix programming part 4 - The conclusion

The 'hunspell' was something missing from Code::Blocks itself so it had to be installed with 'brew install hunspell', but this again was something not mentioned anywhere. After that I think the installation was a success, but I think there was a problem with write permission which had to be fixed with sudo chown command, but unfortunately I didn't write it down.

So you would think everything went fine and I was able to run Code::Blocks? Yes... and no. Something went wrong with the installation and the entire C::B didn't work as it should. The worst problem is that it doesn't have a compiler and you can't even choose it from the compiler dialog, because it only has 'batch build' tab, everything else is missing! Not only that, you can't even load a project and source files, because the missing compiler. Code::Blocks tells the compiler "plugin" is missing which is a weird error message by itself. Also, all plugins are missing as well and they are not in the location where Code::Blocks is searching for them.

As I stated in the forums it would be great if someone else with Mac would try this and see if it works. There is someone who has pre-build for Mac, but he has not replied to my message yet. Code::Blocks developers themselves seem to be clueless about problems in OSX and they have said they don't have a dedicated OSX developer. But it doesn't seem to be a big surprise, because they haven't even cppchecked Code::Blocks. I ran cppcheck just from old habit and got bunch of basic warnings you should always fix before any kind of release. Obviously I got a reply that I should submit patches.

I have many questions but I doubt open source scene or unix style programmers has answers to them. Like for example why is everything so difficult for no reason? Why these projects (and this seems to be a common trait in open source projects) are not easier to build and have a simpler structure? It would benefit the developers also, so why make it more complicated than it has to be? I wonder if it's something people simply learn to do and can't even think about anything else. Still there are strange things like not using cppcheck for your own project. It's the obvious thing to do and if you don't use any code quality tools like cppcheck you are an idiot, there is really no other way to express it.

I don't know, maybe they are just ordinary people and the level of programming is simply lower than what I have. It seems to be the case with many open source projects, they are ok, but not great and often not in the same level as commercial software.

Sunday, 18 August 2019

Unix programming part 3

I learned something when researching terminal programming in unix-style operating systems. In order to run something when you are in that directory you need to use ./ prefix in front of the command. So for example wx-config needs to be called ./wx-config.

However this did not solve the problem I had with ./bootstrap not working. After some messages in wxWidgets forum it turns out I have to 'sudo make install' wxWidgets which is against the guideline in installation. If you run 'make' only it's enough for the library and you can compile and run examples. But this is not enough for Code::Blocks which requires 'make install'. This 'install' is something "more" thorough way to install the library, but it's not recommended if you work with several versions of the same library, I guess, because it's copying files under usr (system libraries).

Code::Blocks developers both failed to tell this in their forum and also they don't tell it in install docs to specifically override wxWidgets guideline and use 'make install'. If they had done this there would be way less confusion. I have to say that readme texts for installations are quite bad in both C::B and wxWidgets library, but wx is far better. It serves no purpose to be "elitist" and write vague, hard to understand documents for the program, library etc. and assume that people are experts in unix-style programming.

After all this frustration and being harassed at Code::Blocks forums I finally was able to run ./bootstrap. After that I ran ./configure --with-contrib-plugins=all for Code::Blocks and guess what? It didn't work. Great. I guess this is unix-programming. The error I get is:

configure: error: Package requirements (hunspell) were not met:

No package 'hunspell' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables HUNSPELL_CFLAGS
and HUNSPELL_LIBS to avoid the need to call pkg-config.

Of course I have no idea what that error is. What is package hunspell? Why it's missing from the actual source code package?

Wednesday, 14 August 2019

Unix programming part 2

In this part I'm trying to compile wxWidgets for Code::Blocks. There is a configure script of some sort which seems to be something unix programming requires. It's I guess telling 'make' how to build the project. The configure in readme of wxWidgets is lacking and doesn't work, because "SDK" has to be different. Searching from internet I gather these settings:

../configure --enable-debug --enable-monolithic --with-osx_cocoa --with-macosx-version-min=10.9

It seems to work and also when I type 'make' the project is compiled. There was one problem and it was a missing 'libtoolize' which confusingly is 'libtool' in homebrew (brew install libtool). It will install another libtool version with prefix b, but configure script knows this and is using b-version.

However... when I try to "configure" Code::Blocks with ./bootstrap command which is something C::B has to run first, I get this error: error: possibly undefined macro: AM_OPTIONS_WXCONFIG
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation. error: possibly undefined macro: AM_PATH_WXCONFIG

When I search internet it seems this is quite common error for whatever reason. The solution is this cryptic command:

export ACLOCAL_FLAGS="-I `wx-config --prefix`/share/aclocal"

But in my case wx-config is not found, it's not recognized as a command. There is wx-config "alias" file in the build directory, but I don't know what it is. Alias is I guess same as shortcut in Windows.

So, I went to Code::Blocks forums to ask about this, but they didn't know the answer and also I get a comment that I don't know anything about osx/unix programming. Well, yes, you are right. But neither do you guys.

I also registered to wxWidgets forums and posted a message about this, but since it's a first message it has to be evaluated by moderators, so we have to wait and see if someone there knows the answer. In Windows if you have precompiled library the only thing you need to worry about is 32/64 bit version of the library, but other than that this "compiling from source" is I think more rare in Windows and it sure seems to be an easier way to get things in the phase where you can work on the actual project's source code.

Sunday, 11 August 2019

Unix programming part 1

I have a Mac Mini as a secondary computer for music "production". Since OSX is unix based I want to see if I can compile something from source and also keep a journey of my experiences as a beginner in unix style programming. The project I want to compile is Code::Blocks, a well known IDE mainly for C/C++.

First thing I need is SVN. It's a version control system like Git. Since I removed XCode I don't have "Apple Developer Tools" which can be installed by writing xcode-select --install in the terminal. This is something I knew, although I wasn't sure if svn was part of it, but it seems to be. The reason I removed XCode was that it can't update itself through my slow internet connection without resulting to an endless loop, for whatever reason. XCode is quite a bloated program, I think the version I had was 6Gb download size. It's an IDE. It's basically a text editor with a swift compiler. Who knows why it got that large.

SVN command downloads the source and places files under 'trunk' in user directory. BUILD file tells you need to install wxWidgets with 'monolithic DLL' which I think could be a reference to Windows .dll which OSX doesn't have. But let's not think about that yet. First I need something called 'autotools'. Google gives an 'ad' page with .io extension I'm not going to click. There is a gnu page, but it doesn't seem to specify what "things" are in autotools. BUILD tells there are at least autoconf, automake, libtool, make, etc. The last two are part of xcode command line tools I guess, because they are found. For autoconf and automake I'm using homebrew which is another tool designed to help installing these "things". I'm not sure what else is in autotools, but I guess when I try to do something it's telling something is missing.

The next step is installing wxWidgets which is a cross platform GUI library.

Saturday, 27 July 2019

The day that would never come

Microsoft Visual Studio has been a great IDE and mainly the one I've been developing my projects, but recently I changed to Code::Blocks. It didn't take much for me to make the decision, because the way VS is developed seems to go downhill fast. Microsoft is breaking features that were always working in reliable way and it tells me their programmers just don't know what they are doing.

I never believed VS development would take such a turn to worse, but then again Windows 10 itself has had some problems with updates breaking things etc. It's hard to understand how this happens, but it must have something to do with quality of programmers and the way development is handled in Microsoft. When you have a renown software it's never guaranteed to stay that way. It's always possible to break it and I believe it is happening right now to Visual Studio for whatever reason.

Open source development is not safe from these problems, we have seen it in projects like Blender 3D which has had quite chaotic development style focusing on some things and leaving others completely dismissed. In that Code::Blocks is a bit different, because it is a decent IDE at least in Windows (OSX users tend to disagree) and has only few problems or missing features I guess. The developers seem to know their stuff and it's possible to harass them directly in the C::B forum which is nice. This is another thing Microsoft is doing completely wrong. Their feedback "forum" for Visual Studio is a failure where your question is quickly buried under thousands of messages and answered by cut-paste indian people who don't understand anything about the IDE itself.

I'm probably going to check out VS in regular intervals just to see what they are doing to it. The way I've set up my projects allows me to switch between IDEs, but I guess it can be dangerous now when you are not sure what VS is doing to your source files. Then again I always do backups as you should and in VS's case really need these days.

Friday, 5 July 2019


Taking off some time from my other projects and starting a new one. With this I'm going to follow different rules than before. It's a traditional RPG rather than a roguelike, but it's going to have some random things. The actual idea is in the implementation with these rules:

1. Completely class-based without public data (only public interface).
2. Inheritance first design.
3. Everything is programmed as a function to a required gameplay feature.
4. External data with parsed dynamic instances.

I think rule 1 is going to be broken in some places, but not inside classes. Mostly in global instances I guess. I think 3 will be an interesting one, because it's the opposite I've done this far. I've always added features without planning them that much and maybe it's one of the reasons I've spent a lot of time wondering how to put everything together.

Saturday, 29 June 2019

Class design tool

I learned today that there is a class design tool in Visual Studio which took some years to figure out. It's not a built-in part of VS2019 but should be. Seeing the class hierarchy in visual level shows "problems" in inheritance very clearly. Although the class hierarchy can be anything you want, but often a tree-like hierarchy is better, from simple to more complex classes.

There are huge stacks of single use classes in both Kaduria and Teemu which looks kind of funny. I think with this new tool it's easier to fix class hierarchy and it's going to be my short term life goal for sure.

I don't yet know what to do with Teemu's github adventure. I actually hate github and source control, because as we saw anything can happen. I feel it's also unneccessarily complex system, but that's typical in the linux/open source scene. Everything is super complex and obfuscated for no clear reason.

Thursday, 6 June 2019

Github failure

Suddenly out of nowhere Visual Studio's github extension reset project files of Teemu (sln, vxproj etc.) to beginning of the project, removing all paths and settings, even to a point that it added already removed files to list of files going to github.

In response I removed github extension, because I still want to develop my projects in Visual Studio. It's still, with all its flaws, much better than let's say Code::Blocks. But since I can't really use or trust github extension it had to go.

I know there are github gui's for other than command line use for github, but it's unclear if I have to remove the current github project and start a new one. After this I've been thinking twice about source control. Yes, it's probably a good idea, but what if something goes wrong? It's feels less reliable now when I know it can change files for no obvious reason. What if it changes some random source files and you can't figure it out until days or weeks later?

Saturday, 1 June 2019

Teemu at Github

Teemu can be now found in github: in its development state and also later as finished version 1.3.

If you look closely you can see it has grown from the previous version and there is even an attempt to create a role-playing system in it.

Tuesday, 28 May 2019

Realtek LAN problem solved

Remember the Asus Prime H370 Plus' Realtek Lan unable to connect to internet? The actual problem was that not even Asus knows the lan chip in their motherboard is Intel I219V, not a Realtek. The installation program in original driver CD has the proper driver and I found out that just by trying it, even they often have outdated drivers. The new computer doesn't have a CD drive, but my old has, so I copied everything from there to usb stick.

I've been thinking to create just one blog for my ramblings, but maybe later. The new plan for Teemu and other projects is that Teemu is going in github, but maybe not Kaduria, at least not yet. Not in the development stage. It makes more sense, because Teemu has always been "open" source (the source code is available).

The new PC is nice and fast, but it still does have couple of problems. Since the case fans are DC type (three pin) they for some reason can't be set less than 800-900rpm so they are quite loud. The processor is running average 30C temp, so it's cold and I guess doesn't need case fans to run that fast. So I need to get quality PWM case fans. Another stranger thing is that when I turn on power from switch outlet the lights in the keyboard lit and they stay on (caps and scroll lock lights) until computer is turned on, then they start to work as usual. It may be even some kind of grounding issue, but I have no idea what it is. Related problems when googled are opposite, when people turn off the computer the keyboard lights stay on. But in this case the computer is not even turned on, just the power.

Saturday, 18 May 2019

Hardware problems

I have a new computer, a tabletop PC I built myself. I was surprised it started the first time and everything seemed to be ok, but then Windows 10 failed connecting internet. The problem seems to be Realtek's LAN and/or Windows. Obviously I tried to find a solution, but nothing seems to fix it. Reading other people's experiences I'm also going to try a LAN card which is going to have Intel's chip. In fact my current PC has Intel's LAN and I never had problems with it.

This is one of those strange things about PCs and hardware. How hard it would be for OS to figure out what exactly is wrong? Windows 10 doesn't really help that much, it just says the driver is not installed. When I install the driver from motherboard's site it doesn't do anything and the driver installation software is giving another error which tells it's not connected. It is and the cable works in my older computer. Maybe the cable or router is too old? No. It can't be. We'll find out about that when the card arrives in couple of days.

I'm really bad at working with hardware. I just want the computer to say it's ok. I spent a lot of time learning about new PC hardware just to be able to select proper parts that fit together. I don't know about the motherboard, it sure does look like it was not the best one to have (Asus Prime H370 Plus). Then again when you build from generic parts it's easier to change them. I even got a retail Windows 10 which means it's not tied to the motherboard (oem) so I can in theory change everything.

I also hate the way internet is full of "information" about how to fix these problems, because in most cases it's just noise. It's so hard to find actual solutions. I think the best one I've read this far was to remove memory and install it to another slot. You know, to fix that LAN port. I think the companies who build this crap should give us confirmed user stories how these have been fixed, but it's not likely, because companies like Realtek are way too large to have any kind of connection to regular computer users. I don't even want to talk about my bad experiences with computer repair, it's just not worth it to send a defected motherboard to repair. You have to remove it and wait for several weeks for it to come back with a note that it works.

Wednesday, 8 May 2019

How other languages can help

Wish I had tried other programming languages way before. I knew what Basic is, because it was my first language contact back in the 1980's. But then I moved to C and later C++. Recently I have tried out languages like D, C# and most recently Go. I think they can help by giving back more motivation to work with C++, because most other languages suck.

Yes, they suck. Even though C++ is far from being a perfect language it has the least amount of suckage.

So what is the problem with other languages? It's often not the theory behind the language, it's the implementation of it which should give the developer more or less painful access to things like graphical output. Yeah, about that... It's mindblowing to realize that the main output type of languages like Go is text output in the terminal or console window. There are external gui libraries, but in case of Go they are quite difficult to install/use and also they are bloated because some weird reason the language works. Maybe it's the garbage collection memory model or something like that.

I guess some of these languages were never designed for desktop use, but then why do people still ask why C++ is the most common language when the answer is obvious. It's because you can actually write desktop software in C++, even it's an ancient language and GUI support is quite bad with bloated antiquated gui libraries like wxWidgets. The point is it's still better than anything else.

Not only I'm sick and tired of all those things, but then there are people who religiously defend some sucky language like Go. Don't these people have anything else to do, like write actual working computer programs. They never do that, because they can't.

Wednesday, 24 April 2019

Visual Studio 2019 first contact

The install procedure as side-by-side version was smooth. Sadly the installation is the best part of the new Visual Studio. Let's list the things I didn't like.

1. Everything is slower in noticeable way. Solution loading is slower, the editor also and compiling. It's less an issue if you have a modern PC which I don't have.

2. Automatic formatting of source code by default. I just don't like it. Why not leave everything off and let the user add formatting as needed?

3. In some cases when you press arrow up it doesn't go up, but warps to the end of the line, for unknown reason. Didn't yet figure out how to turn that off.

4. The already infamous extra horizontal toolbar area under the menu. No one needed it, but there it is and of course you can remove tools from it, but not the bar itself and "live share/feedback" buttons. I think the feedback button will be used to give feedback about this feature. Everyone who is actually programming knows that you need vertical space for text editor, but this strip is taking 2-3 lines of code away for no reason at all. At least make it optional, it can't be that hard to do.

I really hope Microsoft isn't slowly crapping VS, because it's probably the best piece of software Microsoft has ever released. Even with these new features you can work with it, it's not that bad. And there is no competition so you have to take it.

Sunday, 31 March 2019

Daemons everywhere

Banana Rogue has already 6 files that compile which can be seen as a minor success. It tells that once you get old C translated to C++ compiler it will be "fine" if we forget about memory management problems of C like raw arrays etc.

Function pointer stuff in daemon and daemons modules doesn't work, because the function signature has to match the pointer in C++ which is more strict about types. If I'm lucky it will be fixed by changing all 'void' functions to 'int' return value, even if they don't use it. Or check out if the functions actually are all void type.

The gui refactoring is almost ready. Most of the action happens in Window (previously WINDOW) struct of curses which I replaced with a class. Window is used inside io module through procedural function wrappers which makes it "easy-ish" to replace later with other type of implementation. Everything works in ascii level, the Window is simply a rectangle of ascii data. It's quite brilliant. The only connection to SDL2 will be Display which shows the window. Then also you need SDL2 in keyboard routines which are also simple in case of ascii codes. There will be some complications if you want to use modifier keys or any special keys like arrow keys, but it can't be too difficult to fix.

The rest of bigger problems are in save game routine, options module (which can be easy, I have skipped it) and linked list routines. The internal type for linked list data is surprisingly char* which is a mystery, because malloc itself is void type or typeless.

Saturday, 23 March 2019

When otherwise

The strange 'when' keyword was just a macro for break;case pair which I think is cute. I may even keep that macro, but some macros may have to go. Oh, I'm talking about Banana Rogue, a derived game from Advanced Rogue. I've now gone through source files and mostly created missing header files. Somehow it was possible to compile the source without header files back in what year it was made, because they weren't missing from the source, otherwise there would have been #includes for them, right?

The year is also a mystery (well, guess I could google more about it...) because the source says it's 1985, but it can't be that early, right? Also, the xcrypt source code which is some kind of strange encrypting method for wizard's password is from 1994. I think 1990's is much better guess for this game, they just didn't put it into the source code, but kept some random year, maybe the year they started to work on this game.

Xcrypt can be removed, because it's used for networking (password) which is going to be removed also. The system they programmed this had some kind of built-in networking, this was I think before widespread use of internet as we know today.

What is quite surprising is how clean the source code actually is. There aren't too much parameters in functions and the game has only few datatypes. Probably the most dangerous one is the linked_list which is as mentioned before a linked list type and when you combine C's memory management to that it could be a source of bugs. It's maybe too big task to replace it with C++ version, but it's early to tell. Maybe the internal implementation can be changed.

I'm not too concerned about "destroying" the original source code, but at the same time it's silly to replace everything that looks "bad" from C++ perspective.

Sunday, 17 March 2019

Banana Rogue

The license of Advanced Rogue tells you can't use name Advanced if you derive from it so the project name could be Banana Rogue and in the story you work in a banana plantation, but want to escape hard working conditions in nearby deadly dungeon which sounds much better option.

I found rnd() function from main.cpp and it really looks like main could need some cleaning up. There is some kind of "network" code which is going to be removed. Also, there are signal handlers in case the program crashes which makes the player die from bug. I think it's better remove those also, because if the game crashes it's better to make it possible to load the game from possible existing save game.

This project really needs a gui module and there is already io.cpp which has things like msg for message output, but it could have everything gui related in it. I think the game doesn't have a "level" structure but it has at least four WINDOW arrays (which work as layers) which I think are from missing curses library. They are simply char arrays if I'm interpreting the code correctly.

I found another 'when' keyword switch-case which has the first keyword 'case' but the rest are 'when'. It's quite baffling, because I can't even find any mentions of 'when' being a keyword in C.

Saturday, 16 March 2019

Confronting a vast cosmic mystery

It might be possible that the random Advanced Rogue source code that I downloaded from somewhere and started to work on could be obfuscated. One clue for this are the missing function declarations, but I've also seen a switch - case with two 'when' keywords. Or could it really be possible that it's written in some kind of special version of C?

Anyway, rather than trying to compile one file at a time (which is still not even possible) I've started to re-create header files for each file with functions it has. There are some functions that has to be replaced, but luckily more modern alternatives are possible without changing the call style. One of those is msg() which has a vararg style parameter list, but the syntax is different than it will be in the "modern" version and also I'm probably going to change the internal implementation to std::string, because it just looks like it's better that way.

The number of datatypes I've seen this far is reasonable, it's four: coord, object, thing and linked_list. The last one is a manual linked list as the name implies and it could be heterogeneous through void pointer magic, but I'm not sure yet. But it's using macros to allocate memory for objects. I'm not sure if it's useful to replace that with something safer, at least if it actually works.

Friday, 15 March 2019

Advanced Rogue

I was reading the source code of Nethack one day and noticed that I can also read source code better these days, mirroring my increased skills in programming. So I downloaded the source code of Advanced Rogue which I think was last updated in 1985. Rogue had quite a number of variants just like Angband later, but I've never played any of them.

The source code of ARogue seems to be quite small, but it's also old school C which means that weird way of writing function definitions and declarations. The plan is to rewrite the source code to C++ (not OOP, but keeping the procedural style) just for fun reasons and I've already on the way. Another "problem" I guess is curses which is an external library used in ARogue and it's not included, but can be replaced with SDL2 gui. It's possible that curses has also changed during all these years, so it's probably not going to work just like that. However I could even keep the old function names so in theory it's possible to replace SDL2 gui with curses, or whatever.

As a small mystery some functions are defined, but not declared in any of header files. Or in this case rogue.h which is I think one of the two header files the project has. Creating header files for functions defined in a .cpp file is another task in the list.

Other than that I think the majority of old C code should run in a modern C++ compiler, but we'll see it later. There are lots of pointer stuff in ARogue's source which can be a problem and also I'm going to replace memory management routines with C++ code.