Jeffrey van Binsbergen.nl

C and C++ are not dead

Recently I’ve picked up C++ development again and it is great. As most people know, I love fast applications and I love making them. With C#, Python, Node.JS and many more higher level languages gaining in popularity and performance getting pretty cheap, low level languages like C are often forgotten. Hopefully this article will encourage more people to give it a try.

Efficiency matters

A big reason to choose for a low level language is of course: Efficiency. You’re working close to the hardware and you suddenly gain flexibility to do all kinds of fun things, especially with memory access. And it still matters for any application which needs to do some actual work. Conversions, Machine Learning, Image processing or what I’m using it for at this moment: IoT data processing and aggregation. It all runs incredibly fast. To make it more fun for myself I’m testing it on a Raspberry PI zero (5 dollar Linux computer) and it can still handle thousands of clients at the same time. It is great!

Another reason why to think of efficiency: Running it in the cloud. Running things in cloud is actually not that cheap, especially if you need a bit more performance than the budget option. Most problems in the cloud can be solved by throwing a credit card towards it but all the costs add up. By making a small efficient application for any important processing, you can really get the required specs down.

Making something very efficient allows people to do more with your application. If data from a chart takes half a second to get generated, you can only put 1 or 2 on a web page before it feels ‘too slow’. When putting some effort in making a small efficient application. You can display your charts with a lot of additional information instantly and extract information from it the user actually wants to see.

Portability

It is incredibly portable if you are careful with platform specific features and libraries. The same code can run on Windows, Linux, FreeBSD, etc. with just some small modifications to the platform specific functions. You can even try to run your code on an embedded system like an ESP8266. This is especially useful when making a library which can be integrated into a wide selection of other projects on different platforms.

Downside

Making your application takes more time. You will have to worry about things you otherwise never see. Clean up your used data from the memory. A lot of the handy flexible features of your favorite high level language won’t be available. Also some other people will probably think you’re insane. I can definitely recommend taking a look and experimenting with it.

JavaScript Array extensions

For my Japanese learn site I needed a way to quickly filter on an array of objects in JavaScript. I really like LINQ in C# and I missed it in JavaScript. So I decided to make it myself, which barely took 5 minutes but saved me probably hours and a lot of repetitive loops.

Array.prototype.Where = function (func) {
var items = [];
for (var i = 0; i < this.length; i++) {
if (func(this[i]))
items.push(this[i]);
}
return items;
};

Array.prototype.First = function (func) {
for (var i = 0; i < this.length; i++) {
if (func(this[i]))
return this[i];
}
};

Array.prototype.Take = function (count) {
var items = [];
for (var i = 0; i < this.length && i < count; i++) {
items.push(this[i]);
}
return items;
};

Array.prototype.Skip = function (count) {
var items = [];
for (var i = count; i < this.length; i++) {
items.push(this[i]);
}
return items;
};

Array.prototype.OrderBy = function (func) {
return this.sort(function (a, b) {
return func(a) - func(b);
});
};

Array.prototype.Select = function (func) {
var items = [];
for (var i = 0; i < this.length; i++)
items.push(func(this[i]));
return items;
};

Array.prototype.Max = function (func) {
var highest = null;
for (var i = 0; i < this.length; i++) {
var value = func(this[i]);
if (highest == null || value > highest)
highest = value;
}
return highest;
};

Array.prototype.Unique = function (func) {
var items = [];
var uniqueKeys = [];
for (var i = 0; i < this.length; i++) {
var key = func(this[i]);
if (uniqueKeys.indexOf(key) < 0) {
items.push(this[i]);
uniqueKeys.push(key);
}
}
return items;
};

Array.prototype.Randomize = function () {
var items = this.slice();
var currentIndex = items.length, temporaryValue, randomIndex;

while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;

temporaryValue = items[currentIndex];
items[currentIndex] = items[randomIndex];
items[randomIndex] = temporaryValue;
}
return array;
};

A few examples of cool stuff you can do by using this code:

var colors = [
{ name: "Blue", votes: 2 },
{ name: "Green", votes: 9 },
{ name: "Red", votes: 1 }
];

var color = colors.First(function (a) { return a.votes > 5 });
alert(color.name); // Green

var filteredColors = colors.Where(function (a) { return a.votes < 5 });
alert(filteredColors.length); // 2

var colorsInUppercase = colors.Select(function (a) {
return { name: a.name.toUpperCase(), votes: a.votes }
}).OrderBy(function(a) {
return a.votes;
});
alert(colorsInUppercase[0].name); // RED

Of course, after making those few functions and being all happy about it... I saw that are multiple existing projects which do just the same thing. Oh well, I like to make stuff myself anyway.

miageru.net

This is by far my biggest (and most complete) personal project: A site all made to look up anything about the Japanese language, and learn it by doing a shitton of practices. This site was running for a long time in a closed alpha and beta test while still doing big improvements. Since this year is finally released in a public beta. The site is made for everyone who wants to learn Japanese, including myself. The content has been contributed and double checked by multiple people during the developments, but even now more content is added regularly.

Development

During the developments my key point was to make the site fast and useful (nobody likes useless snail sites). The site has been written in ASP.NET MVC, but multiple tweaks were made to improve speed the user experienced while using the information site or the learn center. Caching is enabled on pretty much all areas possible (output cache, http client side cache, local storage) and the requests are kept to a minimum. The structure of the information pages are set up with html5 schematic elements to make our search engine friends happy.

The learn center itself is written almost completely in JavaScript and can run mostly without internet connection needed by using the application cache feature new in HTML5. Of course any cool site needs a few charts, so I've decided to add one library d3.js to build nice SVG based charts and a few interactive introduction videos.

Both the site and learn center is usable on a mobile device as well. I've used media queries to make the layout responsive and usable on any screen.

Nice tricks and technologies

A small addition I've made early on were a few JavaScript array extensions which allowed me to do fun stuff like filtering, ordering, randomizing and extracting information from every array on a C# LINQ kind of way. This really decreased a lot of the development time of the practices. For example: Filter difficult vocab, Randomize, take 20. I've published the code here.

All the screens in the learn center run through a small self-made framework which allowed me to make templates of screens, easy change all elements and add interaction, and most important: Add a good reusable structure through the whole project. Almost no code has been written twice. Basically it added support for JavaScript based components and templates.

I've also used the HTML5 speech recognition API and it turned out to be amazing for the practices! The API allows you to set up a few predefined text, which I've set to the vocab the user knows at that point. By limiting the speech recognition possible interpretations it (almost) always exactly knows what you were saying.

Future

The site is ready to use but like always, my projects are a work in progress. Expect more of everything in the future... you know, somewhere between my other personal projects when I feel like it.

A new site

Hello and welcome on the new improved website where I'll share any interesting, funny or just random stories. This site replaces the old hacky blog I wrote in php a 5 years ago along with a nice cleanup of the old articles.

For those who wanna know: The technology I've used now is the latest ASP.NET MVC, written in the freshly released Visual Studio 2015 community edition. All data is saved and retrieved using the Entity Framework 6 and all traces of JQuery and Bootstrap were carefully killed with fire.

Show all articles