tag: Article

heya-unify: back to JS

-- 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.

heya-unify: incomplete objects

-- 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.

heya-unify: custom 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.

When to unify in JS

5 Jun, 2014 - 10 minutes
-- 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 for JS

18 May, 2014 - 15 minutes
-- 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.

Serve files with nginx conditionally

23 Feb, 2014 - 9 minutes
-- Time and again working on big web applications we customize files based on user’s platform, and their preferences. We can send different files to legacy browsers, different CSS and JS to mobile browsers depending on their form factor, different images to accomodate bandwidth requirements, and so on. This post was prompted by my desire to serve sprites produced by grunt-tight-sprite as WebP images to WebP-capable browsers falling back to “classic” image formats for the rest using nginx.

More on 0ms timeouts

28 Jul, 2012 - 4 minutes
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.

OOP and JS

18 Jan, 2012 - 24 minutes
_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.

Using Dojo Rich Editor with Django's Admin

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.

Using recursion combinators in JavaScript

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.

AOP aspect of JavaScript with Dojo

_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.

On JavaScript, EDP, and 0ms timeouts

23 Mar, 2008 - 11 minutes
What makes JavaScript so different from other languages? Is it its dynamic nature? Its prototype-based funky inheritance? No. The most unusual thing for newcomers is how JavaScript programs handle the workflow. The program looks like a bowl of spaghetti. There is no start or end of the program. What we have here is a bunch of functions, which are called in response to some external events. In most cases we have no way to predict the order of these events.

Functional fun in JavaScript with Dojo

Everybody knows that JavaScript is a multi-paradigm language, and it can be used to program functionally. Practically all functional idioms can be used directly: higher-order functions, recursion, closures, and so on. The recent resurgence of Functional Programming (FP) brings functional methodologies in the mainstream. FP fundamentals gave us a lot of powerful idioms: iterative functions, which can replace loops, list processing in general, function manipulations, and many other things, which helps us to keep our code small yet concise, more powerful, and more fun.

Improving performance of Dojo-based web applications

Introduction Web 2.0 brought on us an onslaught of new server-side web frameworks, and made it OK to put some code on the client side as well. Yes, I am talking about Ajax. While elements of Ajax were available (and used) for a long time now, 2005 was the crucial year for this relatively old technology fueled by proliferation of modern browsers with proper support of JavaScript and HTML DOM, which, in turn, gave a rise to numerous Ajax toolkits.

Estimating unknown

2 Aug, 2006 - 7 minutes
How long does it take to do a project? Software developers are asked this very question on regular basis. This is how every project begins. Why is it important? Because “time is money” and many software projects are priced mostly by time spent on the project. “We will take your project estimate in hours, multiply them by your rate in $/h, and we have our price.” Ask any consultant or IT staffer about that.

Setting up tools 2

This is the 2nd part of Setting up tools on Windows — notes mostly for myself. (No, I don’t run Django with MSSQL under IronPython. Yet.) In this installment I add more stuff to Eclipse, and set up my apps under FastCGI on Linux-based shared host (I use DreamHost). Eclipse This section was updated on 9/30/2006. I already set it up with PyDev and Subclipse. Now I want to add HTML/CSS editing.

Setting up tools on Windows

Update 9/30/2006: when you finish this article don’t forget to read more about setting up tools in the second part: Setting up tools 2. My goal is to set up working environment for Django development on Windows box. You can find a lot of information on setting up open-source development tools on Linux. Somehow it is assumed that your project should target LAMP (Linux, Apache, MySQL, Python). Windows-bound guys are advised to decorate their platform as ersatz Linux: install Apache, install MySQL, and you have WAMP (Windows, Apache, MySQL, Python).