Monday, December 14, 2015

node-gyp installation cl.exe missing


A common problem when you try to install karma, mean stack or other node modules that depend on gyp module. You see following message:
TRACKER : error TRK0005: Failed to locate: "CL.exe". The system cannot find the file specified. [d:\worek\gitHub\meanPlayground\play
ground\node_modules\bufferutil\build\bufferutil.vcxproj]
In many places you will see that you are missing VS2013 compiler, and you will be asked to install Microsoft Visual Studio Express 2012 for Windows Desktop. Do not do it if you are running VS2015, just add feature in VS: Common Tools For Visual C++ 2015.

Under the hood it will still install multiple 2013 components - ech, and the year is almost 2016.

Monday, October 26, 2015

InteliJ is a joke part1


I already can see that there will be part2 and followups. I totally do not understand how as popular language as Java lacks a good and modern IDE. I started to write a code in Java 8.

I created a new project and I had to manually point IDEA to a location of my Java SDK - guys how silly is that. Why not figuring out at least the default Java location from PATH, or check JAVA_HOME variable. How about making programmers life easier!

But I still was not able to write using Java 8! First I had to deal with lambda expressions not supported at this language level error. But that wasn't it, then I was greeted with javactask source release 8 requires target release 1.8 problem. Somehow IDEA thought that I was going to code using Java in version 1.5. I can't believe it, I don't have any other version then 1.8 installed on my machine and it is 21 century; why would I want to code by default in Java 1.5?

I will just add that I am using the newest IDEA IDE; current version is 14.1.

Documentation for Maven archetypes

I don't start new projects in Java often. Each time I do it I have to go thru terribly written Maven documentation. 10 maybe 13 years ago when I was writing my first projects with Maven documentation was terrible and absolutely nothing has changed. If I didn't know what I am looking for I would be terribly lost. Even when I know what I want it takes me huge amount of time to figure out how it is labeled in Maven project. Have a look at a difference between Simple and Quickstart project archetypes.
  1. Simple: An archetype to generate a simple Maven project.
  2. Quickstart: An archetype to generate a sample Maven project.

Wow, now I learned something definitely. Guys, what is the difference between simple and sample. Which archetype should be used just to create a playground application to write some code and unit test it. I mean library project type. I just want to run tests on my code to check something.
What a wonderful explanation we get when we dig into a given archetype. When you click on Simple project you see this. What is it - empty page. Maybe some explanation of what do I see here. Not to mention that I would expect to see a in depth explanation of when should I use it and why should I use this one.
I am speeches, how can you have something like that. The sad part is that Maven is not the only project in Jave world that is terrible in documentation.
To answer my question about which archetype to use. I recommend using quickstart, that will create a following project structure.
project
|-- pom.xml
`-- src
    |-- main
    |   `-- java
    |       `-- App.java
    `-- test
        `-- java
            `-- AppTest.java

Monday, October 12, 2015

Object Oriented Programming - why the term, and are 3 principles of object oriented programming correct.

I had to explain the history of this phrase multiple times, so I gathered here some sources from Alan Key inventor of OOP as a prove that what he had in mind when he invented the term was not:
  1. 1) Encapsulation
  2. 2) Inheritance
  3. 3) Polymorphism
Date: Wed, 23 Jul 2003 09:33:31 -0800 To: Stefan Ram [removed for privacy] From: Alan Kay [removed for privacy] Subject: Re: Clarification of "object-oriented"

Hi Stefan --

Sorry for the delay but I was on vacation.

At 6:27 PM +0200 7/17/03, Stefan Ram wrote:

Dear Dr. Kay,

I would like to have some authoritative word on the term "object-oriented programming" for my tutorial page on the subject. The only two sources I consider to be "authoritative" are the International Standards Organization, which defines "object-oriented" in "ISO/IEC 2382-15", and you, because, as they say, you have coined that term.
I'm pretty sure I did.

Unfortunately, it is difficult to find a web page or source with your definition or description of that term. There are several reports about what you might have said in this regard (like "inheritance, polymorphism and encapsulation"), but these are not first-hand sources. I am also aware that later you put more emphasis on "messaging" - but I still would like to know about "object oriented".

For the records, my tutorial page, and further distribution and publication could you please explain:

When and where was the term "object-oriented" used first?
At Utah sometime after Nov 66 when, influenced by Sketchpad, Simula, the design for the ARPAnet, the Burroughs B5000, and my background in Biology and Mathematics, I thought of an architecture for programming. It was probably in 1967 when someone asked me what I was doing, and I said: "It's object-oriented programming".

The original conception of it had the following parts.

I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages (so messaging came at the very beginning -- it took a while to see how to do messaging in a programming language efficiently enough to be useful).
I wanted to get rid of data. The B5000 almost did this via its almost unbelievable HW architecture. I realized that the cell/whole-computer metaphor would get rid of data, and that "<-" would be just another message token (it took me quite a while to think this out because I really thought of all these symbols as names for functions and procedures.
My math background made me realize that each object could have several algebras associated with it, and there could be families of these, and that these would be very very useful. The term "polymorphism" was imposed much later (I think by Peter Wegner) and it isn't quite valid, since it really comes from the nomenclature of functions, and I wanted quite a bit more than functions. I made up a term "genericity" for dealing with generic behaviors in a quasi-algebraic form.
I didn't like the way Simula I or Simula 67 did inheritance (though I thought Nygaard and Dahl were just tremendous thinkers and designers). So I decided to leave out inheritance as a built-in feature until I understood it better.
My original experiments with this architecture were done using a model I adapted from van Wijngaarten's and Wirth's "Generalization of Algol" and Wirth's Euler. Both of these were rather LISP-like but with a more conventional readable syntax. I didn't understand the monster LISP idea of tangible metalanguage then, but got kind of close with ideas about extensible languages draw from various sources, including Irons' IMP.

The second phase of this was to finally understand LISP and then using this understanding to make much nicer and smaller and more powerful and more late bound understructures. Dave Fisher's thesis was done in "McCarthy" style and his ideas about extensible control structures were very helpful. Another big influence at this time was Carl Hewitt's PLANNER (which has never gotten the recognition it deserves, given how well and how earlier it was able to anticipate Prolog).

The original Smalltalk at Xerox PARC came out of the above. The subsequent Smalltalk's are complained about in the end of the History chapter: they backslid towards Simula and did not replace the extension mechanisms with safer ones that were anywhere near as useful.

What does "object-oriented [programming]" mean to you? (No tutorial-like introduction is needed, just a short explanation [like "programming with inheritance, polymorphism and encapsulation"] in terms of other concepts for a reader familiar with them, if possible. Also, it is not neccessary to explain "object", because I already have sources with your explanation of "object" from "Early History of Smalltalk".)
(I'm not against types, but I don't know of any type systems that aren't a complete pain, so I still like dynamic typing.)

OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I'm not aware of them.

[Also,] One of the things I should have mentioned is that there were two main paths that were catalysed by Simula. The early one (just by accident) was the bio/net non-data-procedure route that I took. The other one, which came a little later as an object of study was abstract data types, and this got much more play.

If we look at the whole history, we see that the proto-OOP stuff started with ADT, had a little fork towards what I called "objects" -- that led to Smalltalk, etc.,-- but after the little fork, the CS establishment pretty much did ADT and wanted to stick with the data-procedure paradigm. Historically, it's worth looking at the USAF Burroughs 220 file system (that I described in the Smalltalk history), the early work of Doug Ross at MIT (AED and earlier) in which he advocated embedding procedure pointers in data structures, Sketchpad (which had full polymorphism -- where e.g. the same offset in its data structure meant "display" and there would be a pointer to the appropriate routine for the type of object that structure represented, etc., and the Burroughs B5000, whose program reference tables were true "big objects" and contained pointers to both "data" and "procedures" but could often do the right thing if it was trying to go after data and found a procedure pointer. And the very first problems I solved with my early Utah stuff was the "disappearing of data" using only methods and objects. At the end of the 60s (I think) Bob Balzer wrote a pretty nifty paper called "Dataless Programming", and shortly thereafter John Reynolds wrote an equally nifty paper "Gedanken" (in 1970 I think) in which he showed that using the lamda expressions the right way would allow data to be abstracted by procedures.

The people who liked objects as non-data were smaller in number, and included myself, Carl Hewitt, Dave Reed and a few others -- pretty much all of this group were from the ARPA community and were involved in one way or another with the design of ARPAnet → Internet in which the basic unit of computation was a whole computer. But just to show how stubbornly an idea can hang on, all through the seventies and eighties, there were many people who tried to get by with "Remote Procedure Call" instead of thinking about objects and messages. Sic transit gloria mundi.

Cheers,

Alan Kay




Alan Kay has argued that message passing is more important than objects in OOP, and that objects themselves are often over-emphasized. The live distributed objects programming model builds upon this observation; it uses the concept of a distributed data flow to characterize the behavior of a complex distributed system in terms of message patterns, using high-level, functional-style specifications.




I was too blythe about the term back in the 60s and should have chosen something like "message oriented" – Alan Kay
There is excellent answer in SO that targets this question:
Actually Alan Kay didn't have Smalltalk in mind when he came up with the term "object oriented programming":

At Utah sometime after Nov 66 when, influenced by Sketchpad, Simula, the design for the ARPAnet, the Burroughs B5000, and my background in Biology and Mathematics, I thought of an architecture for programming. It was probably in 1967 when someone asked me what I was doing, and I said: "It's object-oriented programming".

The original conception of it had the following parts.

I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages (so messaging came at the very beginning -- it took a while to see how to do messaging in a programming language efficiently enough to be useful).
I wanted to get rid of data. The B5000 almost did this via its almost unbelievable HW architecture. I realized that the cell/whole-computer metaphor would get rid of data, and that "<-" would be just another message token (it took me quite a while to think this out because I really thought of all these symbols as names for functions and procedures.
My math background made me realize that each object could have several algebras associated with it, and there could be families of these, and that these would be very very useful. The term "polymorphism" was imposed much later (I think by Peter Wegner) and it isn't quite valid, since it really comes from the nomenclature of functions, and I wanted quite a bit more than functions. I made up a term "genericity" for dealing with generic behaviors in a quasi-algebraic form.
I didn't like the way Simula I or Simula 67 did inheritance (though I thought Nygaard and Dahl were just tremendous thinkers and designers). So I decided to leave out inheritance as a built-in feature until I understood it better.
Smalltalk was the result of this conception, borrowing and extending the concepts of "object" and "class" from Simula, which Simula in turn inherited from ALGOL, as described on "The development of the Simula languages" by Kristen Nygaard and Ole-Johan Dahl (1978, page 253):

In ALGOL, blocks (including procedures) are seen externally as generalized operations. By introducing mechanisms for quasi-parallel sequencing, ~essentially the same construct could play the role of processes in parallel, and through mechanisms for naming block instances and accessing their contents they could function as generalized data objects. The essential benefits of combining data and operations in a single construct were already there to be explored.

One result of this exploration was the discovery that "procedure attributes" might be useful. The following example of a class of "abstract" car objects is quoted from the Language Definition document (Dahl and Nygaard 1965), sect. 5.3.
Further inspiration, especially for sub-classing, was C.A.R. Hoare's record class (page 258):

The subclass idea of Hoare (68) was a natural starting point, but there were two difficulties:

We needed subclasses of processes with own actions and local data stacks, not only of pure data records.
We also needed to group together common process properties in such a way that they could be applied later, in a variety of different situations not necessarily known in advance.
Much time was spent during the autumn of 1966 in trying to adapt Hoare's record class construct to meet our requirements, without success. The solution came suddenly, with the idea of "prefixing", in December 1966. We were thinking in terms of atoll booth on a bridge, with a queue of cars which were either trucks or buses. (This example reappears in (Dahl and Nygaard 1968)).
The terms "class" and "object" also appear on SIMULA 67 COMMON BASE LANGUAGE by Ole-Johan Dahl, Bjorm Myhrhaug, and Kristen Nygaard (pages 4-5):

The block concept corresponds to the intuitive notion of "sub-problem" or "sub-algorithm" which is a useful unit of decomposition in orthodox application areas.

A block is a formal description, or "pattern" of an aggregated data structure and and associated algorithms and actions.

...

An extended block concept is introduced through a "class" declaration and associated interaction mechanism such as "object references" (pointers), remote accessing", "quasi-parallel" operation, and block "concatenation".
Classes are discussed in more detail in chapter 1.3.3 (page 5):

A central new concept in Simula 67 is the "object". An object is a self-contained program (block instance), having its own local data and actions defined by a "class declaration". The class declaration defines a program (data and action) pattern, and objects conforming to that pattern are said to "belong to the same class".

...
So, although the term "object oriented" wasn't invented yet, both "class" and "object" were used similarly to their modern use before Alan Kay began developing Smalltalk in 1969.

Ivan Sutherland goes as far as identifying Simula as the first object oriented programming language, on Sketchpad: A man-machine graphical communication system (page 4), also recognizing C.A.R. Hoare's, Douglas T. Ross', ALGOL's and Sketchpad's influences:

Nevertheless, Sutherland's attempt to remove the division between users and programmers was not the only system that, in failing to do so, provided the imaginative leap to a new programming paradigm. Nygaard and Dahl's Simula [7] was the first conventional programming language incorporating the principles of object orientation, but Sketchpad's implementation of class and instance-based inheritance (though not called objects) predated Simula by several years.

There appears to have been a common influence through the work of Douglas T. Ross, who is mentioned in the acknowledgements of this dissertation and also cited in the MIT Lincoln Laboratory technical report based on it. Ross sat on the Algol 68 committee with C. A. R. Hoare in the mid-1960s, where his previous work on a record-like data structure (called a plex) influenced Hoare's own ideas on abstract data types [3], later credited by Nygaard and Dahl as the origin of the class definition mechanisms in Simula [7].

Alan Kay's seminal Dynabook project, which led both to the Xerox Star and to the explosion of interest in object oriented programming through his language Smalltalk, was directly influenced by Sketchpad. Kay has written of the fact that the genesis of Smalltalk lay in the coincidental appearance on his desk of both a distribution tape of Simula and a copy of Sutherland's Sketchpad thesis [5]. Kay recognized that the two systems were based on the same underlying type concepts (apparently derived via two different routes from Ross's plex), and that these could form the basis of a more widely usable programming system. In comparing these two routes of influence, Simula was a far larger project than Sketchpad, rightly recognized as the first object-oriented programming language, but we hope that the special emphasis of Sketchpad on supporting abstraction in the user interface itself may yet become viable as a result of ongoing research efforts [2,6].
However Alan Kay, obviously, considers Smalltalk to be the first object oriented language:

Though it has noble ancestors indeed, Smalltalk’s contribution is a new design paradigm–which I called object-oriented–for attacking large problems of the professional programmer, and making small ones possible for the novice user. Object-oriented design is a successful attempt to qualitatively improve the efficiency of modeling the ever more complex dynamic systems and user relationships made possible by the silicon explosion.
and having coined the term, I think there isn't much of a debate there.

To finally answer your question: Some of the core concepts of object orientation did exist on Simula, and on earlier languages like Algol and LISP, but the paradigm itself didn't, hence there wasn't really a need for a name.

Smalltalk was designed with object orientation in mind, at least what Alan Kay thought of as object orientation:

OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I'm not aware of them.
The architecture may seem like an amalgamation of earlier concepts, but its central concepts were introduced by Smalltalk, thus marking the first implementation of the paradigm.

Wednesday, September 30, 2015

A good way to manage WCF connections

A typical problem with WCF connections is that programmer can not relay on using statement to manage a connection. A following code is bad:
using (var client = new SomeWCFServiceClient()) 
{
    //Do something with the client 
}
There are few stackoverflow threads about how to do it. But not a single one of them satisfy my typical needs.

This is how I do it.
In a service class:

IBuildServiceDisposable GetBuildWebService()
{
   return _buildWebService.GetBuildWsClient();
}

private WcfDisposableWrapper<IBuildServiceDisposable> WcfService
{
   get
   {
      return new WcfDisposableWrapper<IBuildServiceDisposable>();
   }
}

public Brochure GetBrochures(BrochureRequest param)
{
  return WcfService.Use(
                GetBuildWebService(),
                client => client.GetBrochures(param));
}
Where the service interface inherits from an interface that was auto generated by client proxy (IBuildService) is defined as:
public interface IBuildServiceDisposable : IBuildService, IDisposable, ICommunicationObject {}
The most important part is implementation of WcfDisposableWrapper class itself:
public class WcfDisposableWrapper<T> where T : ICommunicationObject, IDisposable
{
  public TReturnType Use<TReturnType>(T clientProxy, Func<T, TReturnType> codeBlock)
  {
    bool success = false;
    try
    {
       var returnValue = codeBlock(clientProxy);
       clientProxy.Close();
       success = true;
       return returnValue;
    }
    finally
    {
      if (!success)
      {
         clientProxy.Abort();
         clientProxy.Dispose();
      }
    }
  }
}

Saturday, August 8, 2015

Euler was down again

I don't know why anyone would like to attack sites like EulerProject but it was third time the site was hacked - or maybe it was hacked more times but I don't visit it that often to be aware of it.

Wednesday, July 15, 2015

Jenkins: ERROR: Failed to update

My dev machine was building code correctly, and everything was running. Unfortunately CI environment was throwing following exception.
[iTROPICS-TRUNK] $ "C:\Program Files\TortoiseHg/hg" --config auth.jenkins.prefix=* --config ******** --config ******** --config "auth.jenkins.schemes=http https" update --clean --rev default
abort: C:\Jenkins\Workspace\iTROPICS-TRUNK\src/TTC.iTropics.ServiceReferences/Service References/iTropicsBrokerBuildWS/TTC.iTropics.ServiceReferences.iTropicsBrokerBuildWS.com_tropics_webservice_iTropics_vo_current_common_WSGetAssociatedMiscProductsResponse.datasource: The system cannot find the path specified
ERROR: Failed to update
ERROR: Failed to update
It is because machine hit the maximum path length – 260 chars.

Tuesday, June 23, 2015

gitignore file repository

github hosts a repository for .gitignore files. C# developers are interested in VisualStudio template.
To make NCrunch ignored I had to add additional line:
*ncrunch*

Git remove files that were pushed but are added to .gitignore file

git rm -r --cached . 
git add .
git commit -am "Remove files ignored in .gitignore"

IEnumerable Sum extension for complex type

I was not able to find a simple/working example in internet. This is how to do it:
public static Money Sum<T>(this IEnumerable<T> data, Func<T, Money> selector)
        {
            var money = new Money(0);
            money = data.Select(selector.Invoke).Aggregate(money, (current, selectedMoney) => current + selectedMoney);
            return money;
        }

Saturday, April 18, 2015

WinDbg strikes back

Typical problems with winDbg:

.loadby sos mscorwks
Unable to find module 'mscorwks'


for .NET framework 4+ use
.loadby sos clr

SOS does not support the current target architecture.


I see this exception when I run multiple commands because dump was created on 64 bit arch for 32 bit process (I still recommend taking dump using 32 bit Task Manager that is located under C:\Windows\SysWOW64).
!wow64exts.sw
Helps to run some commands like
!clrstack

Tuesday, February 24, 2015

Universal Google Analytics Event Tracking Problems

I keep receiving a following error under Google GA Debugger plugin in Chrome:

Command ignored. Unknown target: undefined

In Google Analytics (GA) I do not see any events. I am using Universal Google Analytics and I attached it to a page thru Google Tag Manager (GTM).
When I change in GTM Tag Type from Universal Anaytics to Custom HTML Tag and paste manually GA code everything works.

Solution to the problem is to set a Tracker Name in GTM config

and raise events in a following way (Tracker Name is set to internalTrackerName):
ga('internalTrackerName.send', 'event', 'button', 'click', 'View Bookings');

Saturday, February 21, 2015

Python after years

Recently I've been installing python on Windows. I haven't done it for few years now. I was surprised that msi installer by default installs pip with its dependencies. It also comes with a basic IDE. This is really nice. Pip seams to be a standard now. But definitely there are few things that didn't change. A quick look at Django code:

def b85decode(b):
        _b85dec = [None] * 256
        for i, c in enumerate(iterbytes(_b85alphabet)):
            _b85dec[c] = i

        padding = (-len(b)) % 5
        b = b + b'~' * padding
        out = []
        packI = struct.Struct('!I').pack
        for i in range(0, len(b), 5):
            chunk = b[i:i + 5]
            acc = 0
            try:
                for c in iterbytes(chunk):
                    acc = acc * 85 + _b85dec[c]
            except TypeError:
                for j, c in enumerate(iterbytes(chunk)):
                    if _b85dec[c] is None:
                        raise ValueError(
                            'bad base85 character at position %d' % (i + j)
                        )
                raise
            try:
                out.append(packI(acc))
            except struct.error:
                raise ValueError('base85 overflow in hunk starting at byte %d'
                                 % i)

Ech, not much changed since I was looking at python programming style years ago. Its not language fault, it is more about how well people are writing open source code. How much does it take to understand what a method above is doing - the method name is a great help, but to understand implementation takes more than few minutes, and it is far more time than few seconds.

Wednesday, January 28, 2015

Latency Numbers Every Programmer Should Know

I am not sure if 1% of programmers know it, but it is a great reference, kudos to Jeff Dean and Peter Norvig: Latency Comparison Numbers
L1 cache reference                            0.5 ns
Branch mispredict                             5   ns
L2 cache reference                            7   ns             14x L1 cache
Mutex lock/unlock                            25   ns
Main memory reference                       100   ns             20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy              3,000   ns
Send 1K bytes over 1 Gbps network        10,000   ns    0.01 ms
Read 4K randomly from SSD*              150,000   ns    0.15 ms
Read 1 MB sequentially from memory      250,000   ns    0.25 ms
Round trip within same datacenter       500,000   ns    0.5  ms
Read 1 MB sequentially from SSD*      1,000,000   ns    1    ms  4X memory
Disk seek                            10,000,000   ns   10    ms  20x datacenter roundtrip
Read 1 MB sequentially from disk     20,000,000   ns   20    ms  80x memory, 20X SSD
Send packet CA->Netherlands->CA     150,000,000   ns  150    ms
 
Notes
-----
1 ns = 10-9 seconds
1 ms = 10-3 seconds
* Assuming ~1GB/sec SSD

Saturday, January 24, 2015

Adding already existing project to GitHub using command line

A typical problem that I often have, playing with various repositories and frameworks is how to add already existing project to a remote repository. In this tutorial I show how to do it for a GitHub mostly by using a command line. I assume that git environment is already set up and that there is already a working environment that is able to push/pull data from GitHub. For windows the only thing that one has to do is to install GitHub for windows.
  • 1. Create a new repository in GitHub - it means go to GitHub page, login, add a new repository. This is the only step that requires doing something not in a command line. I will create a my-app repository, so it will be available under https://github.com/sagasu/my-app
  • 2. Open a git shell.
  • 3. Navigate to a project directory. Actually you have to 'cd my-app', and be in a directory with a project files.
  • 4. git init
  • 5. git add .
  • 6. git commit -m 'message'
  • 7. git remote add my-app https://github.com/sagasu/my-app
  • 8. git push -u my-app master