Profile cover photo
Profile photo
Panu Viljamaa
91 followers -
NODE.JS IS THE NEW SMALLTALK
NODE.JS IS THE NEW SMALLTALK

91 followers
About
Panu's posts

Post has attachment
How to know your Ancestry

function ancestry (ES6Class)
{
// Return an array of ancestor classes
// of the argument, closest one first
// Object last. If argument is not a
// a function return the ancestors
// of its class/constructor

if (ES6Class === Object)
{ return [];
}

if (typeof ES6Class !== "function")
{ ES6Class = ES6Class.constructor;
}
var ancs = [ ];
var Anc = ES6Class .prototype . __proto__ .constructor;
while (Anc && Anc !== Object)
{ ancs.push (Anc);
Anc = Anc .prototype . __proto__ .constructor;
}
ancs.push(Object);
return ancs;
// Copyright © Panu Viljamaa 2017
// This code can be used under the terms of
// https://creativecommons.org/licenses/by/2.0/legalcode
//
}

The Genius of Split Screen Code-Editors

Like DNA, computer-code is much based on copying parts of older code. At the same time that is the part of the process where errors can and are introduced.

So when copying parts of existing code to new code it helps greatly if you can see the code from which to copy and the new code into which to implant the copied parts AT THE SAME TIME. That is what split-screen -mode of your code-editor is for.


Post has attachment
"Back in the 1980s, LISP machines such as the Symbolics 3600 provided hardware support for runtime type checking. Could we do something similar for dynamically typed languages today?"

https://blog.acolyer.org/2017/05/22/typed-architectures-architectural-support-for-lightweight-scripting/

Difference between Arrays and Tuples

An Array is an ordered data-structure with unlimited number of elements each of which must be an instance of the same single element-type of the array it is part of.

A Tuple is is an ordered data-structure with a fixed number of elements which can be of unrelated types. Tuples are often implemented as Arrays. But don't confuse their implementation with their "type".

By giving away the ability to have unlimited number of elements (as in an Array) , you gain the ability for each element to be of different type (in a Tuple). And there is no limit to the number of components each element-type of a Tuple might have.

So you can have an unlimited number of data-elements by using an Array, but limited number of element-types, one . Or you can have an unlimited number of Type-elements but only a fixed number of data-elements, in a Tuple.

Then why don't we have a data-type which would allow both an unlimited number of elements for their instances, and an unlimited number of element-types? BECAUSE such a type would not be very helpful since it would not be an abstraction, it would not describe a set of objects, it would basically just describe itself, because it would have no constraints on its elements, neither on their type, nor their count.


Waves do not really "travel" in the sense that a train or car or person would travel. What happens is that there is a difference in the strength of an electric field or gravitational field or pressure-field (if you think of water and air). A force (or "field") like electricity or gravity has a force that will cause an effect on other bodies over distance even over vacuum. But it takes time for us to observe any change in the strength of such a force. So that is what we usually mean when we say that "waves travel".

So how can one body effect a force on other bodies even if there is only vacuum between them? I'm not sure there's a really good answer to that in the current physics. But the fact that vacuum is said to be full of virtual particles, that there in fact is no such thing as "vacuum" after all, maybe gives us a clue that there's no reason to think that it should be impossible (and our observations tell us it's not). If we don't really understand what vacuum is we can't really understand how forces can have an effect across it. 

Post has attachment
It's not a good idea to periodically change your password, and especially not to require your users to do so. Now it's official.

Why? Because quantity does not replace quality. The chain is only as strong as its weakest link. If people are required to change their password periodically they are more likely to choose weak passwords, because they still need to remember their password. If they can keep on using the same password for a longer time they can more easily remember it, and thus are more likely to use and memorize a stronger one.

http://www.ibtimes.com/my-password-secure-nist-advises-against-periodically-changing-passwords-2541293

Post has attachment
Golden Common Lisp

I started my Lisp programming career with Golden Common Lisp. It was golden. One of the selling points of it as I remember was the ability to "return multiple results" from a function. Now JavaScript ES6 too has "Destructuring Assignment" which in essence does the same thing. Very useful. JavaScript getting closer to its Lisp-origins.

According to the link below Golden Common Lisp is still being sold, no wonder.


http://www.edm2.com/index.php/Golden_Common-LISP

Post has attachment
A typical stock, meaning most stocks, perform worse than Treasury Bills. But diversified portfolios perform better than Treasury Bills. How is that possible? It is possible because average return of stocks is higher than their median return.

How is that possible? It is possible because there are some stocks like Apple which perform so much better than the typical stock.

Well then aren't there some stocks which perform much worse than the typical stock which should counter-balance that? No, because downside is limited. You can only lose as much as you own. Whereas upside is unlimited, the stock can go higher and higher.

But remember that a non-typical winner-stock like Apple is NOT likely to keep on going higher in the future. There is no reason to expect it would just because it did so in the past.

https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2900447

Post has attachment
On the Origins of K&R Code-Formatting Convention

Kernighan & Richie code-formatting convention (link at the end) means you
should format your functions so that the opening "{" is at the end of the line if there is non-white-space content on the same line:

function krTest () {
return 123;
}

I often wondered why would anybody think that is good? It looks unbalanced to me. Whereas aligning the opening and closing braces vertically makes it easy to see which closing bracket corresponds to which opening bracket. Like this:

function nonKrTest ()
{ return 123;
}

So why K&R and how did it get started? Of course, it was used in their book (see link below). But why did they use it?

I don't know, but I suspect it is because of shortcomings of early parser technology. A shortcoming in the parser as to what kind of syntax it can understand. If the opening "{" were not on the same line as the function-header then it would have been too difficult for an early parser to understand it. Is that possible?

Well consider that even today in JavaScript you can write:

function test ()
{ return
{ x: 1
}
}

Guess what the result of the function "test()" is? It is undefined. UNDEFINED. It is undefined because "{" before "x" is NOT on the same line as the "return".

To make that function do something useful we must rewrite it as:

function test2 ()
{ return {
x: 1
}
}

Now the result of test2() is what we want, no longer undefined.

The problem was fixed by using the Kernighan & Richie code-formatting convention! That, I suppose, is the reason why we must use it :-) .

https://en.wikipedia.org/wiki/Indent_style#K.26R



Post has attachment
Wait while more posts are being loaded