Godot and C#

In my previous post, I wrote about my hobby project with Godot.

Limitations of GDScript

But I personally feel that, Godot script, namely GDScript, is not my favourite. Though GDScript is good enough to do anything, it is not what I like. Firstly, it is Python-like language. In my opinion, using indentation as scope is annoying, because I cannot auto-indent using Emacs. Due to my first programming language is C, and heavy use on JavaScript, braces (curly brackets {}) are easier to read.

Besides that, GDScript doesn’t have array operations similar to JavaScript, such as forEach. C# has List class with ForEach method. There are similar methods like map and reduce using LINQ.

Moreover, C# supports lambda expression. This is which GDScript cannot support. Even Python cannot do multiple lines lambda expression.

Comparing C# and GDScript, C# may be slower for development, but learning C# will be more useful than GDScript, as C# is a general purpose programming language. And C# has richer syntax.

Another reason I choose C# over GDScript is the testing. As a web developer, TDD (test-driven development) is a useful approach to make the product more stable. Development in GDScript doesn’t allow me to test my functions by writing test cases. If I choose C#, I can install Machine.Specifications (or MSpec) and Fluent Assertions through NuGet, then write the tests.

In fact, Godot supports native script using GDNative. This allows you to develop your module using C or C++ language. I like C and C++, but they are less efficient comparing to the modern programming languages. They are inefficient for development, as there is no garbage collection. Smart pointer is not garbage collection. However, C++ is acknowledged as best language for game development, according to Google Search.

Setup Godot Mono in Arch Linux

This section is Arch Linux specific.

Firstly, read this, and install godot-mono-bin. Secondly, install MonoDevelop and msbuild (msbuild-16-bin).

Once using Godot Mono to create a project, a solution file (.sln) and a project file (.csproj) will be created. These files are compatible with MonoDevelop. If you cannot open, probably you are using wrong version of msbuild.

To setup .NET Core in MonoDevelop, go to Edit > Preferences > Projects > SDK Locations > .NET Core, edit the location of the dotnet CLI as /opt/dotnet/dotnet, it will detect the SDK and runtime automatically.

Note: /usr/bin/dotnet cannot work, because it is a script.

Then, you can build your C# module using either MonoDevelop or Godot (Mono support). One great thing is, we can use both C# and GDScript together in the same project.

About NuGet

Unluckily, not every package manager acts like npm (Node) or bundle (Ruby). To install packages through NuGet, best approach is to use MonoDevelop.

Best web application framework I like

So far, in my opinion, Ruby on Rails is the best web application framework that I have used. Compared to others, it is very complete (by installing extra gems) and mature, provides everything that I need.

Version manager

There are two version managers: rvm and rbenv. I prefer rvm. It allows to work on different projects with different Ruby versions. Node has similar manager, nvm. Python has similar feature, but acts differently, using venv or virtualenv. In Python, we need to install the specific version, and create the environment by specifying our Python version. Contrarily, rvm or nvm will download and build the corresponding version.

Lambda expression

Ruby supports lambda or anonymous function, which can also be seen in JavaScript, as callback function. Newer languages such as C# and C++11 also support the syntax. The syntax is so useful when handling array. Python can support lambda expression, but it cannot support multiple lines like JavaScript.

REPL

Ruby on Rails has also very powerful REPL. With rails console, you can access the models easily, and manage the database through models.

Node can do similar, but it requires to write the script to setup the context. Meaning, we need to write the script so that REPL can access the controllers and models.

Debugging

Debugging in Rails can be done like client side JavaScript debug keyword, which require byebug gem. By using pry-byebug, we can debug the script line by line easily.

Migrations

Migrations and ORM in Rails simplify the development, as we need not to take care how the database should be structured, but focus on the models design, especially relationships like one-to-one, one-to-many, and many-to-many.

Migrations is commonly used in various web application frameworks, including .NET, Django, Laravel, etc. Node can implement migrations using sequelize and sequelize-cli.

Pagination

Kaminari gem allows to access the ActiveRecord with pagination related methods.

Serializer

By using ActiveModel::Serializers, we can make our JSON output more consistent.

Mailer

Mailer, which act exactly like Controller. And greatly, we can write preview page for the emails, in HTML or text.

CSRF protection

For the security, we can do protect_from_frogery to protect from CSRF.

BDD/TDD

Since we always need to test our code, BDD or TDD makes our development more stable and interesting.

By using rspec and factory_bot gems, we can do our testing easier, including mocking data and stub the methods.

Time travelling

Related to BDD, by using ActiveSupport::Time, we can test our code by specifying the date. Need not to use a date parameter through out all the function calls.

Job

We can do background job by using ActiveJob and also SideKiq.

Cache (SQL)

By default, the ActiveRecord (model) querying will use cache, example.

Drawback

Though Ruby on Rails is powerful, there is one limitation. There is no official support on Windows, which we cannot find the binary installation of the latest version of Ruby and Rails for Windows.

The only workaround for Windows installation is using WSL (Windows Subsystem for Linux). And this feature only available on Windows 10 and Windows Server 2019.

Meaning in older version Windows, probably needs to use virtualization like Docker or Vagrant. (I never tried before.)

Advantages

I prefer Ruby on Rails over Node, because Node has too many modules doing similar jobs, for example crypto-js and node-crypto-js. Too many options cause me to use extra effort to find out which one is better.

I prefer Ruby over Python, because of the lambda expression.

In my opinion, the advantage of Ruby on Rails is because of Ruby language itself.

To print the output, we can do puts something, instead of console.log(something) (JavaScript). Parentheses are optional to call the function, similar to Perl.

We can pass the hash to the function without braces, such as foobar(a: 1, b: 2). But in JavaScript, we need to do foobar({ a: 1, b: 2 }); in PHP, foobar(['a' => 1, 'b' => 2]); in Python foobar({'a': 1, 'b': 2}).

When developing using Ruby on Rails, we can apply Twelve-Factor and Design Patterns. We focus on code readability (using RuboCop), refactoring, and testing.

You can find a curated list of useful gems as well.