My code is trying to kill me

Writing experiment 2

13.08.2019In Writing

The first experiment went quite well, I got a nice story from such a boring theme. Let's do that again.

The random article

Gerd-Liv Valla - Nice, a character

  • a Norwegian former trade union leader - Her trade union history could fit nicely to the setting of Shellville as I have this trade theme
  • resigned in 2007 as a result of the so-called Valla affair - An affair - interesting
  • Valla was politically active in a small communist group. The group split, Valla supported the pro-Stalin faction within the group - Great! Communist are always fun. I lived in a communist country and there are still some supporters around me. I'm very against their agenda, leaning on libertarian side, so it would be a good practice to try to make a good case for communism/socialism and put my own beliefs to test.
  • She was accused of harassment and of authoritarian management - There's nice duality here. Aligned with communism and trade unions, she's advocating workers' rights and then being accused of harassment

The approach

Characters are much harder to write than plot. I tried to write some random character scene but I couldn't. To write a paragraph about your character, you have to know everything about them to make it work: their motivations, fears, desires and what do you want to put them through. I was stuck for month on this scene so I need to change my approach. Instead of a scene, I will try to flesh out this character a little. I'll use John Truby's seven key steps of story structure from his book The Anatomy of Story.

Self-revelation

Following Truby's advice, I'll start with the most important thing: self-revelation.

I heard that before - George R.R. Martin often quote this:

"The only thing worth writing about is the human heart in conflict with itself" ― William Faulkner. And I didn't really understand it before, but now I think I do. And I get now why I admire Martin's Song of Ice and Fire so much. It's a compilation of self-revelations all weaved into one story.

Why is this so important? If you start with the character's back-story, motivation and desires you can get an interesting character at the beginning of the story. But if their motivation do not lead them to interesting self-revelation you either have a boring culmination or you have to artificially change their motivation during the story which can result in an undefined character.

If you start with self-revelation then you defined the most important thing in the story and can adjust beginning of the story to align with the most powerful culmination.

The Character

Let's name the character: Gerdalla. What are my options with her? There are two main possibilities: she could learn that she can't control lives of others and that she has to let them be free or she learns that she can't help people without control over them.

Former sounds preachy because that aligns with my wishes and it's predictable. She could begin as a moderate authoritarian, grow more and more totalitarian but through failures learn to appreciate freedom.

The second version sounds like becoming-a-villain story but she could be good at it. Let's flesh this out.

Psychological Self-Revelation: Gerdalla can't trust people any more. Moral Self-Revelation: People need to be controlled.

  1. Weakness and Need:
    • Psychological Weakness and Need: Gerdalla is too inexperienced and too trusting.
    • Psychological Need: Gerdalla needs to toughen up and learn to think on her own.
    • Moral Weakness: Her inability to manage allows unscrupulous people to take advantage of people she could protect.
    • Moral Need: Gerdalla needs to find a way to protect honest people and punish those who exploit them.
  1. Desire:
    • She wants to become a stronger person and have more power to organize better society.
  1. Opponent:
    • Those who hold power that she needs.
    • Organization that wants to organize society differently. It can reveal itself at first as just a bunch of traders but it could become more sinister.
  1. Plan:
    • Get more power using her connections with authorities.
    • Organize her domain to protect people.
    • Find out who works again her.
  1. Battle:
    • Conflict with those in power.
    • Conflict with organization.
    • Conflict with honest people who change as soon they get some power.
  1. Self-Revelation:
    • Psychological Self-Revelation: Gerdalla can't trust people any more.
    • Moral Self-Revelation: People need to be controlled.
  1. New Equilibrium:
    • Gerdalla is a pragmatic, cynical ruler.
    • She succeeded in organizing fair society and people are happy.
    • But what she learned about human nature makes her sad and dispirited.

Economix - Lessons learned

22.04.2019In Projects

Although I learned a lot from my first two attempts at economy simulator, they failed as projects.

In the first iteration, the world had no dimensions, no concept of place, no distances. It simplified things a lot but it was hard to visualize anything.

A world had resources like forest, hunting ground or berry field which could be extracted wood, food or animal skin. Each human had daily need for food, wood, cloth and he had to have this in inventory to be able to live. There were predefined processes like hunting, woodcutting, spear making which required different resources and items to produce some other item. Each human could take one action per day. He could gather resources, craft something, rest or reproduce. So once the basic needs were covered he could rest to increase happiness, reproduce to increase the number of people or craft something. Crafted tools would increase productivity of any process and using a process would increase the skill of using that process.

But the simulation immediately hit the Malthusian trap, everybody competed to survive on the most basic level. The only viable tactic was to use the resources as much as you can. If you try to invest in skills or tools, you'll most likely die of hunger.

If all critical resources are shared but scarce, there is no economy, just basic survival. What I needed was some kind of private property over the resources but current engine was not able to do it so I wanted to base it on better foundation.

The second attempt abstracted too much and economy was falling. I want describe the internals but I got one important insight. Basic of the economy is sustenance without trade. You need to be able to produce your own food and then decide if you want to trade or not. If you are forced to trade to survive, the prices fluctuate too much.

I still didn't figure how to do money.


Writing experiment 1 - Shellville

26.02.2019In Writing

I'll make an experiment. I want to learn how to write but I don't have any grand idea currently, and even if I had I wouldn't want to spend it on my crappy writing. First I need to get better at it.

Ideas usually came to writers from world around them. I'm not into geting out and having experiences, it takes too much time and can be dangerous. Instead, I'll use Wikipedia to generate random articles and try to get inspiration for some fantasy content.

Good story needs characters, setting and plot and the some conflict that ties them into story. I'll generate random articles, turn them into small writups of character, setting or plot and then think up some conflict that connects them into story.

Let's start.

First random article is... Shelbyville, Indiana. Ok. Fine. I got the most boring city in the world. Let's see if I can make something out of it.

There is a story of some Jacob Whetzel who cut a trail from east which was important for later settlement. Let's work with that.

Exposition

Forest area of ... divides Shellville on the coast from Melanopolis in the fertile plains of the river Melo. Trade is done through the see and river, making the travel long and slow. A trade company decided to clear the path through the forest, despite previous failed attempts.

Story

Jacob lowered his axe and suspiciously stared into woods. It was the third time he noticed a deer between the trees. With all the racket they were producing, no animal should come anywhere near. "Something's not right!" he yelled. Multiple simultaneous thuds and thunks around him were replaced with murmur as woodcutters near him stopped working one by one using the break to wipe off some sweat or stretch their hands while waiting for an explanation. When even the farthest axe threw its last thud, it was time to explain why they stopped. In his mind he was picking the right words. "I saw a dear!" sounded too banal, "Something's wrong!" was undefined. He decided on "There is something in the woods!" but he never got the chance to say it.

Woodcutters from the right flank started walking backwards, their axes held more like a defensive weapons than as a tool, their gaze toward the woods in front of them. "What the..." is all Jacob managed to think as the sight before him sent the chills down his neck. Few steps in the woods, a group of animals stood still. Deers, wolves, boars, a black bear, all unnaturaly together glaring at the people in the clearing. An eagle, ravens and crows, quiet on the branches above them.

"Move!" he yelled and started retreating in the direction of the cleared path they made, walking backwards, stil looking in the woods. Pain shoot from his ankle when he stepped on the axe somebody left in the ground, dull edge sharp enough to remove some skin. This throw him off balance and when he colided with somebody, this threw him on the ground. He fell on a block of wood, bruising his ribs. The sharp, pulsating pain from his ankle and the dull pain from his side diminished instantly when he heard flapping of thousand of wings. The birds made a cloud over the clearing as they attacked. He covered his head as one bite into his skalp. There is no other cover in the clearing, animals are in the woods so he started running down the path they were clearing for the last month.

When the sounds of screetching and screeming were at some distance, he managed to stop and look back.

How to continue

  • Explore the trade between Shellville and Melanopolis
  • Who is Jacob? What made him lead this expedition?
  • What about animals? Is somebody controlling them? Are they pack-sentient

Sourdough starter

18.02.2019In Food

I didn't like bread. The last 20 years, I used to describe bread as glutenous, soggy, chewy piece full of additives people eat instead of coming up with something tastier and healthier. Plus, bread was always combined with even more unhealthy ingredients: salami, cheap cheese or sugary spreads. When I removed it from my diet, it felt like a superpower; I could do what most people around me couldn't: live without bread.

Now and then I would eat a piece of bread, just to confirm that I'm not missing anything. And mostly I didn't. But, sometimes I would run into some great piece of bread, usually combined with something like grains, garlic, butter or cheese that showed me that bread can be delicious if you make it with care and not just for mass production and low price.

I tried to make some bread myself, and it was somewhat better than the store-bought, but there was always this starter part that I had to buy from the same store, which was again mass-produced somewhere. So, when I found out about home made sourdough starter the puzzle was complete.

I learned everything I could about sourdough starters and finally did the complete process, from just some flour and water in the jar to the freshly baked loaf of sourdough bread. The final result was spectacular! Fresh bread had distinct, slightly sour taste, smelled divine and had fluffy and elastic structure with just enough pockets of air. We ate the whole loaf in a day. Part of it just with salt and butter, then some with avocado and garlic.

Sourdough starter process

The basic process is simple:

  • Day 1: Mix 50g of flour with 50g of water. Put somewhere on room temperature.
  • For the next 7 days: Mix 50g of old mixture, 50g of fresh flour and 60g of water. That's called feeding. Throw away the unused part of the old mixture.
  • After 7 days you can start using leftover starter for anything you want

Pro tips:

  • If you don't need bread daily, after feeding you can put the mixture in the refrigerator for up to 10 days. When you take it back out it will just continue where it left off.
  • Find the jar without a screw-on lid as these are hell to clean from dried dough. Jars with wooded lids are enough. I found it in IKEA.
  • I found out that my room temperature of 20C is too cold for sourdough to develop properly. So I needed warmer spot. I used to put a jar of hot water in the oven and put the mixture beside it which gave the results but I had to add the hot water too often so I needed a better idea. And then I found it: my UPS device is just the temperature I wanted: warm but not too much and always at the constant temperature. Check out this rig:

Daniel Whiteson and Jorge Cham: We have no idea (2017)

08.02.2019In Book Impressions

Here's the pop-science book worth reading. If you're interested in why the speed of light is the speed limit of the universe or what is time, why gravity is weird or what are the basic elements of matter, Daniel and Jorge will explain it with just the right amounts of science, philosophy and cat pictures.

I bought this book when I had a feeling that I work only on miniature, banal problems and I just wanted to cope with some grander questions. And this book provided. As Carl Sagan's "Cosmos" was defining read for me some 30 years ago through which I learned about grandeur of the Universe, "We Have No Idea" explains all we know and all we don't know about the Universe using cats and comics.

Some topics it covers:

  • What is the Universe made of?
  • What is the most basic element of matter?
  • What are dark matter and dark energy?
  • What are time, mass, space?
  • How many dimensions are there?

When I tried to read Wikipedia articles on those questions, although I'm curious about the topics, I got bored quickly. But "We Have No Idea" worked remarkably. Not to simple, not overly detailed. I didn't learn any equations and I'm still not able to calculate what happens in hadron collider but I got general knowledge about the topics and the sense of how big and grand those questions are.


Is this still on?

01.08.2018In Projects

I'm just wondering if my static publisher is still working. I just noticed that I eat my own dog food (that's Spolsky's term - google it, I don't know how to add links now). In the last few years I wrote some applications that I use often, some of them daily, and they just work.

Hm, the problem is that I don't know my markup syntax anymore. Well, let's do the plain-text only now.

Static publisher - I'm using it to post articles on the blog and they are formated exactly as I want them. I didn't use it fore some time but if you are reading this online then it works.

Car sharing monitor - I have a web app that crawls facebook car sharing groups to find me a ride when I need one. Without that app, I would have to monitor facebook groups and manually search for rides on my route. If I am too slow, on busy days rides get full in minutes. This app monitors groups for me and alerts me if it finds the ride on my route. I'm usualy able to reserve my ride before anybody else.

Stock monitoring app - Not the live monitoring, I don't need that. I'm trying to be a value investor. This app downloads financial information about companies, their fundamentals and price. I wrote a formula that scores the stock depending on its value and selects what should my portfolio look like and compares to the current state. Of course, the hard part was to learn everything about investing. This app is my knowledge base. It's also fun to apply math to finances.

N3R (Not Really an Rss Reader) - my most used app ever. When Google pulled the plug on their RSS reader (Google reader?) I was in trouble. For years I currated my list of blogs that are worth reading. It shouldn't be a problem to switch to another Rss reader, right? But it is, because what I expect from Rss and what they all provide is so different. I just need a notification that there is a new article, and when i click on it it should open the article in a new window, in full context of the website and mark the item as read. And now I have the app for that.


Daniel C. Dennett: Freedom Evolves (2003)

16.03.2017In Book Impressions

If the universe is deterministic, as physics laws say, how can we have free will? Can we admit that everything we do is just a result of previous state of universe? Is free will just an illusion?

In this book Daniel Dennett tackles this question but I'm not sure I'm satisfied with the answer. He says that one does not exclude the other. Yes, the universe is deterministic on the physics scale, but a complex creatures like us can exert free will and make decisions on biological scale.

And really, how could be any different? If universe has any random element, then we don't have free will, but rather act randomly. We need deterministic framework to exercise free will.

It is, after all, just one of the many weirdness of our existence.


Static publisher features

11.12.2015In Projects

v0.1:

  • read Writemonkey files
  • create static html file for every article
  • create static html file for all articles combined
  • recognized markup: H, UL, LI
  • one click publish to local folder or ftp

v0.2:

  • local index of file - upload only changes

vNext:

  • delete surplus files on destination and ftp

vFuture:

  • categories, tags, types
  • service that publishes in background
  • probably should use third party markup to html converter
  • mark some texts as tweets or facebook posts and automatically post or tweet them to my timeline
  • create rss

Project Economix 7 - money

19.01.2015In Projects

To implement money in the simulator, first I need to know what money is. Last time I wrote why it was invented and why it is necessery. But how does it work and how it did emerged?

You can google it yourself and find many plausible theories, I'll just sumarize the parts I think are important.

First, imagine the world without money where you trade by bartering; it's possible but problematic. A farmer can trade some apples with a toolmaker for a new tool. But he can't trade apples for strawberies because when strawberries are ripe, apples are not yet fully grown. What he can do is to promise he'll give some apples in a few month for strawberies he will get now. So, the root of money is a promise, you can call it debt. If two farmers trust eachother, they can make such trade.

In a small community, it is quite possible to trade without money, only on promises. But how many promises can I give to someone? Can a farmer promise he'll give tons of apples? He can, but only if he has a large apple orchard. He actually have a credit rating to his promises. The more productive he is now, the more promises he can make. So you don't need money to have debt, credit and credit rating. That seems to be inherent to the trade system.


Project Economix 6 - trade

14.01.2015In Projects

Society is pretty limited with only resource gathering and consumption. Everybody is just scavenging for the basic resources and spending them or resting if they have enough.

To reach a more complex society, we need two main ingredients:

  • specialization: instead of everybody doing everything, people can specialize and become experts in they field thus producing more
  • trade: if expert in one field can exchange products with expert in another field they both have more of both than if they didn't specialize

First version of trade is barter where products are exchanged directly: one unit of food for one unit of stone, one axe for three units of wood. Problem with such arrangement is that both buyer and seller have to want each other's product or trade is not possible. As a seller, you need to find not only someone who wants your product but he have to have something you want (Coincidence of wants).

That's way money was invented: it is necessary. In money trade, as a seller you just need to find somebody who needs your product and has the money. Then you can use it later to buy what you need from person completely unrelated to the first trade. Naturally, I tried to implement it too. But to implement the money naturally, without some unknown force printing money and putting it into the economy (like state is doing now), definitely it's not an easy task.


Project Economix 5

11.01.2015In Projects

Quick summary of the project structure so far:

  • there is a world that contains a list of resources and a list of human agents
  • resources are renewable sources of products (forest gives wood, quarry gives stone...) with defined capacity and regeneration speed
  • processes are activities that require input and produce outputs, input being a resource or product and output being another product (stone cutting require query and produce stone, axe making require wood and stone and produce stone axe...)
  • humans are agents that can decide to run a process once per tick (world is ticking)
  • humans have basic needs that must be satisfied regularly to keep living: they have to spend food to eat, wood to warm up and cloth to dress
  • humans can reproduce when they decide to
  • executing a process takes time, this is simulated with cooldown time during which human cannot do any action
  • when human decide to do nothing, it's considered rest and counts as increase in quality of life
  • whem human executes a process, it gains skill in this process, meaning it takes less time to do it (shorter cooldown time)

With this framework in place, I can create various implementations of human and test how they fare in the world. They differ in how they make decisions, do they just consume everything they find or do thy plan in long term, how they behave in abundance of resources and what they do when resources are scarce.


Project Economix 4

10.01.2015In Projects

In previous articles I defined and explained the Malthusian trap. But somehow we avoided it and the conditions are improving for humanity. What happened?

Let's try the island example from previous example. When people discovered agriculture, island could support 3000 people. Current 1000 inhabitants had to work harder but they lived comfortably and multiplied. When they reached population of 3000, conditions again dropped to bare survival, they still had to work hard and destroy the environment. How could they avoid that?

First and obvious option is to stop multiplying. But without harsh imposed limits on personal freedom that wouldn't be possible. But if in period of time when population was between 1000 and 3000 when island could support its population, somebody invented even better technology that could support even more population, they could avoid Malthusian trap. When population reach 3000, new population limit is 4000. When 4000 is reached, new limit is 5000. And so on.

Exactly that happened in Europe. From neolithic revolution to first industrial revolution (6000 - 10000 years), average living conditions didn't improve significantly. Break from Malthusian trap started with industrial revolution around 1800. Technology improved significantly and average income and wealth increased. As always, population increased; but before living conditions dropped, technology improved again. And then again, thus allowing us to keep or improve standard of living although the world population grew six time.

It seams we are now dependent on technology. Not only on current state of it, but we are dependent on growth. Without constant technological development we would return to bare survival. The question is, how much further can technology grow?


Project Economix 3

27.12.2014In Projects

In short, Malthusian trap is an explanation for a problem happening to humanity where we tend to live constantly on the brink of starvation. Whenever we find the way to produce more food (or wealth) from natural resources, we tend to multiply until again everybody lives in misery.

Let's try to explain it with hypothetical example. Imagine an uninhabited island that can support 1000 people, hunter gatherer style. Now, 100 primitive people arrive on the island. What happens? They live in harmony with nature, they gather fruits from bushes and trees, they hunt for meat. They enjoy their lives, they are healthy, nurtured and happy. They live in egalitarian communities. And they multiply...

Soon, island have 1200 inhabitants and problems arise. There isn't enough food for everybody. People are malnourished, sometimes desperate and they start to fight. Population stagnates as more children do not survive to adulthood. Even worse, as climate fluctuates sometimes island can support even more people and population grows. But then, when climate changes, mass starvations occur regularly.

Some smart people try and succeed in growing plants, inventing the agriculture. Invention spreads, it is simple and everybody adopts it. It is much more efficient than just gathering what nature provides and now the island can support 3000 people. They don't live in harmony with nature anymore as they cut the threes whenever they need more land. They are working more and harder but they are again properly nourished as there is enough food for everyone. Technology made their lives better (or at least less miserable). And they multiply...


Project Economix 2

26.12.2014In Projects

Funny things happen when you want to write code but first have to grasp the problem domain. And thoroughly so that you gotta learn something in the way. Supply, demand, elasticity... Simple stuff. I learn that in school. But programming the economy raises some new questions, like:

  • When does economy begin?
  • How does world without economy looks like?
  • Why can't we all be rich and prosperous?

Answers on first two questions are simple. Economy begins when resources are scarce. That's why you have economy for food but not for air. Air is still abundant, but food is not. Once air runs out in some way, there will be economy around it. Same happened with water. Selling water was unheard of two generation ago but it became completely normal to this generation.

Early hunter-gatherer society did not have food economy, anybody who was hungry could just pick or hunt something, there was enough of it. So, the questions is:

  • if there was enough for everybody and everybody was happy, why it didn't stay like that?

Well, humanity is in the trap: Malthusian trap.


Project Economix 1

25.12.2014In Projects

Writing an economy simulator is a kind of a project I always wanted to create but somehow I never did. Not that I do not try, I just never persist long enough for it to became more than quick attempt. I think I have two problems:

  • I can't define the scope
  • I don't understand the mechanisms

This are the problems on which I have to have some answers before I get to coding. They look simple only if you're ignorant enough. I strive not to be, so it seems I'm into serious research project if I want any results.


SourceSafe flashback

12.12.2014

I was introduced to source control in the worst possible way: through the Visual SourceSafe. I was using it for 5 years in my workplace. As complexity of our development rise, VSS showed more and more of its problems. When I saw all the problems it had, I've put all of my home projects into Subversion and later introduced it in the workplace. After a four years of using SVN as my primary SCS, I stared using Mercurial for my home projects but I wasn't feasible to push it in the workplace as SVN worked fine. When I switched jobs, HG became my main SCS. All in all, 5 years of VSS, 5 years of SVN and 4 years of HG.

Today I tried the Team Foundation Version control which replaced Visual SourceSafe as the default SCS in MS Visual Studio, just to see how it looks, as I hear more and more good things about it. Although it includes project management features, I was primarily interested in source control part, especially in:

  • source control features: versioning and merging
  • tooling: integration with visual studio
  • workflow

I was positively surprised with TFS when we tried to merge code changes, that went well. Unfortunately, as a whole, it has some quirks I can't tolerate:

  • Commands are scattered over solution explorer, team explorer, source control window and some actions even open in browser.
  • It doesn't respect my folder hierarchy. I added a shared project to the solution from the folder outside the solution. That worked on my computer but other team members got a copy of the project inside the solution's folder.
  • It is a subjective difference, but unlike with HG, I don't feel like I'm in control of my source. It feels more like source control hope instead of source control system.

How do I test the game loop?

10.12.2014

In short: you don't.

Tests you write are the game loop. The core elements of the game loop are:

  • read player's input
  • update the game state based on input
  • display the game state

From this three, you only test the middle one.

You can't test the player input or the display (well, you can, but you don't want to). In tests you don't read the player's input, you simulate it. You simulate it by calling functions that will be called when user provide some input. After you call that functions, you check the game state and assert your assumptions about the consequent state. Since game will draw the screen from this very state, you can be sure that it has the correct data to draw.


Static publisher motivation

09.12.2014In Projects

I strive for years to write regularly on topics I'm interested in, but it seems I just can't do it. On one side, I'm perfectionist but on the other I'm not skilled yet in writing and also not quite fluent in English. That means I'm in constant deadlock where my every article is not quite good enough to publish it. Without publishing, there is no point in writing as you don't get any returns and without writing, my writing skills stagnate. So, either I won't write or I have to lower my criteria. This is the result: I'm writing my first article and publishing it as it is.

After settling down over my perfectionism obstacle, I need to simplify my workflow. I want to be able to fire up Writemonkey, spew my thoughts in it and be done with it. Current workflow that is based on copying text to Wordpress is too distracting. I want my workflow with my rules - and that's why I'm writing static site generator/publisher. With it I'll just write, and it will handle everything else. And as a bonus, I have first topic and few things to say about it.

And blog format just doesn't feel right. Sometimes I just want to create a short mind dump, like tweet or just a little longer, maybe I'll merge articles later. Sometimes I'll incoherently rumble about topic I don't fully understand. Other times I want to write a well structured research article. All those just aren't on the same level and publishing platform should respect this.


To writing

08.12.2014

To actually have any use for writing tools and writing methods, you need to - well - write. Regullarly. Thus, the challenge:

  • write 5 days a week
  • at least 100 words on single topic per article.
  • worry about quality once you have something to worry about
  • delete articles deemed unworthy after one month.

Advice from lifehacker:

  1. Research or strong points are not necessary
  2. Delaying an article with the belief spending longer will make it better usually just means it won’t get written
  3. We should fear not publishing articles, rather than fearing the bad outcomes of putting something out there
  4. When I have a strong connection between writing and my higher level goals and purpose, it’s easy to write

There, this is the one for today.


Static publisher v0.1

07.12.2014In Projects

After a day of coding and fiddling with css, ftp and html (those didn't feel like coding), I finally made basic functional publisher.

It goes like this:

  1. Fire up Writemonkey, write something and save it to source directory as text
  2. Run publisher

Simple enough. It creates one html file for every txt file and one common that serves as an index page. There is a lot of work left but I can add features incrementally while I'm using the software from the first day.