## 2015-11-19

### Papperstranan och det Atlantiska Havet

"Mamma, kolla ett spöke."
-- Femåringen som såg en kvinna i heltäckande slöja.

Fan vad osammanhängande jag kan skriva... Hänger inte ens med själv. ^_^

# Europa Överger Sina Ideal

Sverige har endast ansvar för att hjälpa svenska medborgare och de med uppehållstillstånd.

Är de inte medborgare i något EU land så har de inte något att göra här.

Visst vi har en extraordinär situation I Europa och Mellanöstern men det är inte vår skyldighet att hjälpa, men det är nog det mest humana att göra.

Men begår de något brott skall de kastas ut ur EU och bli målade med genetiska markörer så att de inte kan återvånda.

Vi har exempel på våldtäkter på barn på asylboendes som inte rapporteras till polisen utan mörkas av personalen[1]. Sådana här saker måste uppmärksammas.

Och om vi tar en avstickare från Flykting frågan så måste vi nog ta tag i problemen som det multikulturella samhället har skapat. Där vi tillåter de som kommer hit att välja att inte assimileras, där vi ser mellan fingrarna när det gäller den icke acceptabla människosynen som vissa individer har.

Antingen står vi upp för den västliga civilisationen eller så låter vi oss bli överkörda av de som inte delar våra värderingar när det gäller synen på människa liv eller vad som utgör ett samhälle.

Att luta sig tillbaka och tycka bra om oss själva bara för att vi hjälper de som kommer hit och inte hjälpa dem med att komma ur sin egna kulturella bubbla hjälper ingen. Och skapar bara problem framöver.

Vill vi ha ett segregerat samhälle eller ett samhälle som är byggt på rättssäkerhet? Vill vi att den generationen som efterträder oss inte vågar ta tag i problem för att inte de skall råka såra någons känslor. Nej, det tror jag inte. Vi måste stå upp för våra demokratiska ideal till vilket pris som helst. Vi skall inte tro att vi kan vara tillmötesgående till alla, vi måste stå upp för de sekulära idealen som det västerländska civilisationen bygger på! Vi skall inte bry oss om hudfärg, kön, religion, bara om individens välstånd i samhället, trotts vad den regressiva vänstern tycker.

Så... Var var jag? Err... Vad fan? Detta får duga.

Källor:

"..."

# Giving up SSTS (for now? for ever?)

So I have been working on this project that I called "SSTS" or Super Simple Type System. It is neither a "Type System" or "Simple".

I have been working on this on and off for two-three years. I started it on a whim, I wanted to learn what makes GLib and GObject tick, so I set out with the simple goal of implementing something like GObject but without all the nasty type-tracking and what not. It started out well, with a base object type that I could use to implement other stuff and call methods using the base object's interface.

"This is easy!" I thought to my self, it was easy, cus' it was nothing special. Then I wanted to add something like the GObject's notify system. But for that I needed some sort of map structure... But to implement a Map structure I needed a Dynamic Array and a Linked List...

It is now almost two years since I started faffing about with this, and get lots of help from the guys over at the C Programmers community on G+, and now I had hit a road block. I got double frees... And I just could not figure out what was wrong.

I posted a query to the community page, but got told I needed more tests. At this point I just give up. I am sick of this. Not of the people trying to help, but at my self, I have spent two years on some code that no one will ever care about. And I just do not care enough to write test cases, the code is not written in a "test friendly" way.

Sure, I have learned a lot by the experience but I just see no end in sight for the project. If I were to implement the object notify system I would start with the next thing (Streams), which would require something else(an Event Loop).

At this point I see nothing but an other two years till I would be finished, and I just do not want to care about it any more.

## Design and good intentions

I like how I have focused on making the function calls not feel to "C"-y. I wrote wrappers for string functions to return strings, so if feels like something like Java or something. And this philosophy is everywhere. "Make it not feel too much like C."

I did not want any of the internals leaking out like some kind of horror show. I did not want the user to have to deal with checking if a function returns a positive or negative value. That is scuff that the user can be without.

This good intentions makes for code that is harder to test than "normal" C code where you get some error value from a function when it fails. It can not just check "is this negative" over and over again and see it go through. No to test these things I have to go through and write complex tests for edge cases that I never thought of when writing it.

I just no not want to deal with that.

I give up... I have had enough of my ineptitude.

## 2015-09-13

### The Paper Crane and the Endless Struggles of a Man in a System of Endless Struggle.

"So what you are saying is that the sky will not fall?"

# ForEach in C

In C we do not have iterators in any sane fashion (C++'s iterators are not sane either, btw 😜 ) nor do we have a standard array_for_each (how would that even work?). So when implementing a C data structure that may need for_each capabilities it is best to do it. Relying on for loops can be problematic if you are not careful.

In these example I will use a DynamicArray as the data structure. With functions to get items at an index and the length of the array. When it comes to LinkedLists you must use linked_list_next, linked_list_prev and linked_list_get_current, but that is outside this discussion.

## First things firts: typedef:ing a standard ForEach function pointer

The signature for a good for each function in any implementation is as follows:


typedef void (ForEachFunc *)(void * self, void * item, void * user_data);


The self here should be a pointer to the data structure you are doing the for each on. No operations should de done on this structure.

The item is the current item, the item that the for each function should operate.

The user_data is any user data you can think of. It may be used as a out value or as some other data that is used inside the for each function.

## Implementing dynamic_array_for_each

In this example I will not rely on any internals of the data structure, instead I will use dynamic_array_get() and dynamic_array_len() this means that you can implement this even if you do not have accesses to the underlying structure.

To begin with you must understand that this relies on a for loop, so it is not more efficient that just writing a for loop your self. It just provides a little bit safer way of coding, where you do not have to keep track of variables to much.

The signature of the function is as follows:

void
dynamic_array_for_each (DynamicArray * self, ForEachFunc func, void * user_data) {}


The self here is the dynamic array to perform the for-each function on.

The func here is the function that we are to execute on each iteration.

The user_data is the data to passed to the function. This may be used as an "output" of sorts.

void
dynamic_array_for_each (DynamicArray * self, ForEachFunc func, void * user_data) {
// First me get the length of the array, This should be the last item in the array.
size_t len = dynamic_array_len (self);
for (size_t i = 0; i <= len; i++) {
// Check if the item is there.
void * item = dynamic_array_get (self, i);
if (item) {
func (self, item, user_data);
}
}
}


And that is it, folks!

## Using it

So now it is now time to use the this for-each thingy. So lets define a function to use in the for-each.

void
for_each_print (SDynamicArray * self, int item, int * itt) {
fprintf (stdout, "The number is: %d on iteration: %d\n", item, (*itt));
(*itt)++;
}


This function prints the number stored in the array and prints it out. as user data it takes a pointer to an int, this is that is incremented each time the function is called.

Lets now put this into a context:

int
main (int argc, char ** argv, char ** argp) {
/* create the array */
DynamicArray * arr = dynamic_array ();
/* ... Code to fill the array with numbers. */
int itt = 0;
dynamic_array_for_each (arr, (ForEachFunc)for_each_print, &itt);
fprintf (stdout, "The last itt number is: %d", itt);
/* ... Code to free the array and what not ... */
}


As you can see it is not too much work to implement or use.

## Conclusion, or something.

So as we have seen it is not magic, it is actually easy to use, and it promotes code-re-use. One downside of this is that it does a lot of calls, and thus uses the call stack, this might be problematic if you you already are hitting the maximum call stack size.

But I firmly believe that this is the best way of doing things like this.