1,000 spaghettis

How much progress should be made before going back and refactoring? I often run into the issue where I’m either overdoing the code cleanup aspect, or I’m spiraling out of control with something that becomes hard to maintain. There is an urge to make sure every detail of every function is completely optimized, but is that really necessary? I’ve recently started abiding by the 1,000 lines of code rule. Especially with games, if my project is less than 1,000 lines, I won’t consider major refactors. Only minute details need to be reworked without having to constantly rewrite along the way.

There is a tendency to assume your code behaves like an automobile in the sense that what’s under the hood matters as much as how cool it looks on the outside. However, I’ve noticed myself running into situations where over-optimizing and refactoring into more generic types can result in code that actually becomes more difficult to fulfill its purpose. Fortunately for code and coders, computers are usually quick enough to compensate for corners that may be cut or overlooked.

D Lang is the Best of Both Worlds?

With the speed of C++ and the eloquence of modern languages, you would think that D is the goto for development these days. Although C++ is my favorite, I like to pick on it as well as Java. Here are some “Hello World” examples from each of the mentioned languages.

// D
import std.stdio;

void main()
    writeln("Hello World without explicit compilations!");
// C++
#include <iostream>

using namespace std; 

int main() 
    cout << "Hello World" << endl; 
    return 0; 
// Java
public static void main(String args[]) 
    System.out.println("Hello World"); 

Perhaps a “Hello World” isn’t the best way to showcase a language preference, but I think even something as trivial as the simplest program is revealing about each of these languages. In the last example, Java’s verbosity is evident with a somewhat substantial main declaration as well as the print statement. C++ isn’t too bad, but the way the print statement is handled isn’t the cleanest. By contrast, D is super straightforward.

Have you tried coding with D? It’s easy to setup for Visual Studio and is a pleasure to work with (https://dlang.org/).

Create your website at WordPress.com
Get started