7 Apr 2011

Ahead-of-time Computing

If a problem is not parallelizable, but the computation is extensive enough for the hardware to fail to complete it on time in a single thread, then probably the only way to implement a soft-real-time system is to calculate the answer before it is needed.

The time spent on computation, data transfer, etc., introduces a latency between an input and the output.

In general, whenever there is a latency between an input data and the output data and the parallelization of the computation does not decrease the latency enough, the next thing to try, probably in conjunction with the parallelization, is the ahead-of-time computing.

The idea is that one calculates a whole bunch of answers in parallel and later, when the actual input data is known, picks the answer, the output, that has been derived from the input that is closest to the real input. The rest of the answers are discharged, thrown away.

As of April 2011 I haven't tried it yet, but may be the ahead-of-time computing could be used for speeding applications up even on single-CPU systems. On single-CPU systems one would perform the ahea-of-time computation in the background, in a low priority thread. Tasks that can be run in the background, for example some of the game artificial intelligence and just-in-time compilation, seems to be good candidates for the ahead-of-time computing, because they are not that time critical.

One might even offload some of the background computation to computers on a local area network. If most of the computation results get thrown away anyway and there's not even a guarantee that the bunch of the ahead-of-time calculated answers contains a usable answer, then it does not matter, if some of the answers in the bunch are not found, completed, calculated, on time. That entails that even old-ish and slow-ish computers can contribute to the speed of an application that runs on a modern computer, provided that their computational power to electric power ratio is acceptable.

11 Feb 2011

How to Bootstrap a Threading API

This article is not intended to be a full-blown tutorial. It is meant to be a relatively concise set of notes, quick reference, with some rehearsal to get the reader's mind to the "track".

Just like any Boolean logic operation (read: digital circuit) can be assembled from Boolean inversion and conjunction, all of the threading API, except the pausing and awakening of sleeping threads, can be assembled if a thread-blocking sleep function exists and a mechanism for forking threads exists.

Once the sleep and fork exist, the rest is all subject to subjective taste, except the pausing and awakening of sleeping threads. The remaining part of this article is just one, somewhat inefficient and largely improvable, version of "the rest".

To create a threading API that does not support the pausing and awakening of sleeping threads I add 2 things:

1) critical sections
2) thread collision detection

The critical sections are used for maintaining consistency of the values of a set of variables.

For the sake of rehearsal, or getting "in the mood": if the set of variables consists of an organism type and its coating, let's say, organism==giraffe, coating==fur, then if the set gets updated to a parrot, i.e. first organism:=parrot, and after that coating:=feathers, then before the value of the coating is updated, there's a situation, where organism==parrot, but the coating==fur. It's better that no thread reads the inconsistent values of the pair, (organism,coating), before the whole pair has been updated and that's where the critical sections become useful.

Thread collision detection is for handling edge-situations, where no thread has yet locked the critical section, but more than one thread wants to enter it.

To allow the capabilities of multi-CPU hardware to be leveraged as much as possible, one should avoid putting the threads to a wait, idle, state. To minimize the waiting time of threads, one wants to maximize the number of threads that can concurrently access the shared set of variables, i.e. one wants to allow as many threads to concurrently enter the critical sections as possible. One way to do that is to use 2 types of critical sections:

A) critical section for only reading
B) critical section for reading and writing


The idea is that it's OK for more than one thread to concurrently read the same set of shared variables, as long as there's no thread writing to the set of shared variables at that very same moment. On the other hand, no thread should be reading the set of shared variables while some other thread is writing to them. Neither should there be more than one thread concurrently writing to the set of shared variables.

At the implementation level it means that each set of the shared variables has 2 locks: one set and released by the read-only critical sections and the other set and released by the read-write critical sections. Both of the critical section implementations read both of the locks.

One possible way to implement the thread collision detection is like this:

b_done=false
while(!b_done)
        i_lock++
        if(i_lock==1){
                enter critical section
                i_lock--
                b_done=true
        } else {
                i_lock--
                sleep some semi-random time
        } // else
} // while

The sleeping time of different blocked threads has to differ, preferably change at every iteration, because otherwise they might collide with each other at every iteration, resulting an infinite loop. One way to assure the sleeping time difference is to use some semi-random numbers. This entails that a programming language can have guite functional threading support without having a statistically proper rand function.

11 Oct 2010

Programming Language Support to Succinct Code

In general, a programming language determines a general idea (semantics), how input data is transformed to output data, and a syntax, the rules how the the contemplation that adheres to the general idea, is written down. APIs don't usually determine syntax, but they do determine semantics.

Leaving a long introduction to aside, the point of this blog post is to point out that in addition to the number of compulsory semicolons, commas, braces, keywords, etc. the succinctness depends heavily on the statistical profile of the code. The number of characters that a construct, let's say, loop clause, function declaration keyword, call to some API subroutine or operator, etc. contributes to an application code depends on the number of times the construct is used in the application.

For example, a code that is written in Maple or Mathematica probably has considerably more calls to various symbolic calculation routines and statistics routines than software that controls industrial robots or runs a customer self service web site. This means that an inefficient, clumsy, API of more "complex" math routines does not have much of an impact on the succinctness of the code of the web application, but it has heavy impact on math intensive data analysis related code.

The conclusion is that one can not assess the succinctness support of a programming language or API without actually measuring the usage frequencies of its different parts in an "average" real life application.

Secondary conclusion is that API-s have to be updated, changed, after they have been in use for a little while and more is known about their "real life usage".

Third conclusion is that if some party comes up with some new technology, programming language, API, etc., then the aiding capability of that technology probably depends on the application domain. It's a bit like comparing antibiotics with a pain killer: taking a pain killer to treat infection might not give as good results as the antibiotics would give and vice versa.

25 Sept 2010

How to Differentiate Oneself in Business

Actually, as of September 2010 I don't know a firm answer to that question, but I think that the contemplation that leads to the hypothesis is probably inspiring.

Suppose we compare passenger cars that fit 2 to 5 passengers. Almost all of them have a staring wheel, 4 tyres, they're more or less of the same size and get the passengers from point A to point B. Usually they all get the job done, technically speaking, they're practically all the same, just switch the car on and drive. In an average non-highway commuting route the cars have roughly the same speed. Probably the skills of their development teams are also equal: an engineer from one of the companies can probably move to another company and be able to handle the job after about a year of learning.

However, obviously, there is a very big difference between Fiat, Mercedes, BMV, Toyota and Ferrari, despite the fact that they're all just cars that take roughly the same amount of fuel and get their passengers from point A to point B.

My hypothesis is that one way to differentiate something is to differentiate it in style, bias, not functionality or technically fundamental properties(i.e. a flying car or an amphibious car). There are different ways of achieving the same goal and there's always the matter of taste. It doesn't make sense to argue that apple juice is somehow better, more innovative, more effective, more functional, etc., than pear juice, but the two definitely differ and people have their preferences.

If the hypothesis held, the conclusion for me would be that even though I'm just an "average" software engineer/developer/whatever-nice-name and even though it probably is possible to find some other person that has at least as good or much "better" (whatever that means) skill set than I have, I can differentiate myself by the style of my software. For example, I can create software that solves a common problem that is already solved by my "competitors", but I can target people with certain habits or preferences, just like BMV and Toyota do it with their products.

Actually, it is also extremely simple to come up with totally UNIQUE products, ideas, by taking something that already exists and giving it A BIAS.  On can just pick anything one likes and quite randomly pick some field, let's say, gardening, military, medical aid, etc., and combine the two. Probability that a thing like this already exists on the market, is pretty low or if it's not low enough, combine something existent with 2 biases in stead of 1, etc.

Examples:
scissors -> gardening scissors,
tongs -> nut crackers,
cup -> coffee cup.

What regards to the business success of unique things, then that's probably subject to marketing and trial and error. After all, even the usefulness of cellphones was considered questionable at their early days. At early days of computing very few could imagine, how a house-wife or a teenager uses a computer, a personal one even, or that a granny needs a strong, military grade, cryptography for paying her utility bills from her living room, over a computer network.

For a halve joke I point out that what I've been describing in my current post is in line with the saying that every great scientist stands on the shoulders of giants. (I'm not a scientist, but development work is what software developers do.)


++++++++++++++++++++++++++

Added in May 2013: "Everything has been Done!

21 Sept 2010

About Domain Specific Algorithms and Software Development Labor

The point of this blog post is to claim that by inventing new programming languages it is not possible to eliminate the labour of describing domain specific algorithms.

For example, an assertion that a file that does not exist, can not be written to, holds regardless of programming language. It is possible for the language designer or library author to make sure that the file is automatically created, if it does not exist, but this is already a labour of describing a domain specific algorithm.

Another example is matrix multiplication. A programming language with its semantics determines the notation, i.e. multiply(a,b) or aTIMESb or a.times(b) or whatever, but someone, be it the hardware designer, programming language designer or a library designer, has to describe the essence of the matrix multiplication at least somehow. The various kinds of implementation details and optimizations do not change the fact that someone has to do actual development labour to get the multiplication to work.

In practice it entails that whenever a new programming language is designed, a new "standard library" is created, the very same work of describing the domain specific algorithms has to be done all over again, unless the previous descriptions are reused.

From intuitive point of view, and yes, according to my personal subjective taste and impressions, software development productivity depends a lot on the notation and semantics of the programming language. As of 2010 I believe that the preferences for a programming language (read: preferences for notation and semantics) is subjective and depends on the chooser's background.

By noticing that most programming languages that are in use in 2010, share a subset of common basic data types, namely arrays/vectors, hashtables, whole numbers, rational numbers, boolean values, I have a hypothesis that a probably withstandable, but imperfect, solution to the reuse and the notation-switch problem is to share memory space (the common data structures) between different programming language implementations. A program would start in one language, then, without exiting, switch to another programming language and then switch to whatever other programming language. The programming language switch regions might, probably would, contain data structure mapping code.

A vague, raw, preliminary, syntax example, where a hashtable named "symbolspace" is reserved in all language implementations:

# We'll start in Ruby
s=(4+5).to_s

LANGSWITCH to PHP

$s_output='The answer is'.$symbolspace['s']
echo $s_output

LANGSWITCH to JavaScript

s3="From PHP we've got:"+symbolspace('s_output')
document.write(s3)


I believe that the .NET and Java virtual machines allow that sort of functionality, but it won't work out socially, because Java got acquired by Oracle, .NET runs practically only on Windows (no, in 2010 the Mono won't do) and in the end many projects, like Haskell, Python, Perl, etc., have their mainstream implementations on "bare C or C++", not to mention the extra work that it would take to port them and how a single virtual machine implementation would limit developer creative freedom. May be a solution is a set of automatically inserted, language specific, library calls that dump and load the values of the common data structures to and from something like the Memcached.

I'll update/modify this article, if I have changed my mind on this or made a working implementation of the Memcached biased solution. So, this blog post will probably be modified.

13 Sept 2010

Array Indexing by Separators

In the case of arrays and strings one often needs to extract a sub part of them.

If one uses the indices of the virtual separators between and at the "edges" of the array elements in stead of the indices of the array elements themselves, one can eliminate conditional statements that check indices for critical values at the "edges" of the array.

Explanation by an example:

# Array indices:       0   1   2   3   4
               array=["H","e","l","l","o"]
# Separator indices: 0   1   2   3   4   5


#           0   1   2
GetSubarray(["H","e"],0,0)==[]         # 0-0=0
GetSubarray(["H","e"],0,1)==["H"]      # 1-0=1
GetSubarray(["H","e"],1,1)==[]         # 1-1=0
GetSubarray(["H","e"],1,2)==["e"]      # 2-1=1
GetSubarray(["H","e"],2,2)==[]         # 2-2=0
GetSubarray(["H","e"],0,2)==["H","e"]  # 2-0=2
GetSubarray(["H","e"],2,2)==[]         # 2-2=0


GetSubarray([],0,0)==[]          # 0-0=0

The thing to notice is, how it is possible to mark empty intervals, including the start edge of the string and the end edge of the string, by using the very same 2 indices that describe a substring start and end positions.

A more permanent version of this post resides here.

25 Jul 2010

The Meaning of Life

As of July 2010, I've come to a conclusion that the ultimate meaning of life, for me at least, is to have as much fun, entertainment, as possible. The amount of fun is equal to a definite integral of fun-power over time. The fun-power is never negative, but it is zero before birth and after death.

Why is that? Well, think of what would one do or want to do, if one could live forever and have perfect health all the time and one could just change one's capabilities, mental and physical, to whatever one wants to, except to remove the capabilities changing capability? What's left then? Entertainment and nothing else and the loss of fun and loved people around me would decrease the amount of entertainment. (Loss does not always have to mean death or "destruction". One does lose every-day objects without destroying them.)

So the way to maximize fun is to prolong one's life and to increase the fun-power. People differ in how they try to achieve that. For instance, some find it most efficient to rob or kill or just tease, if no one is capable of dying. Others find it beneficial to have an environment where everyone tries to treat others the way they self want to be treated. The idea being that one can better maximize one's own fun by not attending in a zero-sum like game, where the increase of one's own fun entails a decrease of someone else's fun. So, it takes quite a theory and skill to be happy in a paradise. :-)





++++++++++++++++++++

Update at 2013_04_27: There exists "The Meaning of life, Version 2".



20 Jul 2010

The Core of Software Development

In the context of this article a computer program is a function and a "description" means "function description". The computer program as a function gets some input, from wherever, and it produces some output, to wherever in whatever form. So, practically all of the time that software developers spend, is spent on the name of creating that function description.

Summary of the previous section: software is a function description, being a productive software developer means minimizing the time spent on creating the function description. That's the reason, why I speak of functions in this post. :-)

A function can contain a mixture of calls to other functions and to oneself. To minimize the time spent on the assembly of the function description(read: to be a more productive software developer), one aims to minimize the following parameters:


A) number of functions to describe;
B) "mean" number of function calls within a single function;


The point B also covers "simple things" like assignment operators, multiplications, additions, etc.

As we do not live in the world of infinitely fast Turing Machines, additional conditions of memory usage patterns, bandwidth usage patterns, "outer memory" access patterns,  algorithm complexity, hardware speed, energy consumption, sizes of various memories, etc. apply, but as of summer 2010 I believe that it really helps to keep the points A and B in mind while doing practical software development. Software design patterns, which in the end migrate from "pattern" status to programming language specification, are just fine-grained, time-dependent, details of the craft.

Cheers!!!

2 Mar 2010

JavaScript Closure by an Example


function func_c() {
var s_c1 = ' the word "funcy" means ';

function func_b() {
var s_b1 = "http://www.urbandictionary.com/define.php?term=funcy";

var func_a = function() {
var s_a1 = 'According to the <a href="'+
s_b1 + '">' + s_b2 + '</a>' +
s_c1 + s_c2 + s_this;
return s_a1;
} // func_a

var s_b2 = "Urban Dictionary"
return func_a;
} // func_b

var s_c2 = ' actually "trashy", but ';
var ff_a=func_b()
return ff_a;
} // func_c

var s_this = 'it sure sounds like "dirty" in a sexual context.';
var fun = func_c();
var s_sentence = fun();
document.write(s_sentence);


The example can be executed online over here and it outputs a string

According to the Urban Dictionary the word "funcy" means actually "trashy", but it sure sounds like "dirty" in a sexual context.

The thing to notice is how the variables, s_b1,s_b2,s_c1,s_c2,s_this are available to the function func_a, even when the func_a is called outside of the func_c. According to Justin Rogers that can cause memory leaks.

20 Feb 2010

About Physical Appearance, Clothing, hair Style and Preferences for sex Partners and Business Partners

This post probably just shows my stupidity and lack of social intelligence, but I am, what I am. So, in the evening of February, 19'th, 2010, I just wondered about 2 things. Well, may be 3 things, depends on how to look at it.

Firstly, why is it that even though I'm not that interested in sex and disqualify anyone, who is not able to provide me a stunningly intelligent conversation or does not leave me an impression that I can rely on his/her intelligence and understanding of the limits of this world, I still pay a great deal of attention to the physical appearance of him/her?

Like, I try to imagine, how he/she would be in bed, how I would cope with him/her in bed and that's with leaving sexual compatibilities like fast versus slow, etc, to aside. To me it seems that if I'm primarily looking for a sole-mate, then physical appearance shouldn't matter, but the fact is that it does matter. Actually, it even matters with my own case, but that's a different story, which can be handled by fixing the shortcomings, and I do take an assertion that before one loves anyone else, one has to love oneself, for granted.

The second thing that I started to wonder, is that why I still do not have my hair colored to blue, like the Estonian flag colour, and then have my pony-tail coloured black and white, giving blue-black-white, like the Estonian flag colours? One of the thoughts that might occur is that I won't "live it up", or, in Estonian: "kanna seda välja". Well, I think that that's not an issue, because I can be just like I am: dead-serious and deep-sceptical most of the time, without smiles, giving scary looks that are colder than ice, and then, suddenly, laugh from my heart so that people that drive by or whom I walk by, give me shy, but sincere, smiles. Strangely, I guess that the answer to this, the second, issue, is that I'm afraid that people might jump to conclusions that are not favourable to me and that might limit my possibilities to communicate with them in a manner that is favourable to me. Think business. Currently it seems to me that I have to get my business going well before I can afford such personal expressions. (NB! I guess that I just said it all. :)

Well, all in all, I came to a thought that the physical appearance (think of wearing a huge swastika on a back and front of ones T-shirt or drawn to the sides of ones' car) and physical interaction (like, sexually, but also "innocent" hugs, pats, etc.) is part of communication. As of 19.02.2010 that thought gives quite a new meaning to semiotics. To me it seems that the semiotics is all around us all the time, like applied art. One might even call it "applied semiotics", or, may be, I don't know, applied semantics? Semiotics in the context of hair dresses might be quite interesting. Or cars, the may-be-third thing that I started to wonder about. I mean, it does make a difference, if one rolls to or from a business meeting with a beetle, Harley-Davidson, limo or a tuned BMV.











The next thought from here is marketing. As a matter of fact I started to see ordinary, every-day, communication astonishingly differently during a series of marketing lectures that were part of a introductory business course that was held within the Mainori Kõrgkool and conducted by Mrs. Aet Kull. Aren't we doing marketing duering dates? As a matter of fact I've been comparing job interviews with (blind) dates since at least 2004. I find them remarkably similar.

In the context of this post, namely, "applied semiotics" point of view combined with my likes and dislikes, I find the George Michael's video, "Fast Love", very interesting.




23 Jan 2010

My Personal Programming Skills Enhancement Strategy Since January 2010 till ... I Come up With some Better idea

In the end source code is a series of bits that tells the computer, what to do. No matter, what the methodology, be it functional, OO, logic, procedure oriented, etc.

So, putting those 2 claims together, I'm looking for a NOTION, how to EXPRESS myself as concisely as possible, while keeping the rule set as simple and concise as possible. After I've figured that out (there are probably very many different possibilities), I can start to think about the compromises that are probably needed in order to use the currently existing technologies. For instance, I will probably need to use JavaScript for browser side software development, PHP for server side development, C++ for systems programming, etc.

So, it's a conquest for language development. And, by the way, doesn't the real, natural, languages pose exactly the same problem? As of January 2010 I think that they do.

It seems to me that predicate logic is quite inspiring, if just something similar could be defined for cases, where OO or loops or conditional sentences are used. May be one key-phrase is also “order-sorted logic”, whatever that means. (As of January 2010 I still need to learn the “order-sorted logic” stuff.)

So, finding a concise way to express myself is definitely something that I as a programmer need quite direly. I think that I'm not going to make it successfully without that knowledge, but the programming language that I have tried so far, mainly Ruby, C++, Java, Delphi, JavaScript, PHP, but also Prolog, a little bit of Haskell and Clean (and a bunch of others that I've just tasted a little bit), just “don't cut it”. I don't know Scala yet, but according to the introduction it seems to be just another morphism of the existing OO and functional technologies.

Now, one thing that I definitely do know is that the size of vocabulary that I'm able to remember is limited. This infers that the most concise solution, where one just assigns one number to a whole program or code block, is not usable by me.

The search for a solution is probably by trying to manually translate an existing, production, system to that concise version and to see, what constructs there exist. Practically, one tries to do some very wild refactoring, identify the common parts, etc., but without the limitation of a concrete syntax, as the syntax is the one that is being searched for. Also, for every part of the production system, one also analyzes the REASON, why the code segment is necessary, why it has been written in the first place and is it possible to just eliminate the reason, refactor the “reason” out of the code or to do the search for common parts in the context of the “reasons”. For instance there's no reason to install light switches to lights that are in places that do not receive any light from windows and are lit up by energy saving LED light bulbs.

It seems that the ideal specification for the new language is something that is not laborious to implement in the currently existing programming languages. It should be something like the ProgFTE specification. May be some kind of an interpreter that can be very easily and efficiently implemented in JavaScript, PHP, Ruby, etc. and then the software that has been written in that new languages can run truly everywhere. IN PRACTICE. For example, the Java runs only in places where the Java language developers have taken the great effort to port it to. I, for instance, do not always have the luxury of choosing a programming language by myself, because due to the amount of labor my software, very often, has to interface with some legacy parts or just parts that have been written by others or even by myself. Typical cases: GUI, network, sound, hardware access, file access, image file format reading, etc.

13 Dec 2009

About knowledge transfer in High-schools and Universities

As of December 2009 I think that it all should conform to the Brain Rules, which can be followed if everyone learns in a place, where one wants to and at a time when one wants to. For example, a home environment probably provides such possibilities. To be more explicit, if people are mentally active at different times of a day, then a lecture at a given, fixed, time of day definitely ignores some of the student's biological needs.

People also differ in their background, which means that feature X needs a more in-depth explanation to student A and feature Y might need a more in-depth explanation to student B. Therefore, there is a need for private, personal, consultations. On the other hand, a common material is a good thing to start with, because it provides a seed for the consultation sessions and the learning process in general. Usually that common material is in a form of a lecture, lecture notes, or some literature.

It's also a fact that people forget. According to the brain rules, repetition is good, but that does not say, that people do not forget things, if they do not work on the things. It's also known, from practice, that males are better at doing things when they do one thing at a time. As a matter of fact, the switching of activity can be quite unpleasant to some of them, me included. (I also know other people that have had similar observations about themselves.) So, for at least some of the males it makes sense to let them learn one subject at a time. That, of course, does not conform to the testing schedule that assumes that a student has to learn one certain part of the material by a few certain tests in the midst of semester.

I believe that a simple and cheaply implementable solution to the testing issue would be that there is one special classroom with 2 security guards. The classroom is open every workday from morning to evening and anyone in the school or university can come there either by first reserving a time-slot or just by dropping by, if there are any free seats available. One of the security guards, who can be even an elderly lady with thick glasses, prints out the test questions and applies a timestamp and her/his personal stamp to the test. From that moment onwards, the student has a given amount of time to perform the test within that classroom, without using his cellphone or laptop. One of the security guards makes sure that the cellphones, nor laptops are used. When the student is ready with the test, he/she hands the test back to the old-lady security guard, who then applies a second timestamp to the test and later, at the end of her work day delivers all of the tests to different lecturers for evaluation. This way, any student can take any test at any time he/she is ready for taking it. The only requirement imposed to the student might be that all of the tests have been passed by the end of the semester. The professor, lecturer, benefits from that system, because he/she is freed up from the dull and boring activity of sitting in the classroom while students take their tests.

What regards to the lectures, then those might be just made available for download and all that the lecturer, professor, has to do, is to provide personal consultation and evaluate the tests.

Well, may be someone might even start to provide the services of such a testing-center to multiple private, or even public, universities, schools, private educators. The old-lady security guard might be even some pensioner, who can watch soap operas while there's no one asking for or handing in a test.

One Thought About the Transhumanism and Nazism

As the future relies on the standing on the shoulders of giants and as the software development has demonstrated that one of the prerequisites of keeping the amount of labor in a feasible limit is by recombining previously completed components, it's no wonder that I do not always have much to add. So, some of my articles, starting with this one, are a combination of citations and a small amount of my own thoughts. And yes, I know, that many people HATE video, photo and sound based citations, but they have an option not to read my posts. I think that a person's time IS equivalent to a part of that person's LIFE.

Well, here it goes. First, I think that the following video explains the political and social aspects of artificial intelligence, without applying the percentage of non-informing SciFi mystification that tends to be added to the topic in many technology popularization texts.


As of December 2009 it seems to me that it is racist to apply segregation laws to that highly intelligent machines, because humans, tehcnically, are not better and the distinction is purely based on the difference in “species”.

As of December 2009 I personally love the idea of cyborgs, because humans can't survive in cold winter without clothing, I.e. self-enhancements, tools. Drugs, artificial joints, glasses, hearing aids, are, according to my view, exact examples of cyborgization. If evolution takes thousands of years, then cyborgization is something that one can use before dying. For instance, if brain prosthesis become stable enough and the computing technology miniature and mature enough, then I hope to have brain enhancement. I believe that it does not hurt if the thinking part of the brain has more computational power than currently can fit into the skull.

And, in that light, the artist called Haddaway has a darn good song:

5 Oct 2009

Programmer Friendly text Exchange (ProgFTE)

(This is edited version #7 of this post.)

There are 2 versions of the ProFTE specifications. As of January 2013 the most up to date version is the ProgFTE_v1.  The rest of the text in this blog post describes the ProgFTE_v0, which originates from 2009.




ProgFTE Specification Version 0 (ProgFTE_v0), which is superseded by ProgFTE_v1



For short: each key-value pair of a hash-table is encoded as:

keyAsText|||ValueAsText|||

The text versions of the key-value pairs are concatenated and one can even use JSON/YAML/XML/almost-whatever strings for the value part, except that one also has to make sure that neither the key, nor the value, contains the literal “|”. This can be overcome by replacing the “|” within the keys and values with some string (one calls it hereafter: pillarSubstString) that does not occur within the keys and values.

For decoding, one has to write a function that BISECTS a string at the first occurrence of a search-string. In this case, the search-string is the “|||”. For example, bisect(“simpler|||than|||XML|||”,”|||”) would output a PAIR that consists of string “simpler” and string “than|||XML|||”.

The reason, why "|" is replaced in stead of the "|||" is that if a key or value contains "|" or "||" as its suffix (one omits the analyzing of the prefix case for now), one ends up with <key or value without suffix>|||| or <key or value without suffix>|||||, which makes the finding of the "|||" problematic.

So, all in all, the format is:

NumberOfKeyValuePairs|||pillarSubstString|||key1AsText|||value1AsText|||key2AsText|||value2AsText|||etcOtherKeyValuePairs

The number of key-value pairs is prefixed to avoid the counting of the “|||” at deserialization.

The reason, why the separator string is "|||" in stead of the more space/traffic efficient "|" is that the "|||" is easier to read during debugging and the "|" and the "||" already have historic meanings in software development.

The main benefit of this format is that one can implement it in different languages with relatively little amount of work. That includes exotic languages, self made, domain specific languages, that do not have extensive XML or JSON or other "mainstream" format libraries available. An example application is a website, where the server side has been written in PHP or Java and the client side has been written in JavaScript (keyword: AJAX) or some JavaScript based Scheme dialect.

The secondary benefit comes from the comfort of using hashtables.

--------

Update on 22 December 2011

Actually, the format that is described in this post, is in use in the real world and has worked without problems, but unfortunately that's pure luck, because the format(ProgFTE_v0) is flawed and I have a new, improved, specification in the works. (Update on 03 January 2013: the new specification  is called ProgFTE_v1.)

If (Hash.new)["nice_key"]="Cariba|" and the pillarSubstString=="baba", then the ProgFTE is

1|||baba|||"nice_key"|||Caribababa|||

There is an issue, how to reverse-translate the "bababa" part of the "Caribababa". Should it be "Cari|ba" or "Cariba|".

The good news is that one can distinguish the old version of ProgFTE, the one described in this blog post, from the new one and simply improve the ProgFTE libraries of the real world application, without any need to convert saved data. The old version, the one in this blog post, always starts with a number, but the new version always starts with a letter "v", like "v<format_version>". I'll update this blog post after I have shipped the new version.

17 Aug 2009

JavaScript __LINE__ and “this” Substitutes

Leaving a longer explanation to aside, the following code demonstrates, how to overcome the absence of the __LINE__ and the proper semantics of the “this” in the JavaScript.

function niceclass(){
    var self_public_=this; // Yes, that's the first "innovation".

    this.a_public_field='whatever';
    function a_private_method(){
        document.write('Public fields value is:'+self_public_.a_public_field);
    }

    this.a_public_method=function(){
        try{
            a_private_method();
        } catch (err){
            // If all of the methods have try-catch-s with
            // Globally Unique Identifiers Copy/Pasted from
            // http://www.guidgenerator.com/ , then
            // it's possible to find out the faulty region even
            // when the JavaScript does not have the __LINE__ support.
            throw "GUID== ba6e3063-9438-42a4-a041-e8fd635fb4c5"+
            "\nerr=="+err+"\n------------------------\n";
        } // catch
    } // this.a_public_method
} // niceclass

window.onload=function(){
    var v1=new niceclass();
    v1.a_public_method();
    v1.a_public_field='Another value';
    v1.a_public_method();
} // window.onload

For the sake of correctness, I have to give credit to the http://www.quirksmode.org/js/this.html and the
http://jspro.org/. Of course those were not the only sources, but as of August 2009 I found them to be the best that I could find.

++++++++++++++++++++++

Update at 2013_04_27:
Tools for debugging and editing GUID-marked JavaScript reside within the BSD-licensed GUID_trace package, which is part of the mmmv_devel_tools package.

The GUID_trace package components assume that GUID-s are surrounded by either double quotes or single quotes, like
 
GUID=="ba6e3063-9438-42a4-a041-e8fd635fb4c5" 
GUID=='ba6e3063-9438-42a4-a041-e8fd635fb4c5'


3 Aug 2009

About the Feasibility of Hydrogen as a Gasoline Replacement

According to my calculations, if one compares gasoline and energetically identical amount of hydrogen, then the price of a gasoline forms about 86% of the price of the hydrogen provided that only green electricity is used for producing the hydrogen and that there are no energy losses within the hydrogen production process.
The price of energetically equivalent amount of jet fuel, kerosene, forms about 90% of the price of the hydrogen.

Conclusion: both, in the case of cars and flying machines, the green electricity based hydrogen seems to be economically feasible, but unfortunately it would still be too expensive to make it affordable to have helicopter based ambulances in regular use. For example, a 300km two-way flight with the Eurocopter AS365 seems to cost at least about 200 Euro-s.

The good news is that if someone figures out a way, how to decompose water by using solar energy and some microbes or chemical reaction, then the hydrogen based aviation might become affordable. :-)

The Mathematica notebook source:

(* All of the following calculations are about one litre of gasoline.*)

Needs["Units`"];
litersPerGallon = 3.78541 Liter/Gallon;
cubicMetersPerGallon = litersPerGallon/(1000*Liter)*Meter^3;

(* http://www32.wolframalpha.com/input/?i=gasoline *)

gasolineEnergy = 47.73 *10^6 Joule/Kilogram;
gasolineDensity = 0.735*10^6*Kilogram/(1000*Meter^3);

gasolineEnergyPerCubicMeter = gasolineDensity*gasolineEnergy;
gasolineEnergyPerLiter = (gasolineEnergyPerCubicMeter*Meter^3)/(
1000*Liter);
eurosPerKroon = 1/15.7 *Euro;(* www.seb.ee *)

greenElectricityUnitPrice = 1.8*eurosPerKroon;
gasolinePriceLiter = 15*eurosPerKroon
gasolineEquivalentElectricitySalesUnits = (
gasolineEnergyPerLiter*(1*Liter))/(3600000 *Joule);
gasolineEquivalentGreenElectricityPrice =
gasolineEquivalentElectricitySalesUnits*greenElectricityUnitPrice
ratioGasoline = \
gasolinePriceLiter/gasolineEquivalentGreenElectricityPrice



dollarsPerKroon = 1/12*Dollar; (* www.seb.ee *)

eurosPerDollar = eurosPerKroon/dollarsPerKroon;

(* http://www32.wolframalpha.com/input/?i=kerosene *)

keroseneDensity = (0.819*10^6*Kilogram)/(1000*Meter^3);

(* http://hypertextbook.com/facts/2003/EvelynGofman.shtml *)

keroseneEnergy = 42.8*10^6 Joule/Kilogram;
keroseneEnergyPerCubicMeter = keroseneDensity*keroseneEnergy;

(* http://www.nyserda.org/energy_information/nyepg.asp
http://www.iata.org/whatwedo/economics/fuel_monitor/index.htm
*)
kerosenePricePerGallon = (5*Dollar)/Gallon*eurosPerDollar;


gasolineEquivalentKeroseneMass =
gasolineEnergyPerLiter/keroseneEnergy*(1*Liter);
gasolineEquivalentKeroseneVolume = gasolineEquivalentKeroseneMass/
keroseneDensity;
gasolineEquivalentKeroseneVolumeGallons =
gasolineEquivalentKeroseneVolume/cubicMetersPerGallon;
gasolineEquivalentKerosenePrice =
gasolineEquivalentKeroseneVolumeGallons*kerosenePricePerGallon
ratioKerosene = \
gasolineEquivalentKerosenePrice/gasolineEquivalentGreenElectricityPrice


(* http://www.eurocopter.com/site/en/ref/Characteristics_99.html *)

eurocopterAS365Power = 700*10^3 Joule/Second;
eurocopterAS365Speed = 269000/3600*Meter/Second;
distanceFromHospital = 300*10^3 Meter;
flightDistance = 2*distanceFromHospital;
flightTakeoffsAndLandingsDuration = 15*60*Second;
flightDuration =
flightDistance/eurocopterAS365Speed +
flightTakeoffsAndLandingsDuration;
flightDurationInHours = flightDuration/(3600*Second)*1.0*Hour

flightEnergy = flightDuration*eurocopterAS365Power
flightEnergyPriceElectricity =
flightEnergy/(3600000*Joule)*greenElectricityUnitPrice

6 Jul 2009

About Caring for Others

This posting is a mixture of some of my beliefs and some thoughts. One of their common denominators is that as of July 2009 I believe them to be true. I will probably think differently in the future.

So called axioms or, in a laxer context of this posting, automatic thoughts:

Different people mostly differ in their objective function

People always use their most up to date version of their objective function, even if the objective function contains some inherent random variables.


When people agree to participate in a transaction, they act only according to their own objective function. (The way the Noam Chomsky put it: if 2 people perform a transaction, let's say, one person sells another person a car, then the 2 parties only care about their own profits and do not take to account the cost of the transaction to third parties.)

Money is just one, though very important, type of currency out of many.


Some implications, which seem to match with observations:

In business people do not mind participating in transactions, where the other side has a terrible disadvantage. An example: whenever there's enough people in a bad enough situation to find a sweatshop a viable working environment and if sweatshops are legal, sweatshops will emerge.

Love is not free. Sometimes some part of it can, indeed, be payed with money, but just like one has to repay a bank loan in Estonia in Euros, while the local currency is Kroon, one has to pay for love with a fine company and physical attraction.

In the case of employee-employer and buyer-seller relationships there are cases, where the selling side does not expect to receive only money. For example, in some cases respectful treatment is also expected, in addition to the money.

Hunting of animals, including humans, does not constitute a murder as long as the hunted do not enforce themselves. (Illustrations: deer hunting, the slaughter of Iraq citizens by united states army and security forces, civilian deaths of United States drone attacks in Pakistan, the holocaust imposed by the Israeli army to the people within the Gaza Strip in 2009, fishing, etc.)

Even people at noticeably honored positions, for example, university professors, don't mind stealing and deceiving in a way that is even worse than that of common pocket thieves. (I won't name anybody, but I know one such case really well.)


What I think that is useful or harmful for the other person probably differs from his or hers own view, because his or her objective function probably differs from mine. (I have also noticed that my views have a much greater match with the views of those people, who have somewhat similar background, let's say, that of other programmers, physicists. For some reason the decisions of people with economics background tend to seem the craziest to me. That is to say, for some weird reason biologists and philologists tend to be much more similar to me than economists.)

One of the questions that might be of interests at the notion of those statements is:
What is to be wanted from a truly true and affectionate lover?

This question has been inspired by an erotic story, where a daemon changes to a passionate lover and a true companion of its disenchanter, while requiring human sperm to stay alive.

From the love perspective there's also a question that if there were a robot, like in the movie Alien Resurrection, with technical ability to attend one's daily life, i.e. shopping, sports, leisure, work, etc., and the robot had comparable or greater intelligence than that of fellow humans, then why should someone fall into love with another human in stead of that robot?



A side-note: As of July 2009 I still find the movie, Alien Resurrection, inspiring. I think that it is one hell of a well done movie in multiple contexts. May be it's because it somewhat summarizes my career, interests, goals and desires (provided that the violence part of the movie is skipped)?

15 Jun 2009

About the Alternative to Knowing Everything

There's a saying, at least in Estonia, that the one, who knows everything about everything, knows nothing at all.

I actually tended to agree with that saying, but, unfortunately, the situation, where I am currently(June 2009), sounds like: “Know everything or become an asocial and die.”

The controversial part is that if one works for one company, becomes specialized in the set of skills, technologies, that are needed at that given position, and then the company reduces staff, goes to bankrupt or just changes business directions, it's next to impossible to find another company, where the acquired skill set is relevant. Specially in a small place like Estonia, where the number of companies is relatively small. As of 2009 there's about 10 companies of each type: banks, security firms, robotic engineering companies, universities, fine hospitals, etc., with an exception of web development companies and consumer product marketing firms.

One might think that, great, one learns web development and one has a secure future. However, I don't think that that's the case, because before the web boom, the type of applications that are now implemented as web based software, i.e. all sorts of business automation related software, was written in Delphi, C++, using Microsoft Foundation Classes, etc. Therefore, I think that it's not possible to say that the things that the businesses currently pay for, are the ones that they will pay for in the future. In another words, if I make an effort to become a top notch web developer, I'll be exactly in the same position, where I am today: I acquired a set of skills, became really good at it, and after getting sacked, for whatever reason, I have difficulties finding a job, where I can say that I'm the top notch specialist for You.

Leaving a long contemplation to aside, I have an urge to bring in a question, what would the job market look like, if machines were much more ample at mental activities, let's say, at jobs that human programmers do nowadays? What would happen to people, in a social context, who do not use brain implants, enhancements, if some other people did use brain enhancements? I mean, the ones that don't, probably will not have any chance at the job market, or will they?

So, in order to be in a different situation after, let's say, 30 years from now, I have to change something in my strategy.

Programming takes a hell of a lot of effort and time, and I want to be at least payed reasonably for making this effort. For example, at one of my positions, at a company that I intentionally will not name here, I learned one programming language from ZERO to an expert level within 3 months, in addition to the company specific technologies and standards. Then the company just sheds about half of its staff. Leaving one small project to aside, all of the development work was halted and obviously there was no need for a brand new programmer, who has been with the company for just about 4 months. And yes, from my perspective, it really seemed that I did not have such a rough times even at the university examination period, as I had while working at that company. I did not receive even a lay-off compensation, because they sacked me literally at the very last day of my trial period. (Actually the story is a little bit more complicated. The CEO got also sacked and the new CEO applied structural changes and applied the layoffs and even that's not all of the story.)

Anyways, the idea is that I know, from my personal experience, that I am capable of learning new technologies and relatively quickly. The described example is not the only example, but I'll skip the description of other cases here. However, coming back to the brain enhancements example, quick is not quick enough. One has to go faster in order to earn a living. As specializing only to a single technology for 5+ years (as requested in many job adverts) is unfeasible, one can only convince potential customers to accept results based pricing. The opposite would be hourly or monthly wage. But this means that one still has to be capable of doing the job at an expert level, which brings me to a question: how do I manage to do that?

Well, the answer is: I don't know. However, it seems to me that I don't stand a chance, if I don't figure that one out. There are no brain-enhanced competitors in the real world, but the job market of today's economic situation seems to impose plain human programmers to a situation that seems to be quite similar to the one, where the brain-enhanced competitors do exist.

May be I'll post something to my blog, if I come up with something along those lines of life.