As programmers we rarely have a luxury to write a project from scratch. Usually we have
to retrofit existing projects with all cool things we need. If a new component, or a library
we want to use introduces new concepts that bleed outside its boundary, we have a “culture clash”,
when old code is unaware about new concepts have to work with it anyhow. Sometimes the clash is so bad
that we have to give up on using shiny new things, or have to significantly rework their code,
which requires time and efforts we cannot afford.
Incomplete objects allow us to concentrate on important properties of JavaScript objects
ignoring the rest: we don’t need to specify every single property, and we can deal with
cyclical graphs.
Incomplete arrays is a complimentary feature to inspect only the first few array items.
Both features are very useful for patterns, and heya-unify
provides rich facilities to automate
creating incomplete objects: they can be marked up explicitly on per-instance basis, recursively
with a special utility, and we can specify how to deal with objects by default during unification.
Custom unification in heya-unify
allows us to deal with our specific objects in JavaScript,
create unification helpers, and even custom logical conditions. It is there to bridge unification
with our existing projects.
Looking at the 1st part
and
the 2nd part
of the series is recommended before diving into details.
Custom unification
Unification makes comparing simple objects a cinch no matter how complex they are, and we can easily apply it
to JSON-like trees as is. Additionally heya-unify
“knows” how to unify other common JavaScript objects:
dates, and regular expressions. Yet in Real Life™ we are faced with complications like that:
Unification for JS
introduced heya-unify
—
a practical mini library to leverage unification in JavaScript. This post explains when
it makes sense to use unification, and gives practical examples of how to use it.
When to unify?
Below is my laundry list for unification. As soon as I see a project, which deals with items on
the list, I investigate if it makes sense to use heya-unify
.
Unification is a very interesting programming tool. Originated from logical programming
(its the foundation of Prolog) and used in functional programming (e.g., Haskell) it helps
to compare objects for equality, identify known patterns, and reassemble results differently.
Wikipedia gives a somewhat complex definition
of unification, but many people see it as
an extended equivalence comparison, a pattern matching tool, and some even find parallels with
XPath queries, CSS, and even jQuery, all operating on regular objects. See it for yourself.
ClubAjax
invited me to speak about technologies behind Heya
, specifically about code generative solutions behind heya-pipe
. Pipes are built on a firm foundation of functional programming (FP), and it allows us to use a wide range of technologies to optimize their performance including generating code on the fly (code generation AKA CG).
As soon as we are talking about CG, the first question to ask is: “How to debug such code?”. Heya provides answers for that too. But no spoilers.
I spoke at ClubAjax
about optimization of modern web applications. Usually I speak about theoretical matters, but this time I decided to go practical. This is a huge topic and it was blogged/debated/presented to death, including my Improving performance…
. Yet I decided to add to it after realizing that many things have changed in last years, including how we build web applications. I concentrated on technical aspects completely bypassing all other areas (e.g., a psychological angle).
Once I wrote a blog post On JavaScript, EDP, and 0ms timeouts
, which discussed a "smart" trend to pepper code with timeouts of … 0ms: setTimeout(f, 0). Authors of those "programming pearls" genuinely believed that this code reschedules a function call to the next available time slice after the code that set the timer was executed without introduction of a delay (after all it is 0ms!). In reality a typical delay was 10-20ms. With new generation of browsers it starts with 4ms and jumps to 1000ms for non-current/hidden tabs.
Finally: my open source JavaScript project DCL
is built on ideas described in this article. Available for node.js and modern browsers, it implements OOP with mixins and AOP at "class" and object level. Read documentation and background articles on www.dcljs.org
, clone its code on github.com/uhop/dcl
, and follow @dcl_js
.
Once again I was invited in ClubAjax
to speak about JavaScript. This time I did a presentation based in part on my previous blog post OOP and JS
. Slides and talk revisit OOP, mixins, AOP, chaining, and other related techniques I discussed in my blog. Of course, OOP deficiencies were discussed at length too. I suggest to look at slides and read the blog post - it will give you a better picture.
Finally: my open source JavaScript project DCL
is built on ideas described in this article. Available for node.js and modern browsers, it implements OOP with mixins and AOP at "class" and object level. Read documentation and background articles on www.dcljs.org
, clone its code on github.com/uhop/dcl
, and follow @dcl_js
.
Almost any Java programmer, who starts to study JS groking its OOP facilities and a dynamic nature of JS, thinks that they can be greatly improved and starts its own OOP library/helpers. Majority of them left forgotten when their authors learn more and more details and patterns of JS, yet some grow to fruition and being marketed. This article is dedicated to such people.
Many years ago I decided to replace plain text areas in Django’s Admin with rich text editor, so I can edit HTML on my blog using WYSIWYG. Six (yes, 6) years ago I looked around and selected
TinyMCE
. Over time it turned out that I was forced to upgrade TinyMCE and the link script I had because new browsers continue breaking my rich editor editing. Finally it stopped working again in all modern browsers, and I decided that enough is enough. It is time to replace it. This time I settled on Dojo’s Rich Editor
hosted on Google CDN
— simple, functional, less work to set up.
This month I continued my presentation at ClubAJAX
. Last time
I did a survey of what is available in JavaScript, and concentrated on object-oriented (OOP) and aspect-oriented (AOP) techniques. This time I continued the survey, and talked about functional programming (FP), and domain-specific languages (DSL). And as promised I touched the code generation facilities too.
I suggest to read the first part
before.
Enjoy!
Direct link: Exciting JavaScript - Part II
.
Today at dojo.connect
I did a presentation “RAD CRUD”: rapid development of form-based applications. It continues my other presentation “CRUD with Dojo”
, but it is more in depth, targets Dojo developers, and contains some advanced material.
Direct link: RAD CRUD
.
View more presentations from Eugene Lazutkin
.
I was asked to talk about advanced JavaScript techniques at the last monthly meeting of ClubAJAX
— monthly get-together of Dallas-area JavaScript programmers. Instead I ended up talking about leveraging cool JavaScript features to implement well-known programming techniques and paradigms: OOP
, AOP
, FP
, and so on.
Unfortunately I couldn’t finish in time, so I did a tour of some language features, and talked about OOP and AOP. The rest (I plan to do FP, code generation, and DSL
) will be covered later.
My presentation at ClubAJAX
got off to a rocky start: I was let in the
building 40 minutes after I was supposed to start the presentation.
Everybody waited patiently. Thank you guys! As promised I publish slides along with relevant links (I had to skip most
of planned demos).
Here is my presentation on SlideShare
: CRUD with Dojo
. The original presentation can be seen on Google Docs: CRUD with Dojo
.
Explaining some dark corners of JavaScript, browsers, or Dojo for the 100th time I realized that I already did it on numerous occasions, and some of my answers are published on public web sites. So I decided to round up the most general ones I posted on StackOverflow
and publish links to them here for a future reference.
JavaScript
This section is for language-specific topics. They can be equally applied in any environment.
In the previous post
we explored “array extras” and how they can help us to write concise yet performant and clean code. In this post we take a look at generalizing recursive algorithms with recursion combinators — high-level functions that encapsulate all boilerplate code needed to set up the recursion. These functions were added to dojox.lang.functional and will be officially released with Dojo 1.2.
In general the recursion is a form of iterative problem solving in the same category as loops. There are two major natural sources of recursive algorithms: recursive data
structures (lists, trees, and so on), and recursive definitions
(factorial, Fibonacci numbers, the GCD algorithm, etc.). The
recursion plays a prominent role in the functional programming (FP),
and one of the best articles on this topic is “Recursion Theory and Joy”
by Manfred von Thun
, the creator of Joy
(a purely functional
programming language with Forth-like syntax). Manfred’s article
explains intricacies of recursion including the venerable Y
combinator
, recursion combinators in general, and introduces a practical set of recursion combinators, which will guide us in this post.
Finally: my open source JavaScript project DCL
is built on ideas described in this article. Available for node.js and modern browsers, it implements OOP with mixins and AOP at "class" and object level. Read documentation and background articles on www.dcljs.org
, clone its code on github.com/uhop/dcl
, and follow @dcl_js
.
If we look at the history of computer programming languages, we can see that practically all new programming methodologies were about one thing: taming complexity. The anarchy of earlier days of procedural programming
(example: Fortran) gave way to structured programming
(Pascal), which was refined with modular programming
(Modula), and was reformulated when object-oriented programing
went mainstream (C++, and much later Java). And it stopped there. The focus shifted to different branches of computer programming, namely to functional programming, and, to a lesser degree, logical programming. The only major development in this branch was the rise of aspect-oriented programming
(AOP) paradigm. Let’s take a look at AOP in our favorite language: JavaScript, and how Dojo helps the language with dojox.lang.aspect package.