siblings 6
Created 2007-Apr-09. Updated 2021-Jul-08.


Edouard de Castro

Stirring news / topics / links

Created 2021-May-17. Updated 2021-Jul-08.

Why I still love scala

It looks nowadays scala is less hyped as a java "replacement" / better java, and more viewed as a too complex language prone to overengineering.

For example, with implicit conversions, operator overloading and method names that could have ~ any characters, it's easy to go overboard, and create monstrous Domain Specific Language looking code (a.k.a. syntactic sugar poisoning ;-). But nobody forces you to do that, and you're free to use sane libraries too. The flexibility to make your code look like some concise DSL is a good thing if it makes it clearer (e.g. akka-http, parser-combinators), but not just for the sake of it.
Non binary compatibility between minor scala releases is also ~annoying (you have to update your scala dependencies to be compatible with your scalac version e.g. going from 2.12 to 2.13, 'not a big deal but 'could cause problems in an non homogeneous environment) 'the trade-off for a young / fast evolving language.

I still love scala because it encouraged me to do functional programming

(image from

... and I particularly like scala "rich" pattern matching (with variable binding, pattern guards), tuples, optional types, default parameter values, traits, collections api with higher order methods (collection processing methods, e.g. fold, collect, map, etc...), parallel collections, lazy evaluation, chaining or cloning instead of modifying, persistent data structures.
All this explicit and readable (if you add explicit types). I do not care for implicit conversions/variables/types, meta-programming etc...
I like running scala on the jvm (default option) and being able to also use java libraries.

case class AndExp( left : Expression, right : Expression ) extends Expression {

    def eval( con : Context ) : Option[ Match ] = {
        ( left.eval( con ), right.eval( con ) ) match {
            case ( Some( lm : Match ), Some( rm : Match ) ) => Some( new Match( ( lm.motifs ++ rm.motifs ).sortBy { m : Motif => ( m.pos, !m.is_start ) } ) )
            case _                                          => None


(real code random example) pattern matching over tuple of optional types, list concatenation, higher order sort by.

Modest scala: yes, scala is powerful and flexible, so it could be easily "abused", but nothing prevent you of writing explicit, easy to follow, "sane" code.

Although all the stuff I like starts now to be more or less (syntactically agreeably) available in java >=15, I'm still resisting raw java, and still enthusiast about scala ecosystem. Once you have the functional mindset, you could apply/use this in java and even javascript, but to me scala remains more pleasant.

Created 2019-Feb-15.

Neural networks trained for object recognition are biased towards texture

Artificial stupidity: According to a new research neural networks trained for object recognition tend to identify stuff based on their texture rather than shape!

from R. Geirhos et al. publication (from

Neural networks are lazy learners. It appears humans can recognize objects by their overall shape, while machines consider smaller details, particularly textures.
current state-of-the-art CNNs are very susceptible to random noise such as rain or snow in the real world, [which is] a problem for autonomous driving [;-)]
When asked to identify objects with an incorrect texture, such as the cat-with-elephant-skin example, the 97 human participants were accurate 95.9 per cent of the time on average, but the neural networks only scored between 17.2 per cent to 42.9 per cent. On a very fundamental level, our work highlights how far current CNNs are from learning the "true" structure of the world
For humans, it is hard to imagine recognizing a car by detecting a specific tire pattern that only images from the 'car' category have, but for CNNs this might just be the easiest solution since the shape of an object is much bigger, and changes a lot depending on viewpoint, etc. Ultimately, we may need better datasets that don't allow for this kind of "cheating"
We then demonstrate that the same standard architecture (ResNet-50) that learns a texture-based representation on ImageNet is able to learn a shape-based representation instead when trained on 'Stylized-ImageNet', a stylized version of ImageNet.

the register article: ... How neural nets are really just looking at textures

ImageNet-trained CNNs are biased towards texture; increasing shape bias improves accuracy and robustness article

Created 2018-Sep-21.

Machine Learning brittleness

Interesting read seen on Quanta Magazine : Machine Learning Confronts the Elephant in the Room reporting about a new study in : The Elephant in the Room showcasing failures of object detectors and challenges to have (more) human like object recognition.

Banksy Elephant on

artificial intelligence systems fail a vision test a child could accomplish with ease. ... The new work accentuates the sophistication of human vision, and the challenge of building systems that mimic it
the researchers presented a computer vision system with a living room scene. The system processed it well. ... Then the researchers introduced an anomalous object into the scene - an image of an elephant. The elephant’s mere presence caused the system to forget itself: Suddenly it started calling a chair a couch and the elephant a chair, while turning completely blind to other objects it had previously seen. ... "There are all sorts of weird things happening that show how brittle current object detection systems are"
In recent years there have been a slew of attempts, known as Adversarial Attacks, in which researchers contrive scenes to make neural networks fail. In one experiment, computer scientists tricked a neural network into mistaking a turtle for a rifle. ... This new study has the same spirit.
A computer can’t drive a car if it might go blind to a pedestrian just because a second earlier it passed a turkey on the side of the road.
Today’s best neural networks for object detection work in a feed forward manner. ... errant observations early in the process end up contaminating the end of the process, when the neural network pools together everything it thinks it knows in order to make a guess about what it’s looking at. ... The human way is better. ... "The human visual system says, 'I don't have right answer yet, so I have to go backwards to see where I might have made an error,'" explained Tsotsos, who has been developing a theory called selective tuning ... neural networks will need a new theoretical framework before they can do the same.
Created 2018-Jun-25.

Functional programming - An Introduction to Functions for kids

'stumble upon cool post Conversations with a six-year-old on functional programming (Brent Yorgey blog)

A function is like a machine where you put something in one end and something comes out the other end. For example, maybe you put a number in, and the number that is one bigger comes out. So if you put in three, four comes out, or if you put in six, seven comes out.
"The type of a function machine tells you what kinds of things you put in and what kinds of things come out. So maybe you put a number in and get a number out. Or maybe you put in a list of numbers and get a number out." He interrupted excitedly: "Or maybe you could put words in??" "Yes, exactly!
Or maybe there is a function machine where you put other function machines in and get function machines out!" He gasped in astonishment at the idea of putting function machines into function machines.
"Hey, I have a good idea for a game," I said. "It’s called the function machine game. I will think of a function machine. You tell me things to put into the function machine, and I will tell you what comes out. Then you have to guess what the function machine does." He immediately liked this game and it has been a huge hit.
After a few rounds of guessing my functions, he wanted to come up with his own functions for me to guess (as I knew he would). Sometimes his functions are great and sometimes they don’t make sense (usually because his idea of what the function does changes over time, which of course he, in all sincerity, denies), but it’s fun either way.

Great idea! I'll try that on my 7year old daughter (a change from animal or character guessing games! ;-)

p.s. ... web search ... in the same vein + with more ideas: Fun with Functions (

Created 2018-Apr-26. Updated 2018-Apr-30.

The urge to start over

Seen via Reddit post There’s a reason that programmers always want to throw away old code and start over... about an old post from Joel Spolsky: Things You Should Never Do, Part I

It’s important to remember that when you start from scratch there is absolutely no reason to believe that you are going to do a better job than you did the first time. First of all, you probably don’t even have the same programming team that worked on version one, so you don’t actually have "more experience". You’re just going to make most of the old mistakes again, and introduce some new problems that weren’t in the original version.


I think sometimes starting from scratch can be the right decision (when refactoring to cleanup the code is not enough). For example to "port" an old application to your currently used platform / ecosystem (but never ever just to follow the latest framework trend!) e.g. going from imperative with interpreted language (Perl + Ruby & rails) to functional under JVM (scala & java) = more present and future "available" developers at hand, more "integration" possible, more explicit code, faster. This is a good excuse to start over and experience the joy of (re)building / learning new stuff ;-) ...

see also You-Should-Almost-Never-Rewrite-Your-Software

Created 2015-Nov-09. Updated 2018-Mar-05.

Google Open Sourced TensorFlow Artificial Intelligence Engine

TensorFlow is a way of building and running neural networks?both at the training stage and the execution stage. It's a set of software libraries that you can slip into any application so that it too can learn tasks like image recognition, speech recognition, and language translation.
Google built the underlying TensorFlow software with the C++ programming language. But in developing applications for this AI engine, coders can use either C++ or Python, the most popular language among deep learning researchers. The hope, however, is that outsiders will expand the tool to other languages, including Google Go, Java, and perhaps even Javascript, so that coders have more ways of building apps.

from wired article


TensorFlow is an open source software library for numerical computation using data flow graphs. Nodes in the graph represent mathematical operations, while the graph edges represent the multidimensional data arrays (tensors) communicated between them.
The rub is that Google is not yet open sourcing a version of TensorFlow that lets you train models across a vast array of machines. The initial open source version only runs on a single computer. This computer can include many GPUs, but it's a single computer nonetheless.


Seen via:

google research announce

see also Finally, Neural Networks That Actually Work

Created 2014-Jul-07. Updated 2021-May-17.

Apple new Swift programming language

Swift is a multi-paradigm, compiled programming language developed by Apple for iOS and OS X development.

At last something exciting to replace Objective-C (that I've never resolved to learn because it was not different enough from C to feel new and exciting, yet different enough to be difficult to master).


Like Scala, it has tuples, optional types, pattern matching, immutables, closures / lambdas / first class functions (obligatory for functional programming), Static typing with type inference, etc...
(Seems to "miss" implicits, futures/promises, Async support)

High level programming and performance (compiled) + interoperability with legacy Objective-C (like scala is interoperable with java): nice!

s. native compilation and lack of full garbage collection - just using automatic reference counting (ARC) - make it ~a systems language, but a modern one!


Created 2012-Jun-02. Updated 2018-Apr-06.

Google Blocky a new visual programming language

Blockly is a web-based, graphical programming language. Users can drag blocks together to build an application. No typing required.

Google blocky

... my generic maze solution

Their maze demo is really cool, it's a "training"; you have to resolve it by building the code...
(it took my slow brain few minutes to understand the system and "resolve" the puzzle in a generic way)

Not for core programming, but could be a nice tool to allow users to define "behaviors" / "rules" ... Could also be a nice way to introduce programming to kids?

The system (javascript) is open source. Hosted on google code

Created 2011-Aug-15. Updated 2018-Mar-05.

Google language benchmark

Loop Recognition in C++/Java/Go/Scala

Google implemented and benchmarked a well specified, compact benchmark in four languages: C++, Java, Scala and (its own programming language) Go and evaluated the results along several dimensions.
(They used the languages’ idiomatic container classes, looping constructs, and memory/object allocation schemes).


We find that in regards to performance, C++ wins out by
a large margin. However, it also required the most extensive
tuning efforts, many of which were done at a level of sophisti-
cation that would not be available to the average programmer.
*Scala concise notation and powerful language features al-
lowed for the best optimization of code complexity.*
The Java version was probably the simplest to implement,
but the hardest to analyze for performance. Specifically the
effects around garbage collection were complicated and very
hard to tune. Since Scala runs on the JVM, it has the same
Go offers interesting language features, which also allow
for a concise and standardized notation. The compilers for this
language are still immature, which reflects in both performance
and binary sizes.
language   time factor   memory footprint factor   

C++ Opt | 1.0x | 1.0 |
C++ debug | 8.6x | 2.8 |
Java 64-bit | 5.8x | 3.7 |
Java 32-bit | 12.6x | 3.7 |
Scala |3.6x | 1.8 |
Scala opt | 2.9x | 1.8 |
Go 6g | 7.0x | 3.1 |

(scala opt: for comprehension replaced with a simple foreach )

A significant part of the original program is the specification
of a complex test graph, which is written in a procedural style.
Because of this style, the structure of the test graph is not
immediately evident. *Scala made it possible to introduce a
declarative DSL which is more concise and additionally makes
the structure of the graph visible syntactically*. It should be
noted that similar changes could have been made in other
languages, e.g., in C++ via nested constructor calls, but *Scala’s
support for functional programming seemed to make this really
easy and required little additional supporting code*.

google research article

Created 2011-Mar-16. Updated 2018-Mar-17.

What I like about Scala

or How I Learned to Stop Worrying and Love the JVM environment

(google doc version - with colors in code examples)

A non boring-Java (and more):

At work I'm using Scala for all my new developments. It's a joy to use! A fast, concise and elegant general-purpose multi-paradigm programming language (object oriented, function oriented) providing seamless integration with Java, designed to scale from scripts to large complex applications.


  • Seamless integration with Java = low-risk adoption
  • multi-paradigm: object oriented and functional = expressive
  • less code = more readable = more productive
  • Multicore friendly = future proof

Used by LinkedIn, Twitter, Foursquare, UBS, EDF etc...

The scala language was created by Martin Odersky who also wrote the Java reference compiler and co-authored the Java generics. His implementation of the Scala compiler produces java bytecode that performs as good as comparable Java code.

As high level and concise as Ruby or Groovy but way faster and IDE friendly.

Trying to merge "the best" of object-oriented and functional languages; "the best" of agile (dynamic typing + lightweight syntax) and safe (static typing) / performant languages.

What I like in Scala - Highlights

Type inference

Scala has a non-annoying, non-verbose advanced static type system with type inference. Static enough to help safe refactoring and self documentation but without cluthering your code:

val txt = "bla" // "bla" is a String literal: so txt is a String...
val r   = new txt )

// obviously in method definition, types should be declared:
def bar( msg:String ) = println( msg )
def foo( a:Int, b:Int ):Int = a + 4 * b
    // n.b. if the return type could be inferred from the last evaluated
    // expr. it can be omitted: def foo( a:Int, b:Int ) = a + 4 * b // ok
def filterEntry( f: Entry => Boolean ):List[ Entry ] = { ...
    // filterEntry takes function f - that should receive an Entry and
    // returns a Boolean - as an input param and returns a list of Entry

/* for parameters in passed function, type is also generally inferred
   ("target typing"): 4, 5, 6 are integer literals, so List( 4, 5, 6 ) is
   a factory generating an integer list, so reduceLeft ("accumulator"
   method) takes a function that will receive integers: x and tot can
   only be integer: no need to specify their type: */
List( 4, 5, 6 ).reduceLeft( ( tot, x ) => tot + x ) // = 15

Implicit type conversions

To extend libraries retroactively, without actually changing them (safer/cleaner than Ruby open classes). You define a new class which contains the desired method and define an implicit conversion from the target class to your new class:

// "adding" a =~ regexp match method to String:
// (java String#matches method works only on the whole string!
// and java String#contains doesn't use regexp)

class MyStr( str: String ) {
    def =~( re: String ): Boolean = {
         if ( re.r.findFirstMatchIn( str ) != None ) true else false
implicit def String2MyStr( str: String ): MyStr = new MyStr( str )

/* every time the compiler found a String with an undefined method,
e.g. here =~ : it will look for the implicit method in the current scope that
has matching in/out types = takes a String and returns an object implementing
=~(). It will then ~inline the conversion method... */

"ABC66DE" =~ "\\\\d+" // will return true
// p.s. dots and parenthesis can be omitted (in some situations):
// is shorter than "ABC66DE".=~( "\\\\d+" ) and than
// new MyStr( "ABC66DE" ).=~( "\\\\d+" )


In addition to being object oriented, Scala is function oriented: Functions can be passed as parameters to other functions/methods; functions/methods can return functions (n.b. cleaner than ruby where regular code blocks are not real objects / "values" = not real first-class citizens).

Higher-order function, Closures, Currying etc...

// Even simple collection processing functional methods can come in handy!

// Cleaning a string:
"ONCE 235354 upon A time".
    split( "\\\\s+" ).
    filterNot( _.matches( "\\\\d+" ) ).
    map( w => w( 0 ).toUpper + w.substring( 1 ).toLowerCase ).
    mkString( " " )
// will give "Once Upon A Time"

// partitioning:
val ages = List( 34, 56, 12, 44, 6, 65 )
val ( youngs, olds ) = ages partition ( _ < 26 )
// youngs: List[Int] = List(12, 6)
// olds: List[Int] = List(34, 56, 44, 65).
// closure, currying, partially applied function ...

import scala.util.matching._

class RegStr( str: String = "" ) {
    def xall( re: String )( f: List[String] => String ) = {
        // regex#replaceAllIn method wants a matcher function eating
        // Match objects: Embed passed f fonction eating
        // List( matched, subgroups* ) inside function of Match matcher_f,
        // that will be a proxy to use f with replaceAllIn
        val matcher_f = ( m: Regex.Match ) => f( m.matched :: m.subgroups )
        re.r.replaceAllIn( str, matcher_f )
    } // xall: a functional String replaceAll
implicit def string2Regstr( str: String ): RegStr = new RegStr( str )

"the quick brown fox".xall( """\\b(\\w)(\\w+)\\s*""" ) {
    hit => hit(1).toUpperCase + "."
} // gives: "T.Q.B.F."   // looks like language ctrl structure (... DSL)

// assigns a partially applied function (also a closure) to a value:
val tqbf = "the quick brown fox".xall( """\\b(\\w)(\\w+)\\s*""" )_

tqbf { ms => ms(1).toUpperCase + ms(2) } // "TheQuickBrownFox"
tqbf { ms => ms(1) + ms(2).toUpperCase } // "tHEqUICKbROWNfOX"
tqbf( _(1) ) // "tqbf"

Refinement types / Structural typing

In addition to the "classical" (class/trait) typing, you can "emulate" duck typing with Scala safer, more explicit structural typing feature:

// If it walks like a duck and quacks like a duck, we could call it a duck.
class Duck {
    def walk  = println( "flip flop" )
    def quack = println( "Quaaack!" )
class Person {
    def walk  = println( "Klop klop" )
    def quack = println( "imitating Quaaack!" )
// Handy to glue unrelated "external" classes by their abilities
def doTheDuck( duck: AnyRef{ def walk; def quack } ) = {
    // usually a param type is a Class/Interface, but could be method(s)
    // ("abilities"); here the type is AnyRef implementing walk and quack!
// def walkLikeDuck[ T <: AnyRef{ def walk; def quack } ]( duck: T ) = { ...

doTheDuck( new Duck ) // flip flop, Quaaack!
doTheDuck( new Person ) // Klop klop, imitating Quaaack!

Advanced pattern matching

Case classes - Allows to match (with "deep match" support and variable binding) on any sort of data, not only against integer types and enums like in Java switch/case-s - and Extractors:

// case classes:
case class B( a:String, b:String ) // just add a case modifier to the normal class definition
case class A( x:String, z:B )
val a = new A( "foo", new B( "*", "*" ) )

val ok = a match {
    case A( "foo", B( e, "+" ) )           => { println( e ); 1 }
    case A( "foo", b @ B( x, y ) ) if x==y => { println( b.toString ); 2 }
    case _ => 0
} // 2
    // tests if a is an A object constructed with "foo" and an object B
    // itself built with any value (put in variable e) and "+" or 2
    // identical values (2nd case)... Works via extractors (see below)
    // n.b. match/case-s return a value!

// pattern matching with extractors:
// n.b. like an object deconstructor / data extractor:

val A( str, b ) = a // equivalent to val( str, b) = A.unapply( a ).get
    // extracts data from a into str and b:
    // str = "foo" // extracts 1st field (x) of a:A object into str:String val
    //             // = instantiate and initialize str:String val to "foo"
    // b   = B( "*", "*" ) // extracts 2nd field (z) of a:A object into b:B val
    //                     // = instantiate and initialize b:B val to "foo"
val A( "foo", b ) = a
    // extracts 2nd field (z) of a:A object into b:B val, but only if 1st field
    // (x) of a:A object equals "foo" (if it doesn't match: will raise
    // scala.MatchError)
// n.b. this extractor works via the unapply method on the class A companion
//      object A (= like a static method). For "case" classes this method
//      (and companion) is ~auto generated, but extractors can be customized
//      (by defining unapply, unapplySeq static or/and instance! methods)
//      to do something different than just extracting object parameters,
//      see below regexp
// n.b. extractors can be used outside case classes (and be polymorphic)...

// with regexps: (sub groups extraction!)
val email_re = """^([\\w\\d\\-\\_\\.]+)(\\+\\d+)?@([\\w\\d\\-\\.]+)$""".r

val email_re( name, _, domain ) = ""
    // Regex extractor extracts matched groups into strings that can be
    // assigned together: define and initialize val name:String to
    // edouard.decastro and domain:String to

// a custom extractor:
// extracting multiple matches (full match and captured groups in a list of Strings)
// from a regex on a String :
// (instead of just captured groups on a String full match (default Regex extractor))
import scala.util.matching._
class RegMore( re:String ) {
    def unapplySeq( str:String ):Option[ List[ List[String] ] ]  = {
        Some( re.r.findAllIn( str ).matchData.toList
                      .map { m => m.matched :: m.subgroups } )

val rem = new RegMore( """\\w(\\d+)""" )

val rem( a, b, _* ) = "foo54, bar18, baz, qux0"
// a: List[String] = List( "o54", "54")
// b: List[String] = List( "r18", "18")

// n.b. couldn't use implicit conversion (to "extend" Regex into RegMore) here...


Interactive console
Tuples (mixed type "collections" ... handy to return multiple values)
Default & named arguments
Traits ((partially) implemented interfaces)
Collections (rich, mutable + immutable versions)
Parser Combinators (built in domain specific "language" for executable grammars)
Abstract fields, and types
Option type
XML literals

Has a great web framework: Lift

Created 2010-Jul-29. Updated 2018-Mar-05.

The Mirah Programming Language

From the O'reilley OSCON 2010 Emerging Languages Camp (seen via an infoQ interview of Charles Nutter - mister JRuby - by Werner Schuster)

A Blend of Java and Ruby

(haven't tried it yet... anyway is not mature and looks no better than scala except that is doesn't require any non Java core lib)

In general, Mirah could be seen as a "Ruby with static types", though Mirah is not Ruby. It does not share Ruby’s type system, core classes, standard library, or even execution model, since none of these things are imposed upon Mirah programs by the Mirah language.
Mirah is more a repurposing of Ruby’s syntax to a flexible toolchain suitable for compiling to any number of type systems and runtimes with maximum performance."


At present, it seems the best way to describe Mirah is as "a nicer way to write Java." So I'd say the primary target right now is Java developers that want a replacement for javac with a nicer syntax and a few additional features.
It turns out that the Java libraries and most of the Java type system aren't really that cumbersome if you put a little sugar around them. For me, the best sugar available comes from Ruby syntax and some of Ruby's "apparent" language features.
Mirah is a statically-typed, compiled language, but it runs well as a script too. You write what mostly looks like "Ruby with a few type annotations", and then either use the "mirah" command to run it as a script or the "mirahc" command to compile it to JVM bytecode or Java source.

How will it stand against jRuby performance and productivity wise ? Will it be soon really usable? How fast is it? ... How could it stand against Scala?

# dynamic.mirah:

def foo( a:dynamic )              # dynamic typing
  puts "I got a #{ a.getClass.getName } of size #{ a.size }"

class SizeThing

    def initialize( size:int )    # static typing
        @size = size

    def size


#foo( [ 1, 2, 3 ] )
#foo( 12 ) )

You can use both static and dynamic types: nice!

# sort_closure.mirah :

import java.util.Collections
import java.util.ArrayList

list = [ 9, 5, 2, 6, 8, 1 ]
puts "unsorted: #{ list }"

Collections.sort( list ) { | a, b | Integer( a ).compareTo( b ) }

puts "sorted: #{ list }"

You can use code blocks that made ruby so (functional) and "beautiful"

Btw, I don't understand why people are so attached to ';' and tons of parenthesis and curly brackets (even ':=') ? Many new languages keep those, maybe to avoid scaring old programmers? (e.g. AmbientTalk - a distibuted event-driven language - looks great if it was not for its syntax). With Mirah, striping an old language of it's ugly and heavy -ness is refreshing! (but Scala already did the same)

Created 2010-Mar-11. Updated 2018-Mar-05.

A richer web with HTML5 Web Sockets?

HTML5 Web Sockets represent the next evolution of web communications: a full-duplex, bidirectional communications channel that operates through a single connection (TCP socket) over the Web; meaning reduction in unnecessary network traffic and latency, cleaner network code, more interactive and responsive web applications. It is not just an incremental enhancement to conventional asynchronous HTTP communications (e.g. AJAX and Comet ); it represents an enormous advance for interactive and real-time (event-driven) web applications.


WebSockets enables establishing a bidirectional communication channel. The WebSocket protocol is not build on top of HTTP, it defines the HTTP handshake behaviour to switch an existing HTTP connection to a lower level WebSocket connection. WebSockets does not try to emulate a server push channel over HTTP. It's a ~ low level framing protocol on top of TCP.

Example (javascript, server side):
n.b. the WebSocket protocol supports a diverse set of clients (e.g. JavaScript, Adobe Flex, JavaFX, Microsoft Silverlight, etc...)

Establishing a connection:

var myWebSocket = new WebSocket("ws://");
n.b. to establish a WebSocket connection, the client and server upgrade from the HTTP protocol to the WebSocket protocol during their initial (HTTP) handshake.
n.b. the connection itself is exposed via the onmessage and postMessage methods defined by the Web Socket interface.
Then associate a series of event listeners to handle each phase of the connection life cycle:
myWebSocket.onopen = function(evt) { alert("Connection open ..."); };
myWebSocket.onmessage = function(evt) { alert( "Received Message:  "  +; };
myWebSocket.onclose = function(evt) { alert("Connection closed."); };
To send a message to the server, call postMessage (with the content you wish to deliver). Call disconnect to terminate the connection...
myWebSocket.postMessage("Hello Web Socket! Goodbye Ajax and Comet!");

Both text and binary WebSocket data frames can be sent full-duplex, in either direction at the same time!

The Web Sockets API is being standardized by the W3C and the Web Socket protocol is being standardized by the IETF.

HTML5 Web Sockets can provide a 500:1 or - depending on the size of the HTTP headers - even a 1000:1 reduction in unnecessary HTTP header traffic and 3:1 reduction in latency. That is not just an incremental improvement; that is a revolutionary jump - a quantum leap.

Web Sockets browser / server support:
soon in Firefox (available in the trunk of the Firefox code base)
node.js a server side JavaScript implementation!
web-socket-ruby server/client implementation in Ruby

The Future of the Web: HTML5 Web Sockets
HTML5 Web Sockets: A Quantum Leap in Scalability for the Web
What is an HTML 5 WebSocket [] (Kaazing Gateway provides an emulation layer for browsers as far back as IE 5.5)

HTML5 Server-Push Technologies, Part 2

Getting started with HTML5's Web Sockets

Created 2009-May-15. Updated 2018-Mar-05.

Cool database technology: CouchDB

(Apache) CouchDB is a peer based DISTRIBUTED database system.

Instead of storing data in rows and columns, the database manages a collection of (JSON) documents.

Apache CouchDB is a distributed, fault-tolerant and schema-free document-oriented database accessible via a RESTful HTTP/JSON API. Among other features, it provides robust, incremental replication with bi-directional conflict detection and resolution, and is queryable and indexable using a table-oriented view engine with JavaScript acting as the default view definition language.


Unlike SQL databases which are designed to store and report on highly structured, interrelated data, CouchDB is designed to store and report on large amounts of semi-structured, document oriented data. CouchDB greatly simplifies the development of document oriented applications, which make up the bulk of collaborative web applications.

It is designed for extreme scalability and is easily deployed to multi-core or multi-server clusters.


on wikipedia

"Front-ends / APIs":

CouchRest (ruby) _

July 2010: CouchDB 1.0 released

Created 2009-Apr-09. Updated 2018-Mar-05.

JRuby and Rails on Google App Engine

imageimageGoogle has released App Engine support for Java ... Great: JRuby + Rails can be used on the infrastructure!

JRuby on Google AppEngine: First Impressions [Article by Nick Sieger]

In the end, I’m still extremely excited about the prospect of using JRuby and Rails on AppEngine, and can’t wait to see what people build with these tools. If you want a little head start, you can check out the first Rails application I deployed,

JRuby on Rails on Google App Engine [Article by Ola Bini]

In this post I thought I’d go through the steps you need to take to get a JRuby on Rails application working on GAE/J, and also what kind of characteristics you should expect from your application.

trade-offs and constraints:

  • No regular net/http, restclient, ActiveResource usage.
  • No ActiveRecord! (use Bumble !?)
  • 1000-files limit per application! (freeze hyphen gems remove unused stuff!)
  • Startup/first request processing is slow.
Created 2008-Sep-08. Updated 2018-Mar-05.

V8 VM: a new era for rich internet applications?

imageV8 is the high-performance JavaScript Virtual Machine that is part of new Google's Chrome web browser.

A high-performance Javascript could be critical for "pure-dHTML rich internet applications" when combined to other developments, like Canvas and SVG support! Then bye bye flash-flex/java applets/silverlight etc...!

V8 JavaScript engine [wikipedia]

Stricking features:

  • Dynamic Just<strong>In<strong>Time compilation to native code!
  • Multi-threaded from the ground up.
  • Efficiant non-conservative garbage collector.
  • Independent from the browser; can be used in other projects.

Nice article by Zviki Cohen: Google Chrome: 'JavaScript Forever!'

Google wants your JavaScript web applications to run fast, stable and secure and to feel much like desktop applications. You achieve that by downloading a different runtime engine (you can call it browser, but that name is totally obsolete). That sounds like the next generation RIA [Rich Internet application] technologies: Microsoft Silverlight, Adobe Flash/Air and Sun's JavaFX. Google are sending a clear message: "we have a lot riding on JavaScript and we're not looking for a replacement anytime soon".

Note: Mozilla's next-generation JavaScript engine TraceMonkey (for firefox 3.1) will outperforms (actual implementation of) V8.

Some people are even starting to think about using V8 as a VM for other (dynamic) languages :

Dave Griswold has made interesting posts on Strongtalk-general google group:
Using V8 for other languages
Chrome and V8

We'll have to see what the details are when the code comes out, but the release of the V8 VM is the beginning of a whole new era for dynamic languages (Smalltalk, Ruby, Python, etc).
Let the flood of fast new dynamic language implementations begin!

Could JavaScript Power A Significant Future Ruby Implementation or VM?

Side note: A nice new book about JavaScript:
JavaScript: The Good Parts

Created 2008-Apr-16. Updated 2018-Mar-05.

Google Apps Engine application cloud service

Run your web applications on Google's infrastructure!

imageOn April 8 Google launched Google App Engine, a hosted dynamic runtime environment for (now Python) web applications inside Google's geo-distributed architecture. The Google App Engine is designed to completely house your service, and to integrate easily with Google services.
Revolution in web application hosting / deployment!?


  • Provides dynamic web serving and persistent storage (BigTable datastore, GoogleFileSystem) with queries, sorting and transactions; automatic scaling and load balancing!
  • A free account can use up to 500MB of persistent storage and enough CPU and bandwidth for about 5 million page views a month (they plan to introduce pricing and service level agreements for additional resources, priced in a pay-as-you-go marginal resource structure, once the product leaves its limited 10,000-person)
  • Google App Engine applications are implemented using the Python programming language (other languages are to come [please!: ruby, groovy]).

(Actual) Feature limitations:

  • Python is now the only supported language (they already have many requests for Ruby, Java, Perl, PHP, and Fortran)
  • users have to have a google account ? (comment by Gábor Farkas "as far as i understand, you do not have to use google-accounts for user management. you can implement your own user/session management if you want to.")
  • No offline processing (no cron jobs and other long-life processes)
  • Served static files limited to 1 MB

but ~all this will be addressed (already in their pipeline, see GoogleAppEngine blog post ); App Engine is going to evolve fast.

Interesting reads:
Google App Engine for developers by Niall Kennedy.
Google App Engine: History's Next Step or Monopolistic Boondoggle? by Marshall Kirkpatrick.

Example (featured project):

Created 2007-Dec-05. Updated 2018-Mar-05.

Tips for software startups (and others?)

Great article by Alex on
Software Engineering Tips for Startups



  • Have working code: the working code is the core and the launchpad for the business (Obviously having the right business model, revenue stream and appropriate funding - or the really cool idea - won't hurt either).
  • Have a technical (co-)founder: always have a strong technical co-founder. Someone who shares or invents the business, but also has the technical feet on the ground! Technology is what makes the business possible to begin with.
  • Hire A+ engineers who love coding: startups can not afford to have developpers who are not that good or not that passionate.
  • Keep the engineering team small and do not outsource. See The Mythical Man-Month : you can get a baby from a women in 9 month, you can’t get a baby in one month from 9 women. Hire a few of the best guns you can find, pay them well, give them stock options, make them happy.
  • Don't bring the wrong person into the company (Ask tough questions during the interview).
  • Avoid hiring (non-technical) managers: if everyone is sharp, knows what they are doing and executes on a task, why do you need a manager?
  • Instill an agile culture: there is no room to plan for 6 months and then execute (because someone else will get there first!). The new approach is to evolve the system. See below agile note.
  • Do not re-invent the wheel: there are so many fantastic open source libraries out there that re-writing existing libraries is a waste of time (and you are not likely to do it better).

I think most of this also applies to any software development team!

Created 2007-Jun-21. Updated 2018-Mar-05.

RESTful Web Services book

Just got this must-have book about the REST 'philosophy':

RESTful Web Services
by Leonard Richardson & Sam Ruby

Putting the "Web" Back Into Web Services.

The first book that sets down best practices for "RESTful" web services.
Introduces the Resource-Oriented Architecture (ROA), a commonsense set of rules for designing RESTful web services.


The world of web services has been on a fast track to supernova ever since the architect astronauts spotted another meme to rocket out of pragmatism and into the universe of enterprises. But, thankfully, all is not lost. A renaissance of HTTP appreciation is building and, under the banner of REST, shows a credible alternative to what the merchants of complexity are trying to ram down everyone's throats; a simple set of principles that every day developers can use to connect applications in a style native to the Web.
RESTful Web Services shows you how to use those principles without the drama, the big words, and the miles of indirection that have scared a generation of web developers into thinking that web services are so hard that you have to rely on BigCo implementations to get anything done. Every developer working with the Web needs to read this book.

David Heinemeier Hansson foreword

see also my Giving SOAP a REST post

Created 2007-Apr-27. Updated 2018-Mar-05.

Adobe open-sources Flex

Adobe Flex, the cross-platform rich web application environment based on Flash, is set to go open-source (part of). No more worries about being locked into a proprietary system?

Adobe announce
So maybe flex/apollo isn't that un-interesting after all!

Schiphol Amsterdam Airport monitoring system built with Adobe Flex

I still haven't fully grasp how it works: to me it looks Flex is a XUL like flash-based system where a User Interface description (called MXML), which can contain event-driven logic (ActionScript) [like html with javascript] is compiled into a flash 'movie' and served (or can be a standalone client application?).
The flash application (compiled on the fly depending on client input ? or precompiled) can be directly served to (web) clients (for them it's then like interacting with a flash only web site) or you can mix html/flash.

The flash movie can be ~bridged to javascript inside a normal html page, so it's possible to build mixed dHTML / Flex systems.
A flex application, like javascript, can directly access HTTPServices (through HTTP GET and POST requests) (? or indirectly through bridging to javascript ajax)

As almost every browser has flash (unlike XUL that only works with firefox), and if it's now open source it might be quite interesting for building richer web apps!?

I think that a flex application can be compiled and stored on the server (as a standalone flash movie), then a web application server can generate html containing an <embed/object> tag pointing to the flash applet on the server.
The generated page can interact with the applet (running on the client) through javascript (via a simple bridging javascript library) : This is flex the cheap way !? You could also dynamically generate flex applets ... but this is more complex and ~useless if you can mix a static flex core applet with dynamically generated html (as long as the flash applet and javascript can fully interact) !?

techcrunch article

Adobe are opening up part of their ecosystem, which is great, but don’t hold your breath for an open source Flash runtime anytime soon (unlike Java). ... but this announcement will definitely be met with calls of 'not enough’ from the open source community and those waiting for a fully open and cross platform rich application platform from Adobe.

Other Rich Internet Application frameworks:

The Ajax Open Source Declarative Framework - XAP -

An Apache incubation 'project'
Doesn't required non dHTML, proprietary - e.g. flash for flex - runtimes.

  • Declarative rich user interface via XML.
  • Data binding for connecting UI to data.
  • Incremental update of web pages, declaratively and programmatically.


Declarative (XML) UI + JavaScript transparently compiled to Flash or dHMTL only (OpenLaszlo 4)


Created 2007-Apr-09. Updated 2018-Mar-05.

Exploring the ugly duckling of programming languages

Nice article by Bruce Tate
Crossing borders: JavaScript's language features



JavaScript is often ridiculed as the black sheep of programming languages. Nearly every Web developer has cursed JavaScript at one time or another.<br /> But JavaScript is becoming increasingly important, and it remains the most broadly available scripting language for Web development. Some industry leaders are taking a fresh look at JavaScript, driven by the resurgence of its use. Programming techniques like Ajax make Web pages more interactive...

The article illustrates JavaScript features that make it attractive:

Higher-order functions. A high-order function is one that either takes functions as arguments or returns a function. This feature gives JavaScript programmers the ability to deal conceptually with actions, or functions, as easily as they deal with other variable types.

A flexible object model. JavaScript's object model uses a relatively uncommon approach to inheritance - called prototypes. JavaScript represents objects as nested functions! JavaScript bases object construction on a prototype, or an existing instance of an object, rather than a class template!

Dynamic & weak typing: Dangerous? but could allow better productivity and flexibility.

Open objects: One can add "on the fly" new attributes and behaviors (methods) to any existing "object"...

To this list, I would add closures.

In the same vain:
Functional Javascript

(April 23 2008):
Javascript will be the Next Big Language

Created 2007-Apr-09. Updated 2018-Mar-05.

Aspect Oriented Programming (... and Ruby?)

A typical software system comprises several "core" and system-level "cross-cutting" concerns (a particular goal, concept, or area of interest).

If writing an application for handling medical records, the bookkeeping and indexing of such records is a core concern, while logging a history of changes to the record database or user database, or an authentication system, would be cross-cutting concerns
since they touch many parts of the program.

Object Oriented Programming paradigm is good for representing core concerns, but not very adapted for handling cross-cutting concerns. This results in code that is hard to design, understand, evolve and reuse.

Aspect Oriented Programming (AOP) is a paradigm for better concerns separation (than previous methodologies such as simple OO) that provides modularization of crosscutting concerns. It shows great promise for improvements in code maintenance and reusability. AspectJ is the most popular AOP language.


An aspect can alter the behavior of the base code (the non-aspect part of a program) by applying advice (additional behavior) at various join points (points in a program) specified in a quantification or query called a pointcut (that detects whether a given join point matches).

An aspect is a modular unit of crosscutting implementation. It encapsulates behaviors that affect multiple classes into reusable modules. With AOP, core concerns are implemented in an object-oriented way, then crosscutting concerns are implemented separately using aspects.

Ruby's meta-programming facilities are powerful enough to allow for AOP-esque techniques but ruby has no dedicated AOP support: no conventional and thus reusable way of applying Aspect Oriented Programming principles. Transami has made a proposal to add AOP abilities to Ruby (does ruby really needs this !? maybe not but it's interesting)

Note: Unit Testing, also a cross-cutting issue!:<br /> article

Aspect-oriented programming wikipedia article article article

Aquarium a framework that implements Aspect-Oriented Programming (AOP) for Ruby

Created 2007-Apr-09. Updated 2018-Mar-05.

The problem with development methodologies

Nice (and fun) article by 'raganwald':
Wasabi cannot cure rotten fish



No methodology [including agile] can 'fix' projects that are staffed with underperforming people. People are more important than process, period.

This is the underlying issue with the language 'wars' as well. No magical combination of JSON, static typing, design patterns, IDE whizzies, and frameworks will somehow help a million monkeys produce any of Shakespeare's works.

my statement is that you can only judge a methodology on the basis of the results it delivers for a team that has already proven it can ship software. You judge it on the basis of incremental value.

What is it that causes companies to buy silver bullet after silver bullet? Why do companies lurch from consultant to methodology to programming language like infomercial junkies looking for something that will flatten their tummies without sweaty exercise or unpleasant diets? [I would answer: naiveness, greed, cluelessness]

I couldn't agree more: Good tools and methodologies can only help good teams, they won't save "miss-staffed" ones!

Created 2007-Apr-09. Updated 2021-Jan-27.

Agile software development methods

An antidote to bureaucracy.

  • Individuals and interactions over processes and tools.
  • Working software over comprehensive documentation.
  • Customer collaboration over contract negotiation.
  • Responding to change over following a plan.

Quite 'old' + I don't believe in silver bullets but it's nice to see that nowadays sanity and common sense are somehow trendy!...


Nice article by Martin Fowler : article


Separation of Design and Construction?

We should be very wary of the traditional engineering metaphor for building software. Coding should not be viewed as a classic construction activity. Coding is not a low (intellectual) skills construction activity, it is a design activity! Creative processes are not easily planned, and so predictability may well be an impossible target.

The Unpredictability of Requirements!

Requirements are not just changeable, they ought to be changeable. Even if the customers/users can fix their requirements, the business world isn't going to stop for them. And many changes in the business world are completely unpredictable.

Controlling an Unpredictable Process - Iterations

Iterative development (has been around for a while under many names: incremental, evolutionary, staged, spiral...) as a feedback mechanism/reality check: frequently produce working versions of the final system that have a subset of the required features.
This leads to a style of planning where long term plans are very fluid, and the only stable plans are short term plans that are made for a single iteration.

The Adaptive Customer/User

In an adaptive process the customer/user has much finer-grained control over the software development process. At every iteration they get both to check progress and to alter the direction of the software development.

No "Plug Compatible" Programming Units!

One of the key features of agile methods is that people involved in software development are not considered replaceable parts/resources (as in traditional methodologies). Alistair Cockburn's studies of software projects have led him to conclude the people are the most important factor in software development.
The notion of people as resources is deeply ingrained in business thinking. But for the highly creative and professional work, this does not hold.

Programmers are Responsible Professionals

Programmers are the best people to decide how to conduct their (technical) work. The Taylorist notion of a separate planning department that decides how to do things only works for uncreative jobs, if the planners understand how to do the job better than those doing it (e.g. sweatshop, army!)...

Managing a People Oriented Process

Developers must be able to make all technical decisions. Such an approach requires a sharing of responsibility where developers and management have an equal place in the leadership of the project.
Ex-developers need to recognize that their technical skills will rapidly disappear and they need to trust and rely on current developers.

Business/Users Leadership

But the technical people cannot do the whole process themselves. They need guidance on the business/users needs.
Agile teams need continuous access to business/users expertise. Furthermore this access is not something that is handled at a management level, it is something that is present for every developer.

Agile methods

Extreme Programming

Where traditional organizations call for the definition of static roles, Scrum developers can change hats dynamically, often passing as analysts, testers, coders, designers, architects and integrators in a single day...

Context Driven Testing
Lean Development
(Rational) Unified Process

Note: By extension, all this probably also make sense for any creative activity!? It's nice to see that people realize that bureaucracy does not represent a surrogate for talent and creativity, but instead is more like an old-fashioned burden.

Agile, lightweight, adaptive/fluid processes are the present trends in development methodologies, and this is not a bad thing! Nevertheless they too are not a surrogate for competence!

Created 2007-Apr-09. Updated 2018-Mar-05.

Functional Programming For The Rest of Us

Nice article by 'coffeemug at':
fp ramblings @


Like object oriented programming, functional programming is a set of ideas, not a set of strict guidelines.
A function is a very basic unit in functional programming. Functions are used for almost everything, even the simplest of calculations. Even variables are replaced with functions. In functional programming variables are simply aliases for expressions. They cannot be modified. All variables can only be assigned to once!
By now you are probably wondering how you could possibly write anything reasonably complicated this way. If every symbol is non-mutable we cannot change the state of anything!
It turns out that functional programs can keep state, except they don't use variables to do it. They use functions instead. The state is kept in function parameters, on the stack. If you want to keep state for a while and every now and then modify it, you write a recursive function.
You may be interested why someone would want to program in this manner ?:

Nice for unit testing, debugging, concurrent programming, hot code deployment ...

Functional languages offer a different kind of abstraction tools that make you forget you've ever liked modifying variables. One such tool is capability to work with higher order functions = functions that operate on other functions (accept them as arguments, modify and manufacture other functions). ..."currying":, lazy evaluation (e.g. infinite data structures, monads), continuations, (function) pattern matching, closures (note: you can use those techniques with Perl!

Opinion: Difficult, marginal and academic image (...that's a cool point...), but if the future of computing is indeed massive parallelism; might help a lot!

see also: Functional programming language
The Next Mainstream Programming Languages: A Game Developer's Perspective (Tim Sweeney, Epic Game. Programming requirements of the video game industry with hard number and real code. Startlingly insightful suggestions to address these problems, mostly coming from... Haskell)
Why People Aren't Using Haskell

Created 2007-Apr-09. Updated 2018-Mar-05.

Metamath: Omega numbers

Not directly progamming related, but information theory related.
A Chaitin constant or halting probability is a construction by Gregory Chaitin which describes the probability that a randomly generated program for a given model of computation or programming language will halt. It is usually denoted with Ω.

It is a normal, uncompressible and transcendental number which can be defined but cannot be computed (beyond a certain value N - which is non-computable too! - you cannot compute the value of any bit of Ω). This means one can prove that there is no algorithm which produces the digits of Ω.

MetaMath! The Quest for Omega. Gregory Chaitin book where he shares his profound insights into the inescapable, shocking limitations that infuse mathematics and computation.

'Don't understand a bit but is really poetical, philosophical!
... together with Gödel's incompleteness theorem this implies that there can never be a "theory of everything" for all of mathematics and maybe, by extension that there is a limit to all possible knowledge... The limits of reason!... Chaitin's constant article

Created 2007-Apr-09. Updated 2018-Mar-05.

Giving SOAP a REST

SOAP isn't the only game in town for Web services interfacing (unless being ignorant of what made and continues to make the Web successful), REST offers a perfectly good solution for the majority of implementations, with greater flexibility and lower overhead.

While REST (Representational State Transfer) originally referred to a collection of architectural principles, people now often use the term in a looser sense to describe any simple web-based interface for programmatic access, that uses XML (or YAML, JSON, plain text) over HTTP without the extra abstractions of MEP & Remote Procedure Call based approaches like the web services SOAP protocol.
The 'naked' data, without any envelope is retrieved as the content of an HTTP query response (or in its header). The input data for the operation to be performed is part of the query parameters, and the target URL represents the resource being accessed.
HTTP POST, GET, PUT, DELETE "verbs"/"methods": can be used, respectively to perform: Create, Read, Update, Delete operation on a target resource (url). OPTIONS method might be use for resource description and service discovery, HEAD for resource status monitoring. Alternatively, simple GET/POST operations with additional parameters to mimic other modes might be used ("low" REST, ).
Relying on just few uniform methods to manipulate distinct resources represents an object oriented way of thinking as opposed to the method - procedural - oriented SOAP approches.

image article
REST-Web-Services @ article On-REST rest

Managing our data/resources is complex enough, why add extra useless levels of complexity for the API. "The web is the API!"
Explicit typing and protocol independence are not surrogates for simplicity, elegance and scalability!

Here's the radical idea: no matter what your problem, you can and should think about it as a data object/resource manipulation problem rather than as a method oriented API design problem. Think of your web server as an information repository, like a database on which one can do uniform data manipulation operations. Even web services with complicated work flows can be organized in a URI-centric "object/resource oriented" manner.


Created 2007-Apr-09. Updated 2018-Mar-05.


(JavaScript Object Notation, ~a subset of YAML ) is a lightweight data-interchange format; a serialized representation of data structures.


{"people": [{"name" : "edouard", "id" : 12}, {"name" : "test", "id" : 13}]}

JSON's simplicity has resulted in its widespread use, especially as an alternative to XML for Ajax. It is less verbose and faster to parse (if using eval()) than XML. In JavaScript (and many other dynamic languages) JSON can be parsed trivially using the eval() procedure (caution: security issues!).

Created 2010-Aug-11. Updated 2018-Mar-19.


Douglas Engelbart

Modern computer "father"

Graphical user interface (2-dimensional display editing), mouse, video teleconferencing, groupware, email, hypertext, document version control etc... all in the 60s!!

Engelbart's 1968 demo flyer
Doug Engelbart's mother of all demos video, 1968!

Mother of all demos wikipedia article

The Mouse Turns 40 video

Working Together - Douglas Engelbart & Harvey Lehtman

Engelbart timeline mural

Ted Nelson

The other "father" of the web

American sociologist, philosopher, and pioneer of information technology.

hypertext and hypermedia concept / term creator.


Started project Xanadu ... following Vannevar Bush and its theoretical machine called the memory extender (""Memex":" c.f. Krell computer terminal ;-) footsteps.... inspiring Tim Berners-Lee in creating the web.

Created 2007-Apr-09. Updated 2018-Mar-05.

Stupid links

White & Nerdy [latest Weird Al]
Note: first appearance of an O'Reilly book in a music video!...

Medieval tech support [introducing the book in a scroll world]

Cookie Monster eats computer [1971!]

The programmer Hierearchy

We all know that there is a hierarchy of programmers. Ruby programmers look down on everybody. C programmers look down on most. Right at the very bottom are Java programmers who are looked down on by everybody, but also consider themselves superior to all other, thus making Java Programmers equivalent to the Erotic Furries in the Geek Hierarchy.

The geek hierarchy

Web2.0 bullshit generator
e.g. "tag podcasting weblogs"

Web Economy Bullshit Generator
e.g. "repurpose extensible synergies"

Can you tell a coder from a serial killer?

Geek cartoons/humour